@fedify/vocab-runtime 2.4.0-dev.2056 → 2.4.0-dev.2065

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 (34) hide show
  1. package/deno.json +1 -1
  2. package/dist/internal/portable-dereference.cjs +355 -8
  3. package/dist/internal/portable-dereference.d.cts +238 -6
  4. package/dist/internal/portable-dereference.d.ts +238 -6
  5. package/dist/internal/portable-dereference.js +343 -10
  6. package/dist/mod.cjs +1 -1
  7. package/dist/mod.d.cts +2 -2
  8. package/dist/mod.d.ts +2 -2
  9. package/dist/mod.js +1 -1
  10. package/dist/portable-DH3947GK.d.ts +160 -0
  11. package/dist/portable-comBI05Y.d.cts +160 -0
  12. package/dist/tests/{body-wkL-XGhe.mjs → body-CNO0jMV8.mjs} +1 -1
  13. package/dist/tests/{body-h9zUR79f.cjs → body-DXHOazEl.cjs} +1 -1
  14. package/dist/tests/body.test.cjs +1 -1
  15. package/dist/tests/body.test.mjs +1 -1
  16. package/dist/tests/decimal.test.cjs +1 -1
  17. package/dist/tests/decimal.test.mjs +1 -1
  18. package/dist/tests/{docloader-CBLgaVPd.cjs → docloader-4Txefi7y.cjs} +2 -2
  19. package/dist/tests/{docloader-DMGssPEX.mjs → docloader-C-nWtUWo.mjs} +2 -2
  20. package/dist/tests/docloader.test.cjs +2 -2
  21. package/dist/tests/docloader.test.mjs +2 -2
  22. package/dist/tests/internal/portable-dereference.test.cjs +87 -0
  23. package/dist/tests/internal/portable-dereference.test.mjs +87 -0
  24. package/dist/tests/{request-ClFs0ePp.cjs → request-BOLanqAd.cjs} +1 -1
  25. package/dist/tests/{request-Ytm0xyZH.mjs → request-dpFdQKXr.mjs} +1 -1
  26. package/dist/tests/request.test.cjs +1 -1
  27. package/dist/tests/request.test.mjs +1 -1
  28. package/package.json +1 -1
  29. package/src/internal/portable-dereference.test.ts +32 -0
  30. package/src/internal/portable-dereference.ts +521 -12
  31. package/src/mod.ts +2 -0
  32. package/src/portable.ts +136 -8
  33. package/dist/portable-CduElToy.d.ts +0 -52
  34. package/dist/portable-DxF2Ut-Z.d.cts +0 -52
package/src/portable.ts CHANGED
@@ -23,30 +23,158 @@ export interface PortableObjectVerifierOptions {
23
23
  * The OpenTelemetry tracer provider.
24
24
  */
25
25
  readonly tracerProvider?: TracerProvider;
26
+
27
+ /**
28
+ * The URL the document was finally retrieved from, i.e., the `documentUrl`
29
+ * of the document loader's result, which may differ from the requested URL
30
+ * after redirects. Trust decisions such as the [FEP-ef61] gateway trust
31
+ * policy for unsecured collections depend on it, so custom document loaders
32
+ * must report it truthfully.
33
+ *
34
+ * [FEP-ef61]: https://w3id.org/fep/ef61
35
+ * @since 2.4.0
36
+ */
37
+ readonly documentUrl?: URL;
38
+
39
+ /**
40
+ * The gateways that the caller explicitly passed to the accessor through
41
+ * its `gateways` option, in order. It is `undefined` if the caller did not
42
+ * pass the option, and can be empty.
43
+ * @since 2.4.0
44
+ */
45
+ readonly gateways?: readonly URL[];
46
+
47
+ /**
48
+ * The gateways inferred from the reference, in order, when the caller did
49
+ * not pass the `gateways` option: the `@gateway` location hints of
50
+ * a portable IRI, the gateway named by an FEP-ef61 compatible identifier,
51
+ * or the WebFinger server of a portable actor. They only tell where the
52
+ * document and related objects might be retrieved, and must not be
53
+ * trusted to act for the portable object's DID.
54
+ * @since 2.4.0
55
+ */
56
+ readonly gatewayHints?: readonly URL[];
57
+
58
+ /**
59
+ * The object whose property referred to the document, if the document was
60
+ * dereferenced through a property accessor.
61
+ * @since 2.4.0
62
+ */
63
+ readonly referrer?: PortableObjectReferrer;
26
64
  }
27
65
 
28
66
  /**
29
- * A function that applies the [FEP-ef61] proof policy to a portable object
67
+ * An object whose property referred to a portable object being verified.
68
+ * Referrers form a chain: {@link PortableObjectReferrer.referrer} is the
69
+ * object through which this referrer itself was obtained, and so on.
70
+ * @since 2.4.0
71
+ */
72
+ export interface PortableObjectReferrer {
73
+ /**
74
+ * The referring vocabulary object.
75
+ */
76
+ readonly object: unknown;
77
+
78
+ /**
79
+ * The `@id` of the referring object, if any.
80
+ */
81
+ readonly id: URL | null;
82
+
83
+ /**
84
+ * The expanded URI of the property through which the referring object
85
+ * referred to the next object in the chain, e.g.,
86
+ * `https://www.w3.org/ns/activitystreams#outbox`.
87
+ */
88
+ readonly property: string;
89
+
90
+ /**
91
+ * How the referring object itself was accepted by a
92
+ * {@link PortableObjectVerifier} when it was dereferenced through gateways:
93
+ *
94
+ * - `"verified"`: accepted as verified, e.g., with a valid integrity proof.
95
+ * - `"unsecured"`: accepted without an integrity proof, e.g., as an
96
+ * unsecured collection served by a trusted gateway.
97
+ *
98
+ * It is `undefined` if the referring object was not dereferenced through
99
+ * gateways, e.g., if it was embedded in another object or constructed by
100
+ * the application.
101
+ */
102
+ readonly acceptance?: "verified" | "unsecured";
103
+
104
+ /**
105
+ * The opaque collection context that a {@link PortableObjectVerifier}
106
+ * attached to the referring object when it accepted it. See
107
+ * {@link PortableObjectVerification}.
108
+ */
109
+ readonly collectionContext?: unknown;
110
+
111
+ /**
112
+ * The referrer of the referring object, if any.
113
+ */
114
+ readonly referrer?: PortableObjectReferrer;
115
+
116
+ /**
117
+ * Whether the chain was cut off here because it was too long. If `true`,
118
+ * the referring object may have a referrer which is not included.
119
+ */
120
+ readonly truncated?: boolean;
121
+ }
122
+
123
+ /**
124
+ * The result of a {@link PortableObjectVerifier}.
125
+ * @since 2.4.0
126
+ */
127
+ export type PortableObjectVerification =
128
+ | {
129
+ /** Whether the document is accepted. */
130
+ readonly verified: false;
131
+ }
132
+ | {
133
+ /** Whether the document is accepted. */
134
+ readonly verified: true;
135
+
136
+ /**
137
+ * Whether the document was accepted without an integrity proof, e.g., as
138
+ * an unsecured [FEP-ef61] collection served by a gateway that its owner
139
+ * lists. Objects embedded in such a document are not trusted because of
140
+ * their origin; property accessors dereference and verify them one by
141
+ * one instead.
142
+ *
143
+ * [FEP-ef61]: https://w3id.org/fep/ef61
144
+ */
145
+ readonly unsecured?: boolean;
146
+
147
+ /**
148
+ * An opaque value that the verifier wants to receive again as
149
+ * {@link PortableObjectReferrer.collectionContext} when objects referred
150
+ * to by this document, such as collection pages, are verified.
151
+ */
152
+ readonly collectionContext?: unknown;
153
+ };
154
+
155
+ /**
156
+ * A function that applies the [FEP-ef61] trust policy to a portable object
30
157
  * fetched through a gateway.
31
158
  *
32
159
  * It receives the fetched JSON-LD document as is, and resolves to an object
33
- * whose `verified` property tells whether the document carries a valid
34
- * [FEP-8b32] Object Integrity Proof made by the DID in its portable ID.
35
- * `verifyPortableObjectProof()` from `@fedify/fedify` satisfies this type, so
36
- * it can be passed as the `verifyPortableObject` option of generated
160
+ * whose `verified` property tells whether the document is acceptable, e.g.,
161
+ * whether it carries a valid [FEP-8b32] Object Integrity Proof made by the
162
+ * DID in its portable ID. `verifyPortableObject()` and
163
+ * `verifyPortableObjectProof()` from `@fedify/fedify` satisfy this type, so
164
+ * they can be passed as the `verifyPortableObject` option of generated
37
165
  * vocabulary accessors such as `Activity.getObject()`.
38
166
  *
39
167
  * [FEP-ef61]: https://w3id.org/fep/ef61
40
168
  * [FEP-8b32]: https://w3id.org/fep/8b32
41
169
  *
42
170
  * @param document The fetched JSON-LD document.
43
- * @param options Loaders and tracing options for verification.
171
+ * @param options Loaders, tracing options, and where the document came from.
44
172
  * @returns An object whose `verified` property is `true` if and only if the
45
- * document satisfies the proof policy. Other properties, such as
173
+ * document satisfies the policy. Other properties, such as
46
174
  * a failure reason, are logged when verification fails.
47
175
  * @since 2.4.0
48
176
  */
49
177
  export type PortableObjectVerifier = (
50
178
  document: unknown,
51
179
  options: PortableObjectVerifierOptions,
52
- ) => Promise<{ readonly verified: boolean }>;
180
+ ) => Promise<PortableObjectVerification>;
@@ -1,52 +0,0 @@
1
- /// <reference lib="esnext.temporal" />
2
- import { n as DocumentLoader } from "./docloader-Dr8wEkif.js";
3
- import { TracerProvider } from "@opentelemetry/api";
4
-
5
- //#region src/portable.d.ts
6
- /**
7
- * Options passed to a {@link PortableObjectVerifier}.
8
- * @since 2.4.0
9
- */
10
- interface PortableObjectVerifierOptions {
11
- /**
12
- * The document loader for fetching remote documents, such as verification
13
- * methods that are not `did:key` URLs.
14
- */
15
- readonly documentLoader?: DocumentLoader;
16
- /**
17
- * The document loader for fetching remote JSON-LD contexts. During
18
- * gateway dereferencing, this loader returns the same context documents
19
- * that the vocabulary parser sees.
20
- */
21
- readonly contextLoader?: DocumentLoader;
22
- /**
23
- * The OpenTelemetry tracer provider.
24
- */
25
- readonly tracerProvider?: TracerProvider;
26
- }
27
- /**
28
- * A function that applies the [FEP-ef61] proof policy to a portable object
29
- * fetched through a gateway.
30
- *
31
- * It receives the fetched JSON-LD document as is, and resolves to an object
32
- * whose `verified` property tells whether the document carries a valid
33
- * [FEP-8b32] Object Integrity Proof made by the DID in its portable ID.
34
- * `verifyPortableObjectProof()` from `@fedify/fedify` satisfies this type, so
35
- * it can be passed as the `verifyPortableObject` option of generated
36
- * vocabulary accessors such as `Activity.getObject()`.
37
- *
38
- * [FEP-ef61]: https://w3id.org/fep/ef61
39
- * [FEP-8b32]: https://w3id.org/fep/8b32
40
- *
41
- * @param document The fetched JSON-LD document.
42
- * @param options Loaders and tracing options for verification.
43
- * @returns An object whose `verified` property is `true` if and only if the
44
- * document satisfies the proof policy. Other properties, such as
45
- * a failure reason, are logged when verification fails.
46
- * @since 2.4.0
47
- */
48
- type PortableObjectVerifier = (document: unknown, options: PortableObjectVerifierOptions) => Promise<{
49
- readonly verified: boolean;
50
- }>;
51
- //#endregion
52
- export { PortableObjectVerifierOptions as n, PortableObjectVerifier as t };
@@ -1,52 +0,0 @@
1
- /// <reference lib="esnext.temporal" />
2
- import { n as DocumentLoader } from "./docloader-Dr8wEkif.cjs";
3
- import { TracerProvider } from "@opentelemetry/api";
4
-
5
- //#region src/portable.d.ts
6
- /**
7
- * Options passed to a {@link PortableObjectVerifier}.
8
- * @since 2.4.0
9
- */
10
- interface PortableObjectVerifierOptions {
11
- /**
12
- * The document loader for fetching remote documents, such as verification
13
- * methods that are not `did:key` URLs.
14
- */
15
- readonly documentLoader?: DocumentLoader;
16
- /**
17
- * The document loader for fetching remote JSON-LD contexts. During
18
- * gateway dereferencing, this loader returns the same context documents
19
- * that the vocabulary parser sees.
20
- */
21
- readonly contextLoader?: DocumentLoader;
22
- /**
23
- * The OpenTelemetry tracer provider.
24
- */
25
- readonly tracerProvider?: TracerProvider;
26
- }
27
- /**
28
- * A function that applies the [FEP-ef61] proof policy to a portable object
29
- * fetched through a gateway.
30
- *
31
- * It receives the fetched JSON-LD document as is, and resolves to an object
32
- * whose `verified` property tells whether the document carries a valid
33
- * [FEP-8b32] Object Integrity Proof made by the DID in its portable ID.
34
- * `verifyPortableObjectProof()` from `@fedify/fedify` satisfies this type, so
35
- * it can be passed as the `verifyPortableObject` option of generated
36
- * vocabulary accessors such as `Activity.getObject()`.
37
- *
38
- * [FEP-ef61]: https://w3id.org/fep/ef61
39
- * [FEP-8b32]: https://w3id.org/fep/8b32
40
- *
41
- * @param document The fetched JSON-LD document.
42
- * @param options Loaders and tracing options for verification.
43
- * @returns An object whose `verified` property is `true` if and only if the
44
- * document satisfies the proof policy. Other properties, such as
45
- * a failure reason, are logged when verification fails.
46
- * @since 2.4.0
47
- */
48
- type PortableObjectVerifier = (document: unknown, options: PortableObjectVerifierOptions) => Promise<{
49
- readonly verified: boolean;
50
- }>;
51
- //#endregion
52
- export { PortableObjectVerifierOptions as n, PortableObjectVerifier as t };