@fedify/vocab-runtime 2.4.0-pr.936.41 → 2.4.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.
- package/deno.json +4 -2
- package/dist/{tests/docloader-Ck8bcBir.mjs → contexts-BK1CqBR5.cjs} +164 -275
- package/dist/{tests/docloader-S_gQZ2tt.cjs → contexts-DPuJ4UYL.js} +160 -294
- package/dist/{docloader-C_dir7Xb.d.ts → docloader-CYwqh5Df.d.cts} +66 -2
- package/dist/{docloader-D2DTRiyA.d.cts → docloader-CYwqh5Df.d.ts} +66 -2
- package/dist/internal/jsonld-cache.cjs +70 -1
- package/dist/internal/jsonld-cache.d.cts +35 -2
- package/dist/internal/jsonld-cache.d.ts +35 -2
- package/dist/internal/jsonld-cache.js +67 -2
- package/dist/internal/portable-dereference.cjs +721 -0
- package/dist/internal/portable-dereference.d.cts +349 -0
- package/dist/internal/portable-dereference.d.ts +349 -0
- package/dist/internal/portable-dereference.js +702 -0
- package/dist/internal/signed-representation.cjs +378 -0
- package/dist/internal/signed-representation.d.cts +144 -0
- package/dist/internal/signed-representation.d.ts +144 -0
- package/dist/internal/signed-representation.js +371 -0
- package/dist/jsonld.cjs +2 -2
- package/dist/mod.cjs +711 -4527
- package/dist/mod.d.cts +400 -8
- package/dist/mod.d.ts +400 -9
- package/dist/mod.js +692 -4522
- package/dist/portable-DqtfLy_1.d.cts +160 -0
- package/dist/portable-DtWsu2yU.d.ts +160 -0
- package/dist/tests/body-CYiu9CO-.mjs +130 -0
- package/dist/tests/body-CkEwROsn.cjs +153 -0
- package/dist/tests/body.test.cjs +89 -0
- package/dist/tests/body.test.d.cts +1 -0
- package/dist/tests/body.test.d.mts +1 -0
- package/dist/tests/body.test.mjs +90 -0
- package/dist/tests/contexts-CIKsin4e.mjs +4512 -0
- package/dist/tests/contexts-DizzBjz4.cjs +4523 -0
- package/dist/tests/decimal.test.cjs +8 -7
- package/dist/tests/decimal.test.mjs +8 -6
- package/dist/tests/digest-3FeH2Y-Q.cjs +176 -0
- package/dist/tests/digest-COC7xDiQ.mjs +141 -0
- package/dist/tests/digest.test.cjs +102 -0
- package/dist/tests/digest.test.d.cts +1 -0
- package/dist/tests/digest.test.d.mts +1 -0
- package/dist/tests/digest.test.mjs +103 -0
- package/dist/tests/docloader-C3YFl6y4.cjs +396 -0
- package/dist/tests/docloader-CvmS4sVq.mjs +373 -0
- package/dist/tests/docloader.test.cjs +692 -39
- package/dist/tests/docloader.test.mjs +686 -34
- package/dist/tests/internal/multicodec.test.cjs +2 -3
- package/dist/tests/internal/multicodec.test.mjs +2 -2
- package/dist/tests/internal/portable-dereference.test.cjs +172 -0
- package/dist/tests/internal/portable-dereference.test.d.cts +1 -0
- package/dist/tests/internal/portable-dereference.test.d.mts +1 -0
- package/dist/tests/internal/portable-dereference.test.mjs +173 -0
- package/dist/tests/jsonld-cache-BPQmOZWD.mjs +342 -0
- package/dist/tests/jsonld-cache-C07AyNOY.cjs +397 -0
- package/dist/tests/jsonld-cache.test.cjs +101 -298
- package/dist/tests/jsonld-cache.test.mjs +94 -289
- package/dist/tests/{key-_wXwomh_.cjs → key-C-AYkdJJ.cjs} +11 -4
- package/dist/tests/{key-CDGDH_vC.mjs → key-C2Db_TAJ.mjs} +11 -3
- package/dist/tests/key.test.cjs +6 -5
- package/dist/tests/key.test.mjs +6 -4
- package/dist/tests/langstr.test.cjs +4 -4
- package/dist/tests/langstr.test.mjs +2 -2
- package/dist/tests/link.test.cjs +2 -3
- package/dist/tests/link.test.mjs +2 -2
- package/dist/tests/multibase/multibase.test.cjs +8 -9
- package/dist/tests/multibase/multibase.test.mjs +6 -6
- package/dist/tests/{multibase-Bz_UUDtL.cjs → multibase-B5Mea7Ip.cjs} +19 -2
- package/dist/tests/{multibase-B4bvakyA.mjs → multibase-BPnF_L4e.mjs} +12 -1
- package/dist/tests/portable-dereference-BNXtgg5U.cjs +278 -0
- package/dist/tests/portable-dereference-DRE5bz-l.mjs +249 -0
- package/dist/tests/portable-media-BLKllU56.cjs +153 -0
- package/dist/tests/portable-media-DRSGBORB.mjs +148 -0
- package/dist/tests/portable-media.test.cjs +222 -0
- package/dist/tests/portable-media.test.d.cts +1 -0
- package/dist/tests/portable-media.test.d.mts +1 -0
- package/dist/tests/portable-media.test.mjs +223 -0
- package/dist/tests/portable-workers.test.cjs +36 -0
- package/dist/tests/portable-workers.test.d.cts +2 -0
- package/dist/tests/portable-workers.test.d.mts +2 -0
- package/dist/tests/portable-workers.test.mjs +35 -0
- package/dist/tests/{request-uk51rkhO.cjs → request-8vPWtV1-.cjs} +10 -4
- package/dist/tests/{request-C8CaGwtt.mjs → request-DRaOaTqD.mjs} +8 -2
- package/dist/tests/request.test.cjs +7 -4
- package/dist/tests/request.test.mjs +5 -2
- package/dist/tests/signed-representation.test.cjs +588 -0
- package/dist/tests/signed-representation.test.d.cts +1 -0
- package/dist/tests/signed-representation.test.d.mts +1 -0
- package/dist/tests/signed-representation.test.mjs +589 -0
- package/dist/tests/temporal.test.cjs +1 -2
- package/dist/tests/temporal.test.mjs +1 -1
- package/dist/tests/url-BNakuZ8k.cjs +998 -0
- package/dist/tests/url-DMxmp7ZG.mjs +859 -0
- package/dist/tests/url.test.cjs +489 -6
- package/dist/tests/url.test.mjs +489 -5
- package/dist/url-DrGTR8yv.cjs +993 -0
- package/dist/url-Dzyp-NsC.js +860 -0
- package/package.json +27 -4
- package/scripts/test-bun.mjs +17 -0
- package/src/body.test.ts +125 -0
- package/src/body.ts +152 -0
- package/src/contexts/cid-v1.json +114 -0
- package/src/contexts/fep-22cd.json +21 -0
- package/src/contexts/miscellany.json +17 -0
- package/src/contexts.ts +39 -1
- package/src/digest.test.ts +220 -0
- package/src/digest.ts +229 -0
- package/src/docloader.test.ts +918 -27
- package/src/docloader.ts +320 -105
- package/src/internal/jsonld-cache.ts +97 -1
- package/src/internal/portable-dereference.test.ts +254 -0
- package/src/internal/portable-dereference.ts +1000 -0
- package/src/internal/signed-representation.ts +565 -0
- package/src/jsonld-cache.test.ts +89 -0
- package/src/key.test.ts +9 -0
- package/src/key.ts +11 -1
- package/src/mod.ts +28 -0
- package/src/multibase/multibase.test.ts +5 -5
- package/src/portable-media.test.ts +293 -0
- package/src/portable-media.ts +264 -0
- package/src/portable-workers.test.ts +81 -0
- package/src/portable.ts +180 -0
- package/src/preprocessor.ts +7 -0
- package/src/request.test.ts +10 -1
- package/src/request.ts +9 -1
- package/src/signed-representation.test.ts +338 -0
- package/src/url.test.ts +823 -3
- package/src/url.ts +700 -23
- package/tsdown.config.ts +2 -0
- package/dist/tests/url-CsOV_B_P.cjs +0 -482
- package/dist/tests/url-Du7RQQgP.mjs +0 -392
- package/dist/url-DD4F0ULf.cjs +0 -483
- package/dist/url-DGVbSVVi.js +0 -393
- /package/dist/{chunk-M78iaK0I.cjs → rolldown-runtime-B7lfambq.cjs} +0 -0
- /package/dist/tests/{langstr-CbAxaeEZ.cjs → langstr-C4Fl80ae.cjs} +0 -0
- /package/dist/tests/{langstr-Di5AvKpB.mjs → langstr-CQ26J_L7.mjs} +0 -0
- /package/dist/tests/{link-NUUWCdnK.mjs → link-Cevmc87v.mjs} +0 -0
- /package/dist/tests/{link-FguCydMA.cjs → link-DlKm8bEr.cjs} +0 -0
- /package/dist/tests/{multicodec-CxGVGa91.cjs → multicodec-CLRPeW4N.cjs} +0 -0
- /package/dist/tests/{multicodec-CyFp54fI.mjs → multicodec-CRIj_05H.mjs} +0 -0
- /package/dist/tests/{chunk-C2EiDwsr.cjs → rolldown-runtime-emK7D4bc.cjs} +0 -0
package/dist/mod.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { a as DocumentLoaderOptions, c as getDocumentLoader, d as
|
|
2
|
+
import { _ as logRequest, a as DocumentLoaderOptions, c as getDocumentLoader, d as withDocumentLoaderTimeout, f as CreateRequestOptions, g as getUserAgent, h as createActivityPubRequest, i as DocumentLoaderFactoryOptions, l as getRemoteDocument, m as GetUserAgentOptions, n as DocumentLoader, o as GetDocumentLoaderOptions, p as FetchError, r as DocumentLoaderFactory, s as RemoteDocument, t as AuthenticatedDocumentLoaderFactory, u as resolveDocumentLoaderTimeout } from "./docloader-CYwqh5Df.js";
|
|
3
|
+
import { i as PortableObjectVerifierOptions, n as PortableObjectVerification, r as PortableObjectVerifier, t as PortableObjectReferrer } from "./portable-DtWsu2yU.js";
|
|
3
4
|
import { TracerProvider } from "@opentelemetry/api";
|
|
4
|
-
|
|
5
5
|
//#region src/contexts.d.ts
|
|
6
6
|
declare const preloadedContexts: Record<string, unknown>;
|
|
7
7
|
//#endregion
|
|
@@ -73,9 +73,16 @@ declare function importDidKey(did: string | URL): Promise<CryptoKey>;
|
|
|
73
73
|
/**
|
|
74
74
|
* Exports an Ed25519 public key as a `did:key` DID.
|
|
75
75
|
*
|
|
76
|
+
* The DID is encoded in base58-btc with the Ed25519 multicodec prefix, e.g.,
|
|
77
|
+
* `did:key:z6Mk...`, as [FEP-ef61] requires for the DIDs of portable
|
|
78
|
+
* objects.
|
|
79
|
+
*
|
|
80
|
+
* [FEP-ef61]: https://w3id.org/fep/ef61
|
|
81
|
+
*
|
|
76
82
|
* @param key The Ed25519 public key.
|
|
77
83
|
* @returns The `did:key` DID.
|
|
78
|
-
* @throws {TypeError} If the key is invalid or unsupported
|
|
84
|
+
* @throws {TypeError} If the key is invalid or unsupported, or it is not
|
|
85
|
+
* a public key.
|
|
79
86
|
* @since 2.4.0
|
|
80
87
|
*/
|
|
81
88
|
declare function exportDidKey(key: CryptoKey): Promise<string>;
|
|
@@ -204,6 +211,87 @@ declare function canParseDecimal(value: string): boolean;
|
|
|
204
211
|
*/
|
|
205
212
|
declare function parseDecimal(value: string): Decimal;
|
|
206
213
|
//#endregion
|
|
214
|
+
//#region src/digest.d.ts
|
|
215
|
+
/**
|
|
216
|
+
* A parsed SHA-256 resource digest.
|
|
217
|
+
*
|
|
218
|
+
* @since 2.4.0
|
|
219
|
+
*/
|
|
220
|
+
interface ParsedDigestMultibase {
|
|
221
|
+
/** The multihash algorithm represented by the digest. */
|
|
222
|
+
readonly algorithm: "sha2-256";
|
|
223
|
+
/** The raw 32-byte SHA-256 digest. */
|
|
224
|
+
readonly digest: Uint8Array;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* A parsed simple hashlink.
|
|
228
|
+
*
|
|
229
|
+
* @since 2.4.0
|
|
230
|
+
*/
|
|
231
|
+
interface ParsedHashlink {
|
|
232
|
+
/** The multibase-encoded multihash carried by the hashlink. */
|
|
233
|
+
readonly digestMultibase: string;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Computes the SHA-256 digest of a byte sequence and encodes it as a
|
|
237
|
+
* base58-btc multibase multihash suitable for FEP-ef61's
|
|
238
|
+
* `digestMultibase` property.
|
|
239
|
+
*
|
|
240
|
+
* @param bytes The bytes to digest.
|
|
241
|
+
* @returns The base58-btc multibase-encoded SHA-256 multihash.
|
|
242
|
+
* @since 2.4.0
|
|
243
|
+
*/
|
|
244
|
+
declare function computeDigestMultibase(bytes: Uint8Array): Promise<string>;
|
|
245
|
+
/**
|
|
246
|
+
* Parses and validates a SHA-256 `digestMultibase` value.
|
|
247
|
+
*
|
|
248
|
+
* @param value The multibase-encoded multihash to parse.
|
|
249
|
+
* @returns The digest algorithm and raw digest bytes.
|
|
250
|
+
* @throws {TypeError} If the value is malformed or uses an unsupported hash
|
|
251
|
+
* algorithm.
|
|
252
|
+
* @since 2.4.0
|
|
253
|
+
*/
|
|
254
|
+
declare function parseDigestMultibase(value: string): ParsedDigestMultibase;
|
|
255
|
+
/**
|
|
256
|
+
* Parses a metadata-free `hl:` hashlink and validates its resource digest.
|
|
257
|
+
*
|
|
258
|
+
* @param value The simple hashlink to parse.
|
|
259
|
+
* @returns The `digestMultibase` value carried by the hashlink.
|
|
260
|
+
* @throws {TypeError} If the hashlink is malformed, contains metadata, or
|
|
261
|
+
* carries an invalid or unsupported digest.
|
|
262
|
+
* @since 2.4.0
|
|
263
|
+
*/
|
|
264
|
+
declare function parseHashlink(value: string | URL): ParsedHashlink;
|
|
265
|
+
/**
|
|
266
|
+
* Creates a metadata-free `hl:` hashlink from a `digestMultibase` value.
|
|
267
|
+
*
|
|
268
|
+
* @param digestMultibase The SHA-256 multibase multihash to embed.
|
|
269
|
+
* @returns The simple hashlink.
|
|
270
|
+
* @throws {TypeError} If the digest is malformed or unsupported.
|
|
271
|
+
* @since 2.4.0
|
|
272
|
+
*/
|
|
273
|
+
declare function createHashlink(digestMultibase: string): string;
|
|
274
|
+
/**
|
|
275
|
+
* Verifies that bytes match a SHA-256 `digestMultibase` value.
|
|
276
|
+
*
|
|
277
|
+
* @param bytes The bytes to verify.
|
|
278
|
+
* @param digestMultibase The expected digest.
|
|
279
|
+
* @returns Whether the bytes match the digest.
|
|
280
|
+
* @throws {TypeError} If the digest is malformed or unsupported.
|
|
281
|
+
* @since 2.4.0
|
|
282
|
+
*/
|
|
283
|
+
declare function verifyDigestMultibase(bytes: Uint8Array, digestMultibase: string): Promise<boolean>;
|
|
284
|
+
/**
|
|
285
|
+
* Verifies that bytes match the resource digest in a simple hashlink.
|
|
286
|
+
*
|
|
287
|
+
* @param bytes The bytes to verify.
|
|
288
|
+
* @param hashlink The simple hashlink containing the expected digest.
|
|
289
|
+
* @returns Whether the bytes match the hashlink digest.
|
|
290
|
+
* @throws {TypeError} If the hashlink or digest is malformed or unsupported.
|
|
291
|
+
* @since 2.4.0
|
|
292
|
+
*/
|
|
293
|
+
declare function verifyHashlink(bytes: Uint8Array, hashlink: string | URL): Promise<boolean>;
|
|
294
|
+
//#endregion
|
|
207
295
|
//#region src/langstr.d.ts
|
|
208
296
|
/**
|
|
209
297
|
* A language-tagged string which corresponds to the `rdf:langString` type.
|
|
@@ -223,6 +311,50 @@ declare class LanguageString extends String {
|
|
|
223
311
|
constructor(value: string, language: Intl.Locale | string);
|
|
224
312
|
}
|
|
225
313
|
//#endregion
|
|
314
|
+
//#region src/portable-media.d.ts
|
|
315
|
+
/** A link or document with an external resource and its integrity digest. */
|
|
316
|
+
interface PortableMedia {
|
|
317
|
+
readonly href?: URL | null;
|
|
318
|
+
readonly url?: URL | {
|
|
319
|
+
readonly href: URL | null;
|
|
320
|
+
readonly digestMultibase?: string | null;
|
|
321
|
+
} | null;
|
|
322
|
+
readonly digestMultibase?: string | null;
|
|
323
|
+
}
|
|
324
|
+
/** Options for {@link fetchPortableMedia}. */
|
|
325
|
+
interface FetchPortableMediaOptions {
|
|
326
|
+
/** Ordered FEP-ef61 gateway origins used for `hl:` resources. */
|
|
327
|
+
readonly gateways?: Iterable<string | URL>;
|
|
328
|
+
/** Expected digest when the first argument is a URL or string. */
|
|
329
|
+
readonly digestMultibase?: string;
|
|
330
|
+
/** Maximum decoded response size in bytes. Defaults to 16 MiB. */
|
|
331
|
+
readonly maxBytes?: number;
|
|
332
|
+
/** Whether private network addresses may be fetched. Defaults to `false`. */
|
|
333
|
+
readonly allowPrivateAddress?: boolean;
|
|
334
|
+
/** The HTTP `User-Agent` value or its components. */
|
|
335
|
+
readonly userAgent?: string | GetUserAgentOptions;
|
|
336
|
+
/** Cancels the entire retrieval and all gateway attempts. */
|
|
337
|
+
readonly signal?: AbortSignal;
|
|
338
|
+
/** Overall timeout in milliseconds. Defaults to 10 seconds; `null` disables it. */
|
|
339
|
+
readonly timeout?: number | null;
|
|
340
|
+
/** Timeout per gateway in milliseconds. Defaults to 3 seconds. */
|
|
341
|
+
readonly gatewayTimeout?: number | null;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Fetches a portable object's external media and returns it only after its
|
|
345
|
+
* SHA-256 `digestMultibase` has been verified. `hl:` resources are tried at
|
|
346
|
+
* the supplied gateways in order. The result contains verified body bytes;
|
|
347
|
+
* its `Content-Type` is unverified metadata supplied by the server.
|
|
348
|
+
*
|
|
349
|
+
* @param media A Link, Image, Document, or URL with an external resource.
|
|
350
|
+
* @param options Retrieval, integrity, and network policy options.
|
|
351
|
+
* @returns A response containing only verified bytes.
|
|
352
|
+
* @throws {TypeError} If the media reference or digest is invalid.
|
|
353
|
+
* @throws {Error} If no source supplies a matching bounded resource.
|
|
354
|
+
* @since 2.4.0
|
|
355
|
+
*/
|
|
356
|
+
declare function fetchPortableMedia(media: string | URL | PortableMedia, options?: FetchPortableMediaOptions): Promise<Response>;
|
|
357
|
+
//#endregion
|
|
226
358
|
//#region src/multibase/types.d.ts
|
|
227
359
|
type BaseCode = "\x00" | "0" | "7" | "9" | "f" | "F" | "v" | "V" | "t" | "T" | "b" | "B" | "c" | "C" | "h" | "k" | "K" | "z" | "Z" | "m" | "M" | "u" | "U";
|
|
228
360
|
/**
|
|
@@ -295,6 +427,12 @@ interface PropertyPreprocessorContext {
|
|
|
295
427
|
contextLoader?: DocumentLoader;
|
|
296
428
|
/** OpenTelemetry tracer provider for instrumentation. */
|
|
297
429
|
tracerProvider?: TracerProvider;
|
|
430
|
+
/**
|
|
431
|
+
* The default FEP-ef61 portable object verifier that objects returned by
|
|
432
|
+
* the preprocessor should use for their property accessors.
|
|
433
|
+
* @since 2.4.0
|
|
434
|
+
*/
|
|
435
|
+
verifyPortableObject?: PortableObjectVerifier;
|
|
298
436
|
/** Base URL for resolving relative references. */
|
|
299
437
|
baseUrl?: URL;
|
|
300
438
|
}
|
|
@@ -311,18 +449,66 @@ type PropertyPreprocessor<T = unknown> = (value: Json, context: PropertyPreproce
|
|
|
311
449
|
//#endregion
|
|
312
450
|
//#region src/url.d.ts
|
|
313
451
|
declare class UrlError extends Error {
|
|
314
|
-
|
|
452
|
+
/**
|
|
453
|
+
* The failure category. Defaults to `"disallowed"`.
|
|
454
|
+
* `"dns"` includes lookup errors and results with no usable IP addresses.
|
|
455
|
+
* @since 2.0.29
|
|
456
|
+
*/
|
|
457
|
+
readonly reason: "dns" | "disallowed";
|
|
458
|
+
constructor(message: string, options?: {
|
|
459
|
+
cause?: unknown;
|
|
460
|
+
reason?: "dns" | "disallowed";
|
|
461
|
+
});
|
|
315
462
|
}
|
|
316
463
|
/**
|
|
317
|
-
* Parses a JSON-LD `@id` value as an IRI
|
|
464
|
+
* Parses a JSON-LD `@id` value as an IRI, including FEP-ef61 portable
|
|
465
|
+
* ActivityPub IRIs. See {@link parseIri} for how IRIs are parsed.
|
|
466
|
+
* @param id The `@id` value.
|
|
467
|
+
* @param base The base IRI to resolve a relative `@id` against.
|
|
468
|
+
* @returns The parsed IRI, or `undefined` if `id` is missing or a blank node
|
|
469
|
+
* identifier.
|
|
470
|
+
* @throws {TypeError} If `id` is not a valid IRI.
|
|
471
|
+
* @since 2.4.0
|
|
318
472
|
*/
|
|
319
473
|
declare function parseJsonLdId(id: string | undefined, base?: string | URL): URL | undefined;
|
|
320
474
|
/**
|
|
321
475
|
* Parses an IRI as a URL, including FEP-ef61 portable ActivityPub IRIs.
|
|
476
|
+
* Portable URI and FEP-ef61 compatible identifier strings whose path contains
|
|
477
|
+
* a `.` or `..` segment, including percent-encoded spellings, throw a
|
|
478
|
+
* `TypeError`: JavaScript `URL` would otherwise identify a different object.
|
|
479
|
+
* This also applies to compatible identifier strings used as relative bases.
|
|
480
|
+
* A `URL` argument may already have lost such segments before this function
|
|
481
|
+
* receives it.
|
|
482
|
+
*
|
|
483
|
+
* Portable IRIs, e.g., `ap://did:key:z6Mk.../actor`, cannot be represented by
|
|
484
|
+
* JavaScript `URL` as they are, so the returned `URL` keeps the DID authority
|
|
485
|
+
* percent-encoded, e.g., `ap+ef61://did%3Akey%3Az6Mk.../actor`. Use
|
|
486
|
+
* {@link formatIri} to get the canonical string back.
|
|
487
|
+
* @param iri The IRI to parse.
|
|
488
|
+
* @param base The base IRI to resolve a relative IRI against.
|
|
489
|
+
* @returns The parsed IRI.
|
|
490
|
+
* @throws {TypeError} If the IRI is malformed.
|
|
491
|
+
* @since 2.4.0
|
|
322
492
|
*/
|
|
323
493
|
declare function parseIri(iri: string | URL, base?: string | URL): URL;
|
|
324
494
|
/**
|
|
325
495
|
* Formats a URL as an IRI, including FEP-ef61 portable ActivityPub IRIs.
|
|
496
|
+
* Portable URI and FEP-ef61 compatible identifier strings with dot segments
|
|
497
|
+
* throw a `TypeError` because their paths cannot be represented by JavaScript
|
|
498
|
+
* `URL` without normalization.
|
|
499
|
+
*
|
|
500
|
+
* Portable IRIs are formatted with the `ap+ef61:` scheme and a decoded DID
|
|
501
|
+
* authority, even if they were parsed from `ap:` IRIs. FEP-ef61 currently
|
|
502
|
+
* recommends the `ap:` scheme, so a future major version of Fedify may change
|
|
503
|
+
* the scheme this function produces. Do not compare its results as strings to
|
|
504
|
+
* tell whether two portable IRIs identify the same object; use
|
|
505
|
+
* `arePortableUrisEqual()` instead.
|
|
506
|
+
* @param iri The IRI to format.
|
|
507
|
+
* @returns The formatted IRI. A string that cannot be parsed as a URL at all
|
|
508
|
+
* is returned unchanged.
|
|
509
|
+
* @throws {TypeError} If the IRI is a malformed portable IRI or FEP-ef61
|
|
510
|
+
* compatible identifier, e.g., one with dot segments.
|
|
511
|
+
* @since 2.4.0
|
|
326
512
|
*/
|
|
327
513
|
declare function formatIri(iri: string | URL): string;
|
|
328
514
|
/**
|
|
@@ -334,6 +520,12 @@ declare function formatIri(iri: string | URL): string;
|
|
|
334
520
|
* string, not a `URL` object, because JavaScript `URL` normalizes opaque path
|
|
335
521
|
* segments before Fedify can compare them.
|
|
336
522
|
*
|
|
523
|
+
* The `ap+ef61:` scheme of the result is a choice of Fedify's, whereas
|
|
524
|
+
* FEP-ef61 currently canonicalizes portable URIs with the `ap:` scheme.
|
|
525
|
+
* A future major version of Fedify may change the scheme of the result, so
|
|
526
|
+
* do not persist the result as the only copy of an identifier; keep the
|
|
527
|
+
* original URI, and canonicalize it again when comparing.
|
|
528
|
+
*
|
|
337
529
|
* @param input The raw portable ActivityPub URI string to canonicalize.
|
|
338
530
|
* @returns The canonical portable ActivityPub URI string.
|
|
339
531
|
* @throws {TypeError} If the input is not a valid portable ActivityPub IRI.
|
|
@@ -371,18 +563,217 @@ declare function getFe34Origin(input: string | URL): string;
|
|
|
371
563
|
*/
|
|
372
564
|
declare function haveSameFe34Origin(left: string | URL, right: string | URL): boolean;
|
|
373
565
|
/**
|
|
374
|
-
* Checks whether two IRIs have the same origin.
|
|
566
|
+
* Checks whether two IRIs have the same origin. Unlike comparing
|
|
567
|
+
* `URL.origin`, which is `"null"` for URLs with non-special schemes, this
|
|
568
|
+
* compares FEP-ef61 portable ActivityPub IRIs by their schemes and DIDs, so
|
|
569
|
+
* that `ap:` and `ap+ef61:` IRIs of the same DID with decoded or
|
|
570
|
+
* percent-encoded authorities have the same origin. Other IRIs with
|
|
571
|
+
* a non-special scheme and a host are compared by their schemes and hosts.
|
|
572
|
+
*
|
|
573
|
+
* This is not an FEP-fe34 origin check: an `ap+ef61:` IRI and the `did:key`
|
|
574
|
+
* verification method of the same DID have different origins here. Use
|
|
575
|
+
* {@link haveSameFe34Origin} for that.
|
|
576
|
+
* @param left The first IRI.
|
|
577
|
+
* @param right The second IRI.
|
|
578
|
+
* @returns `true` if the IRIs have the same origin.
|
|
579
|
+
* @since 2.4.0
|
|
375
580
|
*/
|
|
376
581
|
declare function haveSameIriOrigin(left: URL, right: URL): boolean;
|
|
377
582
|
/**
|
|
378
|
-
* Checks whether the URL is an FEP-ef61 gateway base URI.
|
|
583
|
+
* Checks whether the URL is an FEP-ef61 gateway base URI, i.e., an HTTP(S)
|
|
584
|
+
* URI with no credentials, path, query, or fragment, such as
|
|
585
|
+
* `https://example.com/`. FEP-ef61 requires every item of a portable actor's
|
|
586
|
+
* `gateways` to be such a URI. A URI with an empty query or fragment
|
|
587
|
+
* delimiter, such as `https://example.com/?`, is not a gateway base URI.
|
|
588
|
+
*
|
|
589
|
+
* Note that the `URL` class normalizes `https://example.com` to
|
|
590
|
+
* `https://example.com/`, so both are gateway base URIs.
|
|
591
|
+
* @param url The URL to check.
|
|
592
|
+
* @returns `true` if the URL is an FEP-ef61 gateway base URI.
|
|
593
|
+
* @since 2.4.0
|
|
379
594
|
*/
|
|
380
595
|
declare function isGatewayUrl(url: URL): boolean;
|
|
381
596
|
/**
|
|
382
|
-
* Parses and validates an FEP-ef61 gateway base URI.
|
|
597
|
+
* Parses and validates an FEP-ef61 gateway base URI, i.e., an HTTP(S) URI with
|
|
598
|
+
* no credentials, path, query, or fragment, such as `https://example.com`.
|
|
599
|
+
* See {@link isGatewayUrl} for the rules.
|
|
600
|
+
* @param url The gateway base URI to parse.
|
|
601
|
+
* @returns The parsed gateway base URI, whose path is `/`.
|
|
602
|
+
* @throws {TypeError} If the URI is malformed, or is not an HTTP(S) base URI
|
|
603
|
+
* with no credentials, path, query, or fragment. In the
|
|
604
|
+
* latter case, the message starts with
|
|
605
|
+
* `Invalid FEP-ef61 gateway:`.
|
|
606
|
+
* @since 2.4.0
|
|
383
607
|
*/
|
|
384
608
|
declare function parseGatewayUrl(url: string): URL;
|
|
385
609
|
/**
|
|
610
|
+
* Converts an [FEP-ef61] compatible identifier into a portable ActivityPub
|
|
611
|
+
* URI.
|
|
612
|
+
*
|
|
613
|
+
* A compatible identifier is an HTTP(S) URL under a gateway's fixed
|
|
614
|
+
* `/.well-known/apgateway/` path, such as
|
|
615
|
+
* `https://server.example/.well-known/apgateway/did:key:z6Mk.../objects/1`.
|
|
616
|
+
* This function removes the gateway part and returns the corresponding
|
|
617
|
+
* portable URI, e.g., `ap+ef61://did:key:z6Mk.../objects/1`, in the same
|
|
618
|
+
* internal `URL` form that {@link parseIri} produces. The path, query, and
|
|
619
|
+
* fragment are preserved, so the result is a portable URI, not a comparison
|
|
620
|
+
* form; pass its `href` to {@link canonicalizePortableUri} or
|
|
621
|
+
* {@link arePortableUrisEqual} to compare it with other portable URIs.
|
|
622
|
+
*
|
|
623
|
+
* The conversion only reveals the *claimed* portable identifier. Anyone can
|
|
624
|
+
* publish a compatible identifier for any DID on their own server, so the
|
|
625
|
+
* gateway that served it is neither the object's origin nor authorized to act
|
|
626
|
+
* for the DID. Callers must still verify the retrieved document's Object
|
|
627
|
+
* Integrity Proof against the DID, as FEP-ef61 requires, and should keep the
|
|
628
|
+
* original URL if they need the gateway as a retrieval hint.
|
|
629
|
+
*
|
|
630
|
+
* Arbitrary gateway paths are not supported.
|
|
631
|
+
*
|
|
632
|
+
* [FEP-ef61]: https://w3id.org/fep/ef61
|
|
633
|
+
*
|
|
634
|
+
* @param input The URL to convert.
|
|
635
|
+
* @returns The portable ActivityPub URI, or `null` if the input is not an
|
|
636
|
+
* HTTP(S) URL whose path starts with `/.well-known/apgateway/did:`.
|
|
637
|
+
* Other gateway routes, such as the gateway discovery endpoint and
|
|
638
|
+
* hashlink media URLs, also yield `null`.
|
|
639
|
+
* @throws {TypeError} If the input looks like a compatible identifier but is
|
|
640
|
+
* malformed, e.g., it has an invalid DID, no object path,
|
|
641
|
+
* invalid percent-encoding, credentials, or location
|
|
642
|
+
* hints (`@gateway` query parameters, or the legacy
|
|
643
|
+
* `gateways` parameter), or its raw string path would
|
|
644
|
+
* change during URL parsing. Already-parsed `URL`
|
|
645
|
+
* arguments cannot reveal segments lost by their parser.
|
|
646
|
+
* @since 2.4.0
|
|
647
|
+
*/
|
|
648
|
+
declare function fromCompatibleEf61Id(input: string | URL): URL | null;
|
|
649
|
+
/**
|
|
650
|
+
* Converts a portable ActivityPub URI into an [FEP-ef61] compatible
|
|
651
|
+
* identifier, which is an HTTP(S) URL under the gateway's fixed
|
|
652
|
+
* `/.well-known/apgateway/` path.
|
|
653
|
+
*
|
|
654
|
+
* For example, `ap+ef61://did:key:z6Mk.../objects/1` and
|
|
655
|
+
* `https://server.example` yield
|
|
656
|
+
* `https://server.example/.well-known/apgateway/did:key:z6Mk.../objects/1`.
|
|
657
|
+
* Both `ap:` and `ap+ef61:` URIs with decoded or percent-encoded DID
|
|
658
|
+
* authorities are accepted. Publishers should use the first gateway in the
|
|
659
|
+
* actor's `gateways` list, as FEP-ef61 requires.
|
|
660
|
+
*
|
|
661
|
+
* The path and fragment are preserved, with characters that are not allowed
|
|
662
|
+
* in HTTP(S) URLs percent-encoded the same way as
|
|
663
|
+
* {@link canonicalizePortableUri} does. FEP-ef61 location hints (`@gateway`
|
|
664
|
+
* query parameters, and the legacy `gateways` parameter) are removed, since
|
|
665
|
+
* compatible identifiers must not have them; other query parameters are kept
|
|
666
|
+
* in order.
|
|
667
|
+
*
|
|
668
|
+
* Arbitrary gateway paths are not supported.
|
|
669
|
+
*
|
|
670
|
+
* [FEP-ef61]: https://w3id.org/fep/ef61
|
|
671
|
+
*
|
|
672
|
+
* @param portableId The `ap:` or `ap+ef61:` URI to convert.
|
|
673
|
+
* @param gateway The gateway's HTTP(S) origin, e.g., `https://server.example`.
|
|
674
|
+
* @returns The compatible identifier.
|
|
675
|
+
* @throws {TypeError} If the portable ID is not a valid `ap:` or `ap+ef61:`
|
|
676
|
+
* URI, if its path has `.` or `..` segments (which
|
|
677
|
+
* HTTP(S) URLs cannot represent without changing the
|
|
678
|
+
* identified object), or if the gateway is
|
|
679
|
+
* not an HTTP(S) origin with no credentials, path, query,
|
|
680
|
+
* or fragment.
|
|
681
|
+
* @since 2.4.0
|
|
682
|
+
*/
|
|
683
|
+
declare function toCompatibleEf61Id(portableId: string | URL, gateway: string | URL): URL;
|
|
684
|
+
/**
|
|
685
|
+
* Returns a copy of an [FEP-ef61] portable ActivityPub URI with `@gateway`
|
|
686
|
+
* location hints for the given gateways, which tell consumers where they can
|
|
687
|
+
* retrieve the object. Put hints on *references* to portable actors, e.g.,
|
|
688
|
+
* in `actor`, `attributedTo`, `to`, or `cc`, when constructing an object, as
|
|
689
|
+
* FEP-ef61 recommends:
|
|
690
|
+
*
|
|
691
|
+
* ~~~~ typescript
|
|
692
|
+
* withGatewayHints("ap://did:key:z6Mk.../actor", [
|
|
693
|
+
* "https://server1.example",
|
|
694
|
+
* "https://server2.example",
|
|
695
|
+
* ]);
|
|
696
|
+
* // ap+ef61://did:key:z6Mk.../actor?@gateway=https%3A%2F%2Fserver1.example&@gateway=https%3A%2F%2Fserver2.example
|
|
697
|
+
* ~~~~
|
|
698
|
+
*
|
|
699
|
+
* Do not put hints on an object's own `id`. Hints do not change the
|
|
700
|
+
* identity of a portable URI, since FEP-ef61 drops the query when comparing
|
|
701
|
+
* portable URIs, but implementations that do not canonicalize portable URIs
|
|
702
|
+
* would take a hinted ID for another object. Add hints before signing the
|
|
703
|
+
* object, since its Object Integrity Proof covers its references too.
|
|
704
|
+
*
|
|
705
|
+
* The hints that the URI already has, including the legacy `gateways`
|
|
706
|
+
* parameter, are replaced. Each gateway becomes a `@gateway` query
|
|
707
|
+
* parameter whose value is its URI-encoded origin, e.g.,
|
|
708
|
+
* `@gateway=https%3A%2F%2Fserver1.example`, in the given order after the
|
|
709
|
+
* other query parameters. Duplicate gateways are dropped, and an empty list
|
|
710
|
+
* removes the hints as {@link withoutGatewayHints} does. The other query
|
|
711
|
+
* parameters, their order, and the fragment are kept, but percent-encoding
|
|
712
|
+
* is normalized the same way as {@link canonicalizePortableUri} does it.
|
|
713
|
+
*
|
|
714
|
+
* Fedify follows at most five hints when dereferencing a portable URI
|
|
715
|
+
* (three for the key ID of an HTTP Signature), so list the preferred
|
|
716
|
+
* gateways first; there is no limit on the number of hints added here.
|
|
717
|
+
*
|
|
718
|
+
* [FEP-ef61]: https://w3id.org/fep/ef61
|
|
719
|
+
*
|
|
720
|
+
* @param portableId The `ap:` or `ap+ef61:` URI. Pass the raw string rather
|
|
721
|
+
* than a `URL` if its path may have `.` or `..` segments,
|
|
722
|
+
* because the `URL` class resolves them.
|
|
723
|
+
* @param gateways The gateways, e.g., the `gateways` of the actor that the
|
|
724
|
+
* URI refers to. Each has to be an HTTP(S) origin with no
|
|
725
|
+
* credentials, path, query, or fragment.
|
|
726
|
+
* @returns The portable URI with the hints, in the same internal `URL` form
|
|
727
|
+
* as {@link parseIri} returns. Use {@link formatIri} to get its
|
|
728
|
+
* canonical string.
|
|
729
|
+
* @throws {TypeError} If the portable ID is not a valid `ap:` or `ap+ef61:`
|
|
730
|
+
* URI, e.g., it is a compatible identifier, which must
|
|
731
|
+
* not have location hints; if its path has `.` or `..`
|
|
732
|
+
* segments, which the `URL` class cannot represent; or
|
|
733
|
+
* if a gateway is invalid.
|
|
734
|
+
* @since 2.4.0
|
|
735
|
+
*/
|
|
736
|
+
declare function withGatewayHints(portableId: string | URL, gateways: Iterable<string | URL>): URL;
|
|
737
|
+
/**
|
|
738
|
+
* Returns a copy of an [FEP-ef61] portable ActivityPub URI without its
|
|
739
|
+
* location hints, i.e., `@gateway` query parameters and the legacy
|
|
740
|
+
* `gateways` parameter. The other query parameters, their order, and the
|
|
741
|
+
* fragment are kept, but percent-encoding is normalized the same way as
|
|
742
|
+
* {@link canonicalizePortableUri} does it.
|
|
743
|
+
*
|
|
744
|
+
* [FEP-ef61]: https://w3id.org/fep/ef61
|
|
745
|
+
*
|
|
746
|
+
* @param portableId The `ap:` or `ap+ef61:` URI. Pass the raw string rather
|
|
747
|
+
* than a `URL` if its path may have `.` or `..` segments,
|
|
748
|
+
* because the `URL` class resolves them.
|
|
749
|
+
* @returns The portable URI without the hints, in the same internal `URL`
|
|
750
|
+
* form as {@link parseIri} returns.
|
|
751
|
+
* @throws {TypeError} If the portable ID is not a valid `ap:` or `ap+ef61:`
|
|
752
|
+
* URI, or if its path has `.` or `..` segments, which
|
|
753
|
+
* the `URL` class cannot represent.
|
|
754
|
+
* @since 2.4.0
|
|
755
|
+
*/
|
|
756
|
+
declare function withoutGatewayHints(portableId: string | URL): URL;
|
|
757
|
+
/**
|
|
758
|
+
* Gets the gateways in the `@gateway` location hints of an [FEP-ef61]
|
|
759
|
+
* portable ActivityPub URI, in order. Hints that are not valid gateways,
|
|
760
|
+
* i.e., HTTP(S) origins with no credentials, path, query, or fragment, are
|
|
761
|
+
* skipped, and so are duplicates. The legacy `gateways` parameter is not
|
|
762
|
+
* read.
|
|
763
|
+
*
|
|
764
|
+
* Unlike Fedify's dereferencing, which follows at most five hints, this
|
|
765
|
+
* returns all of them.
|
|
766
|
+
*
|
|
767
|
+
* [FEP-ef61]: https://w3id.org/fep/ef61
|
|
768
|
+
*
|
|
769
|
+
* @param portableId The `ap:` or `ap+ef61:` URI.
|
|
770
|
+
* @returns The gateways, e.g., `https://server1.example/`.
|
|
771
|
+
* @throws {TypeError} If the portable ID is not a valid `ap:` or `ap+ef61:`
|
|
772
|
+
* URI.
|
|
773
|
+
* @since 2.4.0
|
|
774
|
+
*/
|
|
775
|
+
declare function getGatewayHints(portableId: string | URL): URL[];
|
|
776
|
+
/**
|
|
386
777
|
* Validates a URL to prevent SSRF attacks.
|
|
387
778
|
*/
|
|
388
779
|
declare function validatePublicUrl(url: string): Promise<void>;
|
|
@@ -390,4 +781,4 @@ declare function isValidPublicIPv4Address(address: string): boolean;
|
|
|
390
781
|
declare function isValidPublicIPv6Address(address: string): boolean;
|
|
391
782
|
declare function expandIPv6Address(address: string): string;
|
|
392
783
|
//#endregion
|
|
393
|
-
export { type AuthenticatedDocumentLoaderFactory, type CreateRequestOptions, type Decimal, type DidKeyVerificationMethod, type DocumentLoader, type DocumentLoaderFactory, type DocumentLoaderFactoryOptions, type DocumentLoaderOptions, FetchError, type GetDocumentLoaderOptions, type GetUserAgentOptions, type Json, LanguageString, type PropertyPreprocessor, type PropertyPreprocessorContext, type RemoteDocument, UrlError, arePortableUrisEqual, canParseDecimal, canonicalizePortableUri, createActivityPubRequest, decodeMultibase, encodeMultibase, encodingFromBaseData, expandIPv6Address, exportDidKey, exportMultibaseKey, exportSpki, formatIri, getDocumentLoader, getFe34Origin, getRemoteDocument, getUserAgent, haveSameFe34Origin, haveSameIriOrigin, importDidKey, importMultibaseKey, importPem, importPkcs1, importSpki, isDecimal, isGatewayUrl, isValidPublicIPv4Address, isValidPublicIPv6Address, logRequest, parseDecimal, parseDidKeyVerificationMethod, parseGatewayUrl, parseIri, parseJsonLdId, preloadedContexts, validatePublicUrl };
|
|
784
|
+
export { type AuthenticatedDocumentLoaderFactory, type CreateRequestOptions, type Decimal, type DidKeyVerificationMethod, type DocumentLoader, type DocumentLoaderFactory, type DocumentLoaderFactoryOptions, type DocumentLoaderOptions, FetchError, type FetchPortableMediaOptions, type GetDocumentLoaderOptions, type GetUserAgentOptions, type Json, LanguageString, type ParsedDigestMultibase, type ParsedHashlink, type PortableMedia, type PortableObjectReferrer, type PortableObjectVerification, type PortableObjectVerifier, type PortableObjectVerifierOptions, type PropertyPreprocessor, type PropertyPreprocessorContext, type RemoteDocument, UrlError, arePortableUrisEqual, canParseDecimal, canonicalizePortableUri, computeDigestMultibase, createActivityPubRequest, createHashlink, decodeMultibase, encodeMultibase, encodingFromBaseData, expandIPv6Address, exportDidKey, exportMultibaseKey, exportSpki, fetchPortableMedia, formatIri, fromCompatibleEf61Id, getDocumentLoader, getFe34Origin, getGatewayHints, getRemoteDocument, getUserAgent, haveSameFe34Origin, haveSameIriOrigin, importDidKey, importMultibaseKey, importPem, importPkcs1, importSpki, isDecimal, isGatewayUrl, isValidPublicIPv4Address, isValidPublicIPv6Address, logRequest, parseDecimal, parseDidKeyVerificationMethod, parseDigestMultibase, parseGatewayUrl, parseHashlink, parseIri, parseJsonLdId, preloadedContexts, resolveDocumentLoaderTimeout, toCompatibleEf61Id, validatePublicUrl, verifyDigestMultibase, verifyHashlink, withDocumentLoaderTimeout, withGatewayHints, withoutGatewayHints };
|