@fedify/vocab-runtime 2.4.0-pr.936.41 → 2.4.1

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 (152) hide show
  1. package/deno.json +4 -2
  2. package/dist/{tests/docloader-Ck8bcBir.mjs → contexts-B09jb9Pi.cjs} +173 -274
  3. package/dist/{tests/docloader-S_gQZ2tt.cjs → contexts-DWrj4AGR.js} +169 -293
  4. package/dist/{docloader-C_dir7Xb.d.ts → docloader-BMHljyYb.d.cts} +68 -2
  5. package/dist/{docloader-D2DTRiyA.d.cts → docloader-BMHljyYb.d.ts} +68 -2
  6. package/dist/internal/jsonld-cache.cjs +70 -1
  7. package/dist/internal/jsonld-cache.d.cts +35 -2
  8. package/dist/internal/jsonld-cache.d.ts +35 -2
  9. package/dist/internal/jsonld-cache.js +67 -2
  10. package/dist/internal/portable-dereference.cjs +721 -0
  11. package/dist/internal/portable-dereference.d.cts +349 -0
  12. package/dist/internal/portable-dereference.d.ts +349 -0
  13. package/dist/internal/portable-dereference.js +702 -0
  14. package/dist/internal/signed-representation.cjs +378 -0
  15. package/dist/internal/signed-representation.d.cts +144 -0
  16. package/dist/internal/signed-representation.d.ts +144 -0
  17. package/dist/internal/signed-representation.js +371 -0
  18. package/dist/jsonld.cjs +2 -2
  19. package/dist/mod.cjs +762 -4529
  20. package/dist/mod.d.cts +427 -9
  21. package/dist/mod.d.ts +427 -10
  22. package/dist/mod.js +742 -4524
  23. package/dist/portable-6Aj-7dZJ.d.cts +160 -0
  24. package/dist/portable-nkTiqH0w.d.ts +160 -0
  25. package/dist/tests/body-DpC9p-iG.mjs +130 -0
  26. package/dist/tests/body-cKLBprYm.cjs +153 -0
  27. package/dist/tests/body.test.cjs +89 -0
  28. package/dist/tests/body.test.d.cts +1 -0
  29. package/dist/tests/body.test.d.mts +1 -0
  30. package/dist/tests/body.test.mjs +90 -0
  31. package/dist/tests/contexts-C9Lj11SC.cjs +4533 -0
  32. package/dist/tests/contexts-duRA_dDC.mjs +4522 -0
  33. package/dist/tests/decimal.test.cjs +9 -7
  34. package/dist/tests/decimal.test.mjs +9 -6
  35. package/dist/tests/digest-3FeH2Y-Q.cjs +176 -0
  36. package/dist/tests/digest-COC7xDiQ.mjs +141 -0
  37. package/dist/tests/digest.test.cjs +102 -0
  38. package/dist/tests/digest.test.d.cts +1 -0
  39. package/dist/tests/digest.test.d.mts +1 -0
  40. package/dist/tests/digest.test.mjs +103 -0
  41. package/dist/tests/docloader-DyZ1JGIl.cjs +398 -0
  42. package/dist/tests/docloader-tUmMeXjU.mjs +375 -0
  43. package/dist/tests/docloader.test.cjs +816 -39
  44. package/dist/tests/docloader.test.mjs +810 -34
  45. package/dist/tests/internal/multicodec.test.cjs +2 -3
  46. package/dist/tests/internal/multicodec.test.mjs +2 -2
  47. package/dist/tests/internal/portable-dereference.test.cjs +172 -0
  48. package/dist/tests/internal/portable-dereference.test.d.cts +1 -0
  49. package/dist/tests/internal/portable-dereference.test.d.mts +1 -0
  50. package/dist/tests/internal/portable-dereference.test.mjs +173 -0
  51. package/dist/tests/jsonld-CmDhHNTx.cjs +12 -0
  52. package/dist/tests/jsonld-DweIJ07b.mjs +5 -0
  53. package/dist/tests/jsonld-cache-BEXiiM-V.cjs +386 -0
  54. package/dist/tests/jsonld-cache-DFnWsLuZ.mjs +339 -0
  55. package/dist/tests/jsonld-cache.test.cjs +102 -298
  56. package/dist/tests/jsonld-cache.test.mjs +95 -289
  57. package/dist/tests/{key-_wXwomh_.cjs → key-C-AYkdJJ.cjs} +11 -4
  58. package/dist/tests/{key-CDGDH_vC.mjs → key-C2Db_TAJ.mjs} +11 -3
  59. package/dist/tests/key.test.cjs +6 -5
  60. package/dist/tests/key.test.mjs +6 -4
  61. package/dist/tests/{langstr-Di5AvKpB.mjs → langstr-DYRmJqFn.mjs} +5 -2
  62. package/dist/tests/{langstr-CbAxaeEZ.cjs → langstr-_PqsL1ae.cjs} +5 -2
  63. package/dist/tests/langstr.test.cjs +11 -4
  64. package/dist/tests/langstr.test.mjs +9 -2
  65. package/dist/tests/langtag-CUppHs_s.mjs +45 -0
  66. package/dist/tests/langtag-Czjvxfzx.cjs +50 -0
  67. package/dist/tests/langtag.test.cjs +45 -0
  68. package/dist/tests/langtag.test.d.cts +1 -0
  69. package/dist/tests/langtag.test.d.mts +1 -0
  70. package/dist/tests/langtag.test.mjs +46 -0
  71. package/dist/tests/link.test.cjs +2 -3
  72. package/dist/tests/link.test.mjs +2 -2
  73. package/dist/tests/multibase/multibase.test.cjs +8 -9
  74. package/dist/tests/multibase/multibase.test.mjs +6 -6
  75. package/dist/tests/{multibase-Bz_UUDtL.cjs → multibase-B5Mea7Ip.cjs} +19 -2
  76. package/dist/tests/{multibase-B4bvakyA.mjs → multibase-BPnF_L4e.mjs} +12 -1
  77. package/dist/tests/portable-dereference-DmTYDy2p.mjs +250 -0
  78. package/dist/tests/portable-dereference-qTLMqe2_.cjs +279 -0
  79. package/dist/tests/portable-media-5p8azal0.cjs +153 -0
  80. package/dist/tests/portable-media-B_lt9MMA.mjs +148 -0
  81. package/dist/tests/portable-media.test.cjs +222 -0
  82. package/dist/tests/portable-media.test.d.cts +1 -0
  83. package/dist/tests/portable-media.test.d.mts +1 -0
  84. package/dist/tests/portable-media.test.mjs +223 -0
  85. package/dist/tests/portable-workers.test.cjs +36 -0
  86. package/dist/tests/portable-workers.test.d.cts +2 -0
  87. package/dist/tests/portable-workers.test.d.mts +2 -0
  88. package/dist/tests/portable-workers.test.mjs +35 -0
  89. package/dist/tests/{request-uk51rkhO.cjs → request-BgjA9wyl.cjs} +10 -4
  90. package/dist/tests/{request-C8CaGwtt.mjs → request-DodZNukP.mjs} +8 -2
  91. package/dist/tests/request.test.cjs +7 -4
  92. package/dist/tests/request.test.mjs +5 -2
  93. package/dist/tests/signed-representation.test.cjs +588 -0
  94. package/dist/tests/signed-representation.test.d.cts +1 -0
  95. package/dist/tests/signed-representation.test.d.mts +1 -0
  96. package/dist/tests/signed-representation.test.mjs +589 -0
  97. package/dist/tests/temporal.test.cjs +1 -2
  98. package/dist/tests/temporal.test.mjs +1 -1
  99. package/dist/tests/url-BNakuZ8k.cjs +998 -0
  100. package/dist/tests/url-DMxmp7ZG.mjs +859 -0
  101. package/dist/tests/url.test.cjs +489 -6
  102. package/dist/tests/url.test.mjs +489 -5
  103. package/dist/url-DrGTR8yv.cjs +993 -0
  104. package/dist/url-Dzyp-NsC.js +860 -0
  105. package/package.json +27 -4
  106. package/scripts/test-bun.mjs +17 -0
  107. package/src/body.test.ts +125 -0
  108. package/src/body.ts +152 -0
  109. package/src/contexts/cid-v1.json +114 -0
  110. package/src/contexts/fep-22cd.json +21 -0
  111. package/src/contexts/fep-6757.json +12 -0
  112. package/src/contexts/joinmastodon.json +1 -1
  113. package/src/contexts/miscellany.json +17 -0
  114. package/src/contexts.ts +47 -1
  115. package/src/digest.test.ts +220 -0
  116. package/src/digest.ts +229 -0
  117. package/src/docloader.test.ts +1066 -27
  118. package/src/docloader.ts +322 -105
  119. package/src/internal/jsonld-cache.ts +97 -1
  120. package/src/internal/portable-dereference.test.ts +254 -0
  121. package/src/internal/portable-dereference.ts +1000 -0
  122. package/src/internal/signed-representation.ts +565 -0
  123. package/src/jsonld-cache.test.ts +89 -0
  124. package/src/key.test.ts +9 -0
  125. package/src/key.ts +11 -1
  126. package/src/langstr.test.ts +18 -1
  127. package/src/langstr.ts +6 -2
  128. package/src/langtag.test.ts +53 -0
  129. package/src/langtag.ts +76 -0
  130. package/src/mod.ts +29 -0
  131. package/src/multibase/multibase.test.ts +5 -5
  132. package/src/portable-media.test.ts +293 -0
  133. package/src/portable-media.ts +264 -0
  134. package/src/portable-workers.test.ts +81 -0
  135. package/src/portable.ts +180 -0
  136. package/src/preprocessor.ts +7 -0
  137. package/src/request.test.ts +10 -1
  138. package/src/request.ts +9 -1
  139. package/src/signed-representation.test.ts +338 -0
  140. package/src/url.test.ts +823 -3
  141. package/src/url.ts +700 -23
  142. package/tsdown.config.ts +2 -0
  143. package/dist/tests/url-CsOV_B_P.cjs +0 -482
  144. package/dist/tests/url-Du7RQQgP.mjs +0 -392
  145. package/dist/url-DD4F0ULf.cjs +0 -483
  146. package/dist/url-DGVbSVVi.js +0 -393
  147. /package/dist/{chunk-M78iaK0I.cjs → rolldown-runtime-B7lfambq.cjs} +0 -0
  148. /package/dist/tests/{link-NUUWCdnK.mjs → link-Cevmc87v.mjs} +0 -0
  149. /package/dist/tests/{link-FguCydMA.cjs → link-DlKm8bEr.cjs} +0 -0
  150. /package/dist/tests/{multicodec-CxGVGa91.cjs → multicodec-CLRPeW4N.cjs} +0 -0
  151. /package/dist/tests/{multicodec-CyFp54fI.mjs → multicodec-CRIj_05H.mjs} +0 -0
  152. /package/dist/tests/{chunk-C2EiDwsr.cjs → rolldown-runtime-emK7D4bc.cjs} +0 -0
@@ -1,282 +1,88 @@
1
- import { a as formatIri, c as haveSameIriOrigin, p as parseIri, s as haveSameFe34Origin } from "./url-Du7RQQgP.mjs";
2
- import { deepStrictEqual, ok, strictEqual } from "node:assert";
1
+ import { _ as parseIri } from "./url-DMxmp7ZG.mjs";
2
+ import { t as jsonld_default } from "./jsonld-DweIJ07b.mjs";
3
+ import { a as isTrustedIriOrigin, i as getPortableActorGateways, o as normalizeJsonLdIris, r as getJsonLdContext, t as compactJsonLdCache } from "./jsonld-cache-DFnWsLuZ.mjs";
3
4
  import { test } from "node:test";
4
- import jsonld from "jsonld/dist/jsonld.esm.js";
5
- //#region src/jsonld.ts
6
- var jsonld_default = jsonld;
7
- //#endregion
8
- //#region src/internal/jsonld-cache.ts
9
- const noJsonLdContext = Symbol("noJsonLdContext");
10
- /**
11
- * Checks whether an IRI is trusted relative to another IRI.
12
- *
13
- * @internal Technically exported for generated vocabulary classes, but not
14
- * part of the public API contract. This is not considered public API for
15
- * Semantic Versioning decisions.
16
- */
17
- function isTrustedIriOrigin(options, left, right) {
18
- return options.crossOrigin === "trust" || left == null || right != null && (haveSameIriOrigin(left, right) || haveSameFe34Origin(left, right));
19
- }
20
- /**
21
- * Normalizes portable IRIs in JSON-LD cache data.
22
- *
23
- * @internal Technically exported for generated vocabulary classes, but not
24
- * part of the public API contract. This is not considered public API for
25
- * Semantic Versioning decisions.
26
- */
27
- function normalizeJsonLdIris(value, iriKeys, iriPattern = /^ap(?:\+ef61)?:\/\//i) {
28
- return normalize(value, void 0, 0, void 0);
29
- function isIriPosition(key, parentKey) {
30
- return iriKeys.has(key) || (key === "@value" || key === "@list" || key === "@set") && parentKey != null && iriKeys.has(parentKey);
31
- }
32
- function arrayItemParentKey(key, parentKey) {
33
- return key === "@list" || key === "@set" ? parentKey : key;
34
- }
35
- function entryParentKey(entryKey, key, parentKey) {
36
- if (entryKey === "@list" || entryKey === "@set") return parentKey ?? key;
37
- return key === "@list" || key === "@set" ? parentKey : key;
38
- }
39
- function normalize(value, key, depth = 0, parentKey) {
40
- if (depth > 32 || key === "@context") return value;
41
- if (typeof value === "string") {
42
- if (key != null && isIriPosition(key, parentKey) && iriPattern.test(value)) try {
43
- return formatIri(value);
44
- } catch {
45
- return value;
46
- }
47
- return value;
48
- }
49
- if (Array.isArray(value)) {
50
- let clone;
51
- const itemParentKey = arrayItemParentKey(key, parentKey);
52
- for (let i = 0; i < value.length; i++) {
53
- const result = normalize(value[i], key, depth + 1, itemParentKey);
54
- if (result !== value[i]) {
55
- clone ??= value.slice(0, i);
56
- clone.push(result);
57
- } else if (clone != null) clone.push(value[i]);
58
- }
59
- return clone ?? value;
60
- }
61
- if (value == null || typeof value !== "object") return value;
62
- const object = value;
63
- let clone;
64
- for (const entryKey of globalThis.Object.keys(object)) {
65
- const result = normalize(object[entryKey], entryKey, depth + 1, entryParentKey(entryKey, key, parentKey));
66
- if (result !== object[entryKey]) {
67
- clone ??= { ...object };
68
- defineJsonLdProperty(clone, entryKey, result);
69
- }
70
- }
71
- return clone ?? object;
72
- }
73
- }
74
- /**
75
- * Finds the first JSON-LD context in a value.
76
- *
77
- * @internal Technically exported for generated vocabulary classes, but not
78
- * part of the public API contract. This is not considered public API for
79
- * Semantic Versioning decisions.
80
- */
81
- function getJsonLdContext(value, depth = 0) {
82
- if (depth > 32) return void 0;
83
- if (Array.isArray(value)) {
84
- for (const item of value) {
85
- const context = getJsonLdContext(item, depth + 1);
86
- if (context !== void 0) return context;
87
- }
88
- return;
89
- }
90
- if (value == null || typeof value !== "object" || !("@context" in value)) return;
91
- return value["@context"];
92
- }
93
- function getOwnJsonLdContext(value) {
94
- if (value == null || typeof value !== "object" || Array.isArray(value) || !("@context" in value)) return noJsonLdContext;
95
- return value["@context"];
96
- }
97
- /**
98
- * Recompacts normalized JSON-LD cache data against the original context.
99
- *
100
- * @internal Technically exported for generated vocabulary classes, but not
101
- * part of the public API contract. This is not considered public API for
102
- * Semantic Versioning decisions.
103
- */
104
- async function compactJsonLdCache(normalized, original, documentLoader, depth = 0, inheritedContext) {
105
- if (depth > 32) return normalized;
106
- if (Array.isArray(original)) {
107
- const normalizedArray = Array.isArray(normalized) ? normalized : normalized != null && typeof normalized === "object" && "@graph" in normalized && Array.isArray(normalized["@graph"]) ? normalized["@graph"] : void 0;
108
- if (normalizedArray == null) return normalized;
109
- let clone;
110
- for (let i = 0; i < normalizedArray.length; i++) {
111
- const item = await compactJsonLdCache(normalizedArray[i], original[i], documentLoader, depth + 1, inheritedContext);
112
- if (item !== normalizedArray[i]) {
113
- clone ??= normalizedArray.slice(0, i);
114
- clone.push(item);
115
- } else if (clone != null) clone.push(normalizedArray[i]);
116
- }
117
- return clone ?? (Array.isArray(normalized) ? normalized : normalizedArray);
118
- }
119
- const ownContext = getOwnJsonLdContext(original);
120
- const context = ownContext === noJsonLdContext ? inheritedContext : ownContext;
121
- if (context == null) return preserveNoContextJsonLdShape(normalized, original, depth);
122
- return await preserveJsonLdShape(await mergeUnmappedTerms(await jsonld_default.compact(Array.isArray(normalized) && normalized.length === 1 ? normalized[0] : normalized, context, { documentLoader }), original, context, documentLoader), original, context, documentLoader, depth);
123
- }
124
- function preserveNoContextJsonLdShape(normalized, original, depth = 0) {
125
- if (depth > 32) return normalized;
126
- if (original == null || typeof original !== "object" || Array.isArray(original)) return normalized;
127
- const normalizedObject = Array.isArray(normalized) && normalized.length === 1 ? normalized[0] : normalized;
128
- if (normalizedObject == null || typeof normalizedObject !== "object" || Array.isArray(normalizedObject)) return normalized;
129
- const source = normalizedObject;
130
- const originalObject = original;
131
- let clone;
132
- for (const key of globalThis.Object.keys(originalObject)) {
133
- if (!globalThis.Object.prototype.hasOwnProperty.call(source, key)) continue;
134
- const value = preserveNoContextValue(source[key], originalObject[key], depth + 1);
135
- if (value !== originalObject[key]) {
136
- clone ??= { ...originalObject };
137
- defineJsonLdProperty(clone, key, value);
138
- }
139
- }
140
- return clone ?? original;
141
- }
142
- function preserveNoContextValue(normalized, original, depth) {
143
- if (depth > 32) return normalized;
144
- if (Array.isArray(original)) {
145
- const normalizedArray = Array.isArray(normalized) ? normalized : [normalized];
146
- let clone;
147
- for (let i = 0; i < original.length; i++) {
148
- const value = preserveNoContextValue(normalizedArray[i], original[i], depth + 1);
149
- if (value !== original[i]) {
150
- clone ??= original.slice(0, i);
151
- clone.push(value);
152
- } else if (clone != null) clone.push(original[i]);
153
- }
154
- return clone ?? original;
155
- }
156
- const normalizedValue = Array.isArray(normalized) ? normalized[0] : normalized;
157
- if (normalizedValue == null || typeof normalizedValue !== "object" || Array.isArray(normalizedValue)) return normalizedValue;
158
- const normalizedObject = normalizedValue;
159
- if (original != null && typeof original === "object" && !Array.isArray(original)) return preserveNoContextJsonLdShape(normalizedObject, original, depth + 1);
160
- if (typeof normalizedObject["@id"] === "string") return normalizedObject["@id"];
161
- if ("@value" in normalizedObject) return normalizedObject["@value"];
162
- return normalizedValue;
163
- }
164
- function getTopLevelTerms(value) {
165
- const terms = /* @__PURE__ */ new Set();
166
- const nodes = Array.isArray(value) ? value : [value];
167
- for (const node of nodes) {
168
- if (node == null || typeof node !== "object" || Array.isArray(node)) continue;
169
- for (const key of globalThis.Object.keys(node)) {
170
- if (key.startsWith("@")) continue;
171
- terms.add(key);
172
- }
173
- }
174
- return terms;
175
- }
176
- async function mergeUnmappedTerms(compacted, original, context, documentLoader) {
177
- if (original == null || typeof original !== "object" || Array.isArray(original) || compacted == null || typeof compacted !== "object" || Array.isArray(compacted)) return compacted;
178
- const unmappedKeys = globalThis.Object.keys(original).filter((key) => key !== "@context" && !globalThis.Object.prototype.hasOwnProperty.call(compacted, key));
179
- if (unmappedKeys.length < 1) return compacted;
180
- const result = { ...compacted };
181
- const compactedWithContext = compacted != null && typeof compacted === "object" && !Array.isArray(compacted) && !("@context" in compacted) ? {
182
- "@context": context,
183
- ...compacted
184
- } : compacted;
185
- const compactedTerms = getTopLevelTerms(await jsonld_default.expand(compactedWithContext, { documentLoader }));
186
- const dummyPrefix = "urn:fedify:dummy:";
187
- const dummy = { "@context": context };
188
- for (let i = 0; i < unmappedKeys.length; i++) defineJsonLdProperty(dummy, unmappedKeys[i], `${dummyPrefix}${i}`);
189
- const expanded = await jsonld_default.expand(dummy, { documentLoader });
190
- const representedKeys = /* @__PURE__ */ new Set();
191
- const nodes = Array.isArray(expanded) ? expanded : [expanded];
192
- for (const node of nodes) {
193
- if (node == null || typeof node !== "object" || Array.isArray(node)) continue;
194
- for (const [term, termValue] of globalThis.Object.entries(node)) {
195
- if (!compactedTerms.has(term)) continue;
196
- for (let i = 0; i < unmappedKeys.length; i++) if (containsValue(termValue, `${dummyPrefix}${i}`)) representedKeys.add(unmappedKeys[i]);
197
- }
198
- }
199
- for (const key of unmappedKeys) if (!representedKeys.has(key)) defineJsonLdProperty(result, key, original[key]);
200
- return result;
201
- }
202
- function defineJsonLdProperty(object, key, value) {
203
- globalThis.Object.defineProperty(object, key, {
204
- value,
205
- enumerable: true,
206
- configurable: true,
207
- writable: true
208
- });
209
- }
210
- function containsValue(value, expected, depth = 0) {
211
- if (depth > 32) return false;
212
- if (value === expected) return true;
213
- if (Array.isArray(value)) return value.some((item) => containsValue(item, expected, depth + 1));
214
- if (value == null || typeof value !== "object") return false;
215
- return globalThis.Object.entries(value).some(([key, item]) => key !== "@context" && containsValue(item, expected, depth + 1));
216
- }
217
- async function preserveJsonLdShape(compacted, original, context, documentLoader, depth = 0) {
218
- if (depth > 32) return compacted;
219
- if (compacted === original) return compacted;
220
- if (original == null || typeof original !== "object" || compacted == null || typeof compacted !== "object") return compacted;
221
- if (Array.isArray(original)) {
222
- const compactedArray = Array.isArray(compacted) ? compacted : "@graph" in compacted && Array.isArray(compacted["@graph"]) ? compacted["@graph"] : void 0;
223
- if (compactedArray == null) return compacted;
224
- let clone;
225
- for (let i = 0; i < compactedArray.length; i++) {
226
- const value = await preserveJsonLdShape(compactedArray[i], original[i], context, documentLoader, depth + 1);
227
- const originalContext = original[i] != null && typeof original[i] === "object" && !Array.isArray(original[i]) && "@context" in original[i] ? original[i]["@context"] : void 0;
228
- const shaped = originalContext !== void 0 && value != null && typeof value === "object" && !Array.isArray(value) && !("@context" in value) ? {
229
- "@context": originalContext,
230
- ...value
231
- } : value;
232
- if (shaped !== compactedArray[i]) {
233
- clone ??= compactedArray.slice(0, i);
234
- clone.push(shaped);
235
- } else if (clone != null) clone.push(compactedArray[i]);
236
- }
237
- return clone ?? (Array.isArray(compacted) ? compacted : compactedArray);
5
+ import { deepStrictEqual, ok, strictEqual } from "node:assert";
6
+ //#region src/jsonld-cache.test.ts
7
+ test("getPortableActorGateways() preserves unmapped portable actor gateways", () => {
8
+ const gateways = [
9
+ { "@value": "https://second.example" },
10
+ { "@value": "https://first.example" },
11
+ { "@value": "not a valid gateway" }
12
+ ];
13
+ for (const id of [
14
+ "ap://did:key:z6Mkabc/actor",
15
+ "ap+ef61://did:key:z6Mkabc/actor",
16
+ "https://gateway.example/.well-known/apgateway/did:key:z6Mkabc/actor"
17
+ ]) {
18
+ const node = {
19
+ "@id": id,
20
+ "http://www.w3.org/ns/ldp#inbox": [{ "@id": `${id}/inbox` }],
21
+ "https://www.w3.org/ns/activitystreams#outbox": [{ "@id": `${id}/outbox` }],
22
+ "_:gateways": gateways
23
+ };
24
+ const original = structuredClone(node);
25
+ strictEqual(getPortableActorGateways(node), gateways, id);
26
+ strictEqual(getPortableActorGateways(node, false), void 0, id);
27
+ deepStrictEqual(node, original);
238
28
  }
239
- if (Array.isArray(compacted)) return compacted;
240
- let clone;
241
- const ownContext = getOwnJsonLdContext(original);
242
- const objectContext = combineContexts(context, ownContext);
243
- const objectCompacted = depth > 0 && ownContext === null ? await compactWithEmptyContext(compacted, context, documentLoader) : compacted;
244
- const compactedObject = depth > 0 ? await mergeUnmappedTerms(objectCompacted, original, objectContext, documentLoader) : objectCompacted;
245
- const originalObject = original;
246
- for (const key of globalThis.Object.keys(compactedObject)) {
247
- if (key === "@context") continue;
248
- const value = await preserveJsonLdShape(compactedObject[key], originalObject[key], objectContext, documentLoader, depth + 1);
249
- const shaped = Array.isArray(originalObject[key]) && !Array.isArray(value) ? [value] : value;
250
- if (shaped !== compactedObject[key]) {
251
- clone ??= { ...compactedObject };
252
- defineJsonLdProperty(clone, key, shaped);
253
- }
29
+ });
30
+ test("getPortableActorGateways() gives mapped gateways precedence", () => {
31
+ const canonical = "https://w3id.org/fep/ef61/gateways";
32
+ const gateways = [{ "@list": [{ "@id": "https://gateway.example" }] }];
33
+ const node = {
34
+ "@id": "ap://did:key:z6Mkabc/actor",
35
+ "http://www.w3.org/ns/ldp#inbox": [],
36
+ "https://www.w3.org/ns/activitystreams#outbox": [],
37
+ "_:gateways": [{ "@value": "https://other.example" }],
38
+ [canonical]: gateways
39
+ };
40
+ strictEqual(getPortableActorGateways(node), gateways);
41
+ strictEqual(getPortableActorGateways(node, false), gateways);
42
+ for (const value of [
43
+ void 0,
44
+ null,
45
+ {},
46
+ "https://gateway.example",
47
+ []
48
+ ]) {
49
+ node[canonical] = value;
50
+ strictEqual(getPortableActorGateways(node), Array.isArray(value) ? value : void 0);
254
51
  }
255
- if (depth > 0) {
256
- if ("@context" in originalObject && !("@context" in compactedObject)) {
257
- clone ??= { ...compactedObject };
258
- clone["@context"] = originalObject["@context"];
259
- }
52
+ });
53
+ test("getPortableActorGateways() limits unmapped terms to portable actors", () => {
54
+ const node = {
55
+ "@id": "ap://did:key:z6Mkabc/actor",
56
+ "http://www.w3.org/ns/ldp#inbox": [],
57
+ "https://www.w3.org/ns/activitystreams#outbox": [],
58
+ "_:gateways": [{ "@value": "https://gateway.example" }]
59
+ };
60
+ for (const id of [
61
+ void 0,
62
+ 1,
63
+ "not an IRI",
64
+ "https://ordinary.example/actor",
65
+ "https://gateway.example/.well-known/apgateway/not-a-did/actor",
66
+ "https://user@gateway.example/.well-known/apgateway/did:key:z6Mkabc/actor"
67
+ ]) strictEqual(getPortableActorGateways({
68
+ ...node,
69
+ "@id": id
70
+ }), void 0);
71
+ for (const property of ["http://www.w3.org/ns/ldp#inbox", "https://www.w3.org/ns/activitystreams#outbox"]) {
72
+ const nonActor = { ...node };
73
+ delete nonActor[property];
74
+ strictEqual(getPortableActorGateways(nonActor), void 0);
260
75
  }
261
- return clone ?? compactedObject;
262
- }
263
- async function compactWithEmptyContext(compacted, context, documentLoader) {
264
- const compactedWithContext = compacted != null && typeof compacted === "object" && !Array.isArray(compacted) && !("@context" in compacted) ? {
265
- "@context": context,
266
- ...compacted
267
- } : compacted;
268
- const expanded = await jsonld_default.expand(compactedWithContext, { documentLoader });
269
- return await jsonld_default.compact(expanded, {}, { documentLoader });
270
- }
271
- function combineContexts(inheritedContext, ownContext) {
272
- if (ownContext === noJsonLdContext || ownContext === inheritedContext) return inheritedContext;
273
- if (ownContext == null) return ownContext;
274
- const inherited = Array.isArray(inheritedContext) ? inheritedContext : [inheritedContext];
275
- const own = Array.isArray(ownContext) ? ownContext : [ownContext];
276
- return [...inherited, ...own];
277
- }
278
- //#endregion
279
- //#region src/jsonld-cache.test.ts
76
+ strictEqual(getPortableActorGateways({
77
+ ...node,
78
+ "_:gateways": null
79
+ }), void 0);
80
+ const empty = [];
81
+ strictEqual(getPortableActorGateways({
82
+ ...node,
83
+ "_:gateways": empty
84
+ }), empty);
85
+ });
280
86
  test("isTrustedIriOrigin() trusts same portable IRI origins", () => {
281
87
  ok(isTrustedIriOrigin({}, parseIri("ap://did:key:z6Mkabc/actor"), parseIri("ap+ef61://did:key:z6Mkabc/outbox")));
282
88
  ok(!isTrustedIriOrigin({}, parseIri("ap://did:key:z6Mkabc/actor"), parseIri("ap://did:key:z6Mkdef/outbox")));
@@ -287,17 +93,17 @@ test("normalizeJsonLdIris() normalizes selected JSON-LD IRI positions", () => {
287
93
  "@id": "ap://did:key:z6Mkabc/object",
288
94
  "https://example.com/ns#ref": [{ "@value": "ap://did:key:z6Mkabc/ref" }],
289
95
  "https://example.com/ns#text": [{ "@value": "ap://did:key:z6Mkabc/not-an-iri-position" }]
290
- }, new Set(["@id", "https://example.com/ns#ref"])), {
96
+ }, /* @__PURE__ */ new Set(["@id", "https://example.com/ns#ref"])), {
291
97
  "@id": "ap+ef61://did:key:z6Mkabc/object",
292
98
  "https://example.com/ns#ref": [{ "@value": "ap+ef61://did:key:z6Mkabc/ref" }],
293
99
  "https://example.com/ns#text": [{ "@value": "ap://did:key:z6Mkabc/not-an-iri-position" }]
294
100
  });
295
101
  });
296
102
  test("normalizeJsonLdIris() preserves IRI context in list/set wrappers", () => {
297
- deepStrictEqual(normalizeJsonLdIris({ "https://example.com/ns#ref": [{ "@list": [{ "@value": "ap://did:key:z6Mkabc/listed" }] }, { "@set": [{ "@value": "ap://did:key:z6Mkabc/set" }] }] }, new Set(["https://example.com/ns#ref"])), { "https://example.com/ns#ref": [{ "@list": [{ "@value": "ap+ef61://did:key:z6Mkabc/listed" }] }, { "@set": [{ "@value": "ap+ef61://did:key:z6Mkabc/set" }] }] });
103
+ deepStrictEqual(normalizeJsonLdIris({ "https://example.com/ns#ref": [{ "@list": [{ "@value": "ap://did:key:z6Mkabc/listed" }] }, { "@set": [{ "@value": "ap://did:key:z6Mkabc/set" }] }] }, /* @__PURE__ */ new Set(["https://example.com/ns#ref"])), { "https://example.com/ns#ref": [{ "@list": [{ "@value": "ap+ef61://did:key:z6Mkabc/listed" }] }, { "@set": [{ "@value": "ap+ef61://did:key:z6Mkabc/set" }] }] });
298
104
  });
299
105
  test("normalizeJsonLdIris() defines prototype-like keys safely", () => {
300
- const iriKeys = new Set(["__proto__"]);
106
+ const iriKeys = /* @__PURE__ */ new Set(["__proto__"]);
301
107
  const value = {};
302
108
  globalThis.Object.defineProperty(value, "__proto__", {
303
109
  value: "ap://did:key:z6Mkabc/object",
@@ -320,7 +126,7 @@ test("compactJsonLdCache() preserves no-context object shape", async () => {
320
126
  "https://www.w3.org/ns/activitystreams#attributedTo": [{ "@id": "ap://did:key:z6Mkabc/actor" }],
321
127
  "https://www.w3.org/ns/activitystreams#content": [{ "@value": "No-context object shape should stay cached." }]
322
128
  };
323
- deepStrictEqual(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id", "https://www.w3.org/ns/activitystreams#attributedTo"])), original), {
129
+ deepStrictEqual(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), /* @__PURE__ */ new Set(["@id", "https://www.w3.org/ns/activitystreams#attributedTo"])), original), {
324
130
  "@id": "ap+ef61://did:key:z6Mkabc/objects/1",
325
131
  "@type": ["https://www.w3.org/ns/activitystreams#Note"],
326
132
  "https://www.w3.org/ns/activitystreams#attributedTo": [{ "@id": "ap+ef61://did:key:z6Mkabc/actor" }],
@@ -341,7 +147,7 @@ test("compactJsonLdCache() ignores nested contexts for no-context parents", asyn
341
147
  name: "Nested object"
342
148
  }]
343
149
  };
344
- deepStrictEqual(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original), {
150
+ deepStrictEqual(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), /* @__PURE__ */ new Set(["@id"])), original), {
345
151
  "@id": "ap+ef61://did:key:z6Mkabc/objects/1",
346
152
  "@type": ["https://www.w3.org/ns/activitystreams#Note"],
347
153
  "https://www.w3.org/ns/activitystreams#attachment": [{
@@ -388,7 +194,7 @@ test("compactJsonLdCache() preserves nested unmapped terms", async () => {
388
194
  extra: "This nested unmapped property should stay cached."
389
195
  }
390
196
  };
391
- deepStrictEqual(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original), {
197
+ deepStrictEqual(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), /* @__PURE__ */ new Set(["@id"])), original), {
392
198
  "@context": context,
393
199
  type: "as:Note",
394
200
  id: "ap+ef61://did:key:z6Mkabc/objects/1",
@@ -420,7 +226,7 @@ test("compactJsonLdCache() reuses unchanged unmapped values", async () => {
420
226
  extra
421
227
  }
422
228
  };
423
- const compacted = await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original);
229
+ const compacted = await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), /* @__PURE__ */ new Set(["@id"])), original);
424
230
  strictEqual(compacted.rootExtra, rootExtra);
425
231
  strictEqual(compacted.attachment.extra, extra);
426
232
  });
@@ -441,7 +247,7 @@ test("compactJsonLdCache() defines prototype-like unmapped keys safely", async (
441
247
  configurable: true,
442
248
  writable: true
443
249
  });
444
- const compacted = await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original);
250
+ const compacted = await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), /* @__PURE__ */ new Set(["@id"])), original);
445
251
  strictEqual(globalThis.Object.getOwnPropertyDescriptor(compacted, "__proto__")?.value, protoValue);
446
252
  strictEqual(globalThis.Object.getPrototypeOf(compacted), Object.prototype);
447
253
  });
@@ -468,7 +274,7 @@ test("compactJsonLdCache() checks prototype-like aliases safely", async () => {
468
274
  configurable: true,
469
275
  writable: true
470
276
  });
471
- const compacted = await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original);
277
+ const compacted = await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), /* @__PURE__ */ new Set(["@id"])), original);
472
278
  const protoDescriptor = globalThis.Object.getOwnPropertyDescriptor(compacted, "__proto__");
473
279
  ok(protoDescriptor?.value === "Alias represented by the compacted term." || Array.isArray(protoDescriptor?.value) && protoDescriptor.value.includes("Alias represented by the compacted term."));
474
280
  strictEqual(protoDescriptor?.enumerable, true);
@@ -498,7 +304,7 @@ test("compactJsonLdCache() preserves nested contexts", async () => {
498
304
  title: "Nested title."
499
305
  }
500
306
  };
501
- deepStrictEqual(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original), {
307
+ deepStrictEqual(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), /* @__PURE__ */ new Set(["@id"])), original), {
502
308
  "@context": context,
503
309
  type: "as:Note",
504
310
  id: "ap+ef61://did:key:z6Mkabc/objects/1",
@@ -530,7 +336,7 @@ test("compactJsonLdCache() preserves nested array contexts", async () => {
530
336
  title: "Nested title."
531
337
  }
532
338
  };
533
- deepStrictEqual(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original), {
339
+ deepStrictEqual(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), /* @__PURE__ */ new Set(["@id"])), original), {
534
340
  "@context": context,
535
341
  type: "as:Note",
536
342
  id: "ap+ef61://did:key:z6Mkabc/objects/1",
@@ -558,7 +364,7 @@ test("compactJsonLdCache() preserves nested null contexts", async () => {
558
364
  "https://example.com/ns#title": "Absolute title."
559
365
  }
560
366
  };
561
- deepStrictEqual(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original), {
367
+ deepStrictEqual(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), /* @__PURE__ */ new Set(["@id"])), original), {
562
368
  "@context": context,
563
369
  type: "as:Note",
564
370
  id: "ap+ef61://did:key:z6Mkabc/objects/1",
@@ -597,7 +403,7 @@ test("compactJsonLdCache() does not re-add represented nested aliases", async ()
597
403
  actorRef: "ap://did:key:z6Mkabc/actor"
598
404
  }
599
405
  };
600
- deepStrictEqual(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id", "https://www.w3.org/ns/activitystreams#actor"])), original), {
406
+ deepStrictEqual(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), /* @__PURE__ */ new Set(["@id", "https://www.w3.org/ns/activitystreams#actor"])), original), {
601
407
  "@context": context,
602
408
  type: "as:Note",
603
409
  id: "ap+ef61://did:key:z6Mkabc/objects/1",
@@ -631,7 +437,7 @@ test("compactJsonLdCache() does not confuse dummy marker prefixes", async () =>
631
437
  key9: "Extension 9",
632
438
  key10: "Alias represented by the compacted term."
633
439
  };
634
- deepStrictEqual(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original), {
440
+ deepStrictEqual(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), /* @__PURE__ */ new Set(["@id"])), original), {
635
441
  "@context": context,
636
442
  id: "ap+ef61://did:key:z6Mkabc/objects/1",
637
443
  key0: "Extension 0",
@@ -1,6 +1,5 @@
1
- require("./chunk-C2EiDwsr.cjs");
2
- const require_multicodec = require("./multicodec-CxGVGa91.cjs");
3
- const require_multibase = require("./multibase-Bz_UUDtL.cjs");
1
+ const require_multicodec = require("./multicodec-CLRPeW4N.cjs");
2
+ const require_multibase = require("./multibase-B5Mea7Ip.cjs");
4
3
  let asn1js = require("asn1js");
5
4
  let byte_encodings_base64 = require("byte-encodings/base64");
6
5
  let byte_encodings_base64url = require("byte-encodings/base64url");
@@ -143,12 +142,20 @@ async function importDidKey(did) {
143
142
  /**
144
143
  * Exports an Ed25519 public key as a `did:key` DID.
145
144
  *
145
+ * The DID is encoded in base58-btc with the Ed25519 multicodec prefix, e.g.,
146
+ * `did:key:z6Mk...`, as [FEP-ef61] requires for the DIDs of portable
147
+ * objects.
148
+ *
149
+ * [FEP-ef61]: https://w3id.org/fep/ef61
150
+ *
146
151
  * @param key The Ed25519 public key.
147
152
  * @returns The `did:key` DID.
148
- * @throws {TypeError} If the key is invalid or unsupported.
153
+ * @throws {TypeError} If the key is invalid or unsupported, or it is not
154
+ * a public key.
149
155
  * @since 2.4.0
150
156
  */
151
157
  async function exportDidKey(key) {
158
+ if (key.type !== "public") throw new TypeError("The key must be a public key.");
152
159
  if (key.algorithm.name !== "Ed25519") throw new TypeError("Unsupported key type: " + JSON.stringify(key.algorithm));
153
160
  return DID_KEY_PREFIX + await exportMultibaseKey(key);
154
161
  }
@@ -1,5 +1,5 @@
1
- import { n as getMulticodecPrefix, r as removeMulticodecPrefix, t as addMulticodecPrefix } from "./multicodec-CyFp54fI.mjs";
2
- import { n as encodeMultibase, t as decodeMultibase } from "./multibase-B4bvakyA.mjs";
1
+ import { n as getMulticodecPrefix, r as removeMulticodecPrefix, t as addMulticodecPrefix } from "./multicodec-CRIj_05H.mjs";
2
+ import { n as encodeMultibase, t as decodeMultibase } from "./multibase-BPnF_L4e.mjs";
3
3
  import { Integer, Sequence } from "asn1js";
4
4
  import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
5
5
  import { decodeBase64Url } from "byte-encodings/base64url";
@@ -142,12 +142,20 @@ async function importDidKey(did) {
142
142
  /**
143
143
  * Exports an Ed25519 public key as a `did:key` DID.
144
144
  *
145
+ * The DID is encoded in base58-btc with the Ed25519 multicodec prefix, e.g.,
146
+ * `did:key:z6Mk...`, as [FEP-ef61] requires for the DIDs of portable
147
+ * objects.
148
+ *
149
+ * [FEP-ef61]: https://w3id.org/fep/ef61
150
+ *
145
151
  * @param key The Ed25519 public key.
146
152
  * @returns The `did:key` DID.
147
- * @throws {TypeError} If the key is invalid or unsupported.
153
+ * @throws {TypeError} If the key is invalid or unsupported, or it is not
154
+ * a public key.
148
155
  * @since 2.4.0
149
156
  */
150
157
  async function exportDidKey(key) {
158
+ if (key.type !== "public") throw new TypeError("The key must be a public key.");
151
159
  if (key.algorithm.name !== "Ed25519") throw new TypeError("Unsupported key type: " + JSON.stringify(key.algorithm));
152
160
  return DID_KEY_PREFIX + await exportMultibaseKey(key);
153
161
  }
@@ -1,9 +1,8 @@
1
- require("./chunk-C2EiDwsr.cjs");
2
- const require_multicodec = require("./multicodec-CxGVGa91.cjs");
3
- const require_key = require("./key-_wXwomh_.cjs");
4
- const require_multibase = require("./multibase-Bz_UUDtL.cjs");
5
- let node_assert = require("node:assert");
1
+ const require_multicodec = require("./multicodec-CLRPeW4N.cjs");
2
+ const require_key = require("./key-C-AYkdJJ.cjs");
3
+ const require_multibase = require("./multibase-B5Mea7Ip.cjs");
6
4
  let node_test = require("node:test");
5
+ let node_assert = require("node:assert");
7
6
  //#region src/key.test.ts
8
7
  const rsaSpki = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxsRuvCkgJtflBTl4OVsm\nnt/J1mQfZasfJtN33dcZ3d1lJroxmgmMu69zjGEAwkNbMQaWNLqC4eogkJaeJ4RR\n5MHYXkL9nNilVoTkjX5BVit3puzs7XJ7WQnKQgQMI+ezn24GHsZ/v1JIo77lerX5\nk4HNwTNVt+yaZVQWaOMR3+6FwziQR6kd0VuG9/a9dgAnz2cEoORRC1i4W7IZaB1s\nZnh1WbHbevlGd72HSXll5rocPIHn8gq6xpBgpHwRphlRsgn4KHaJ6brXDIJjrnQh\nIe/YUBOGj/ImSEXhRwlFerKsoAVnZ0Hwbfa46qk44TAt8CyoPMWmpK6pt0ng4pQ2\nuwIDAQAB\n-----END PUBLIC KEY-----\n";
9
8
  const rsaPkcs1 = "-----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCAQEAxsRuvCkgJtflBTl4OVsmnt/J1mQfZasfJtN33dcZ3d1lJroxmgmM\nu69zjGEAwkNbMQaWNLqC4eogkJaeJ4RR5MHYXkL9nNilVoTkjX5BVit3puzs7XJ7\nWQnKQgQMI+ezn24GHsZ/v1JIo77lerX5k4HNwTNVt+yaZVQWaOMR3+6FwziQR6kd\n0VuG9/a9dgAnz2cEoORRC1i4W7IZaB1sZnh1WbHbevlGd72HSXll5rocPIHn8gq6\nxpBgpHwRphlRsgn4KHaJ6brXDIJjrnQhIe/YUBOGj/ImSEXhRwlFerKsoAVnZ0Hw\nbfa46qk44TAt8CyoPMWmpK6pt0ng4pQ2uwIDAQAB\n-----END RSA PUBLIC KEY-----\n";
@@ -79,6 +78,8 @@ const ed25519Multibase = "z6MksHj1MJnidCtDiyYW9ugNFftoX9fLK4bornTxmMZ6X7vq";
79
78
  (0, node_assert.deepStrictEqual)(await require_key.exportJwk(await require_key.importDidKey(new URL(did))), ed25519Jwk);
80
79
  const rsaKey = await require_key.importJwk(rsaJwk, "public");
81
80
  await (0, node_assert.rejects)(() => require_key.exportDidKey(rsaKey), TypeError);
81
+ const { privateKey } = await crypto.subtle.generateKey("Ed25519", true, ["sign", "verify"]);
82
+ await (0, node_assert.rejects)(() => require_key.exportDidKey(privateKey), /* @__PURE__ */ new TypeError("The key must be a public key."));
82
83
  await (0, node_assert.rejects)(() => require_key.importDidKey(`did:key:${rsaMultibase}`), /* @__PURE__ */ new TypeError("Unsupported did:key type: 0x1205"));
83
84
  });
84
85
  (0, node_test.test)("parseDidKeyVerificationMethod()", async () => {
@@ -1,8 +1,8 @@
1
- import { t as addMulticodecPrefix } from "./multicodec-CyFp54fI.mjs";
2
- import { a as importMultibaseKey, c as importSpki, d as importJwk, i as importDidKey, l as parseDidKeyVerificationMethod, n as exportMultibaseKey, o as importPem, r as exportSpki, s as importPkcs1, t as exportDidKey, u as exportJwk } from "./key-CDGDH_vC.mjs";
3
- import { n as encodeMultibase } from "./multibase-B4bvakyA.mjs";
4
- import { deepStrictEqual, rejects } from "node:assert";
1
+ import { t as addMulticodecPrefix } from "./multicodec-CRIj_05H.mjs";
2
+ import { a as importMultibaseKey, c as importSpki, d as importJwk, i as importDidKey, l as parseDidKeyVerificationMethod, n as exportMultibaseKey, o as importPem, r as exportSpki, s as importPkcs1, t as exportDidKey, u as exportJwk } from "./key-C2Db_TAJ.mjs";
3
+ import { n as encodeMultibase } from "./multibase-BPnF_L4e.mjs";
5
4
  import { test } from "node:test";
5
+ import { deepStrictEqual, rejects } from "node:assert";
6
6
  //#region src/key.test.ts
7
7
  const rsaSpki = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxsRuvCkgJtflBTl4OVsm\nnt/J1mQfZasfJtN33dcZ3d1lJroxmgmMu69zjGEAwkNbMQaWNLqC4eogkJaeJ4RR\n5MHYXkL9nNilVoTkjX5BVit3puzs7XJ7WQnKQgQMI+ezn24GHsZ/v1JIo77lerX5\nk4HNwTNVt+yaZVQWaOMR3+6FwziQR6kd0VuG9/a9dgAnz2cEoORRC1i4W7IZaB1s\nZnh1WbHbevlGd72HSXll5rocPIHn8gq6xpBgpHwRphlRsgn4KHaJ6brXDIJjrnQh\nIe/YUBOGj/ImSEXhRwlFerKsoAVnZ0Hwbfa46qk44TAt8CyoPMWmpK6pt0ng4pQ2\nuwIDAQAB\n-----END PUBLIC KEY-----\n";
8
8
  const rsaPkcs1 = "-----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCAQEAxsRuvCkgJtflBTl4OVsmnt/J1mQfZasfJtN33dcZ3d1lJroxmgmM\nu69zjGEAwkNbMQaWNLqC4eogkJaeJ4RR5MHYXkL9nNilVoTkjX5BVit3puzs7XJ7\nWQnKQgQMI+ezn24GHsZ/v1JIo77lerX5k4HNwTNVt+yaZVQWaOMR3+6FwziQR6kd\n0VuG9/a9dgAnz2cEoORRC1i4W7IZaB1sZnh1WbHbevlGd72HSXll5rocPIHn8gq6\nxpBgpHwRphlRsgn4KHaJ6brXDIJjrnQhIe/YUBOGj/ImSEXhRwlFerKsoAVnZ0Hw\nbfa46qk44TAt8CyoPMWmpK6pt0ng4pQ2uwIDAQAB\n-----END RSA PUBLIC KEY-----\n";
@@ -78,6 +78,8 @@ test("exportDidKey() and importDidKey()", async () => {
78
78
  deepStrictEqual(await exportJwk(await importDidKey(new URL(did))), ed25519Jwk);
79
79
  const rsaKey = await importJwk(rsaJwk, "public");
80
80
  await rejects(() => exportDidKey(rsaKey), TypeError);
81
+ const { privateKey } = await crypto.subtle.generateKey("Ed25519", true, ["sign", "verify"]);
82
+ await rejects(() => exportDidKey(privateKey), /* @__PURE__ */ new TypeError("The key must be a public key."));
81
83
  await rejects(() => importDidKey(`did:key:${rsaMultibase}`), /* @__PURE__ */ new TypeError("Unsupported did:key type: 0x1205"));
82
84
  });
83
85
  test("parseDidKeyVerificationMethod()", async () => {
@@ -1,3 +1,4 @@
1
+ import { t as normalizeLanguageTag } from "./langtag-CUppHs_s.mjs";
1
2
  //#region src/langstr.ts
2
3
  /**
3
4
  * A language-tagged string which corresponds to the `rdf:langString` type.
@@ -12,11 +13,13 @@ var LanguageString = class extends String {
12
13
  * Constructs a new `LanguageString`.
13
14
  * @param value A string value written in the given language.
14
15
  * @param language The language of the string. If a string is given, it will
15
- * be parsed as a `Intl.Locale` object.
16
+ * be parsed as a `Intl.Locale` object. Extended language
17
+ * subtags are normalized first, e.g., `zh-yue` is parsed as
18
+ * `yue`.
16
19
  */
17
20
  constructor(value, language) {
18
21
  super(value);
19
- this.locale = typeof language === "string" ? new Intl.Locale(language) : language;
22
+ this.locale = typeof language === "string" ? new Intl.Locale(normalizeLanguageTag(language)) : language;
20
23
  }
21
24
  };
22
25
  LanguageString.prototype[Symbol.for("Deno.customInspect")] = function(inspect, options) {
@@ -1,3 +1,4 @@
1
+ const require_langtag = require("./langtag-Czjvxfzx.cjs");
1
2
  //#region src/langstr.ts
2
3
  /**
3
4
  * A language-tagged string which corresponds to the `rdf:langString` type.
@@ -12,11 +13,13 @@ var LanguageString = class extends String {
12
13
  * Constructs a new `LanguageString`.
13
14
  * @param value A string value written in the given language.
14
15
  * @param language The language of the string. If a string is given, it will
15
- * be parsed as a `Intl.Locale` object.
16
+ * be parsed as a `Intl.Locale` object. Extended language
17
+ * subtags are normalized first, e.g., `zh-yue` is parsed as
18
+ * `yue`.
16
19
  */
17
20
  constructor(value, language) {
18
21
  super(value);
19
- this.locale = typeof language === "string" ? new Intl.Locale(language) : language;
22
+ this.locale = typeof language === "string" ? new Intl.Locale(require_langtag.normalizeLanguageTag(language)) : language;
20
23
  }
21
24
  };
22
25
  LanguageString.prototype[Symbol.for("Deno.customInspect")] = function(inspect, options) {