@fedify/vocab-runtime 2.1.0-dev.543 → 2.1.0-dev.592

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 +4 -3
  2. package/dist/chunk-CUT6urMc.cjs +30 -0
  3. package/dist/jsonld.cjs +8 -0
  4. package/dist/jsonld.d.cts +6 -0
  5. package/dist/jsonld.d.ts +6 -0
  6. package/dist/jsonld.js +7 -0
  7. package/dist/mod.cjs +87 -44
  8. package/dist/mod.js +75 -10
  9. package/dist/tests/docloader.test.cjs +27 -1
  10. package/dist/tests/docloader.test.js +27 -1
  11. package/dist/tests/internal/multicodec.test.cjs +77 -0
  12. package/dist/tests/internal/multicodec.test.d.cts +1 -0
  13. package/dist/tests/internal/multicodec.test.d.ts +1 -0
  14. package/dist/tests/internal/multicodec.test.js +76 -0
  15. package/dist/tests/key.test.cjs +10 -8
  16. package/dist/tests/key.test.js +11 -9
  17. package/dist/tests/multibase/multibase.test.cjs +1 -1
  18. package/dist/tests/multibase/multibase.test.js +1 -1
  19. package/dist/tests/multicodec-DvC5xnX2.js +41 -0
  20. package/dist/tests/multicodec-mHcRzSGY.cjs +59 -0
  21. package/dist/tests/{request-BJJB7u81.cjs → request-CK7hgRUX.cjs} +6 -3
  22. package/dist/tests/{request-Divb6wDy.js → request-DKDE-Rcx.js} +6 -3
  23. package/dist/tests/request.test.cjs +1 -1
  24. package/dist/tests/request.test.js +1 -1
  25. package/package.json +12 -2
  26. package/src/contexts.ts +38 -0
  27. package/src/internal/multicodec.test.ts +68 -0
  28. package/src/internal/multicodec.ts +53 -0
  29. package/src/jsonld.ts +4 -0
  30. package/src/key.test.ts +22 -1
  31. package/src/key.ts +9 -8
  32. package/tsdown.config.ts +2 -2
  33. /package/dist/tests/{multibase-BFbBiaPE.cjs → multibase-B2D6B0V4.cjs} +0 -0
  34. /package/dist/tests/{multibase-DStmqni9.js → multibase-BdHCGO4H.js} +0 -0
package/deno.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@fedify/vocab-runtime",
3
- "version": "2.1.0-dev.543+e09fd1b4",
3
+ "version": "2.1.0-dev.592+6c1f6e6f",
4
4
  "license": "MIT",
5
5
  "exports": {
6
- ".": "./src/mod.ts"
6
+ ".": "./src/mod.ts",
7
+ "./jsonld": "./src/jsonld.ts"
7
8
  },
8
9
  "description": "Runtime library for @fedify/vocab",
9
10
  "author": {
@@ -16,7 +17,7 @@
16
17
  "asn1js": "npm:asn1js@^3.0.6",
17
18
  "byte-encodings": "npm:byte-encodings@^1.0.11",
18
19
  "fetch-mock": "npm:fetch-mock@^12.5.4",
19
- "multicodec": "npm:multicodec@^3.2.1",
20
+ "jsonld": "npm:jsonld@^9.0.0",
20
21
  "pkijs": "npm:pkijs@^3.2.5"
21
22
  },
22
23
  "exclude": [
@@ -0,0 +1,30 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+
25
+ Object.defineProperty(exports, '__toESM', {
26
+ enumerable: true,
27
+ get: function () {
28
+ return __toESM;
29
+ }
30
+ });
@@ -0,0 +1,8 @@
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ const jsonld_dist_jsonld_esm_js = require_chunk.__toESM(require("jsonld/dist/jsonld.esm.js"));
3
+
4
+ //#region src/jsonld.ts
5
+ var jsonld_default = jsonld_dist_jsonld_esm_js.default;
6
+
7
+ //#endregion
8
+ module.exports = jsonld_default;
@@ -0,0 +1,6 @@
1
+ import * as jsonld0 from "jsonld";
2
+
3
+ //#region src/jsonld.d.ts
4
+ declare const _default: typeof jsonld0;
5
+ //#endregion
6
+ export { _default as default };
@@ -0,0 +1,6 @@
1
+ import * as jsonld0 from "jsonld";
2
+
3
+ //#region src/jsonld.d.ts
4
+ declare const _default: typeof jsonld0;
5
+ //#endregion
6
+ export { _default as default };
package/dist/jsonld.js ADDED
@@ -0,0 +1,7 @@
1
+ import jsonld from "jsonld/dist/jsonld.esm.js";
2
+
3
+ //#region src/jsonld.ts
4
+ var jsonld_default = jsonld;
5
+
6
+ //#endregion
7
+ export { jsonld_default as default };
package/dist/mod.cjs CHANGED
@@ -1,39 +1,15 @@
1
- //#region rolldown:runtime
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
- value: mod,
20
- enumerable: true
21
- }) : target, mod));
22
-
23
- //#endregion
24
- const __logtape_logtape = __toESM(require("@logtape/logtape"));
25
- const __opentelemetry_api = __toESM(require("@opentelemetry/api"));
26
- const node_process = __toESM(require("node:process"));
27
- const node_dns_promises = __toESM(require("node:dns/promises"));
28
- const node_net = __toESM(require("node:net"));
29
- const asn1js = __toESM(require("asn1js"));
30
- const byte_encodings_base64 = __toESM(require("byte-encodings/base64"));
31
- const byte_encodings_base64url = __toESM(require("byte-encodings/base64url"));
32
- const byte_encodings_hex = __toESM(require("byte-encodings/hex"));
33
- const multicodec = __toESM(require("multicodec"));
34
- const node_crypto = __toESM(require("node:crypto"));
35
- const pkijs = __toESM(require("pkijs"));
36
- const __multiformats_base_x = __toESM(require("@multiformats/base-x"));
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ const __logtape_logtape = require_chunk.__toESM(require("@logtape/logtape"));
3
+ const __opentelemetry_api = require_chunk.__toESM(require("@opentelemetry/api"));
4
+ const node_process = require_chunk.__toESM(require("node:process"));
5
+ const node_dns_promises = require_chunk.__toESM(require("node:dns/promises"));
6
+ const node_net = require_chunk.__toESM(require("node:net"));
7
+ const asn1js = require_chunk.__toESM(require("asn1js"));
8
+ const byte_encodings_base64 = require_chunk.__toESM(require("byte-encodings/base64"));
9
+ const byte_encodings_base64url = require_chunk.__toESM(require("byte-encodings/base64url"));
10
+ const node_crypto = require_chunk.__toESM(require("node:crypto"));
11
+ const pkijs = require_chunk.__toESM(require("pkijs"));
12
+ const __multiformats_base_x = require_chunk.__toESM(require("@multiformats/base-x"));
37
13
 
38
14
  //#region src/contexts.ts
39
15
  const preloadedContexts = {
@@ -4307,6 +4283,32 @@ const preloadedContexts = {
4307
4283
  "@id": "https://w3id.org/fep/5711#likedOf",
4308
4284
  "@type": "@id"
4309
4285
  }
4286
+ } },
4287
+ "http://joinmastodon.org/ns": { "@context": {
4288
+ "toot": "http://joinmastodon.org/ns#",
4289
+ "Emoji": "toot:Emoji",
4290
+ "featured": {
4291
+ "@id": "toot:featured",
4292
+ "@type": "@id"
4293
+ },
4294
+ "featuredTags": {
4295
+ "@id": "toot:featuredTags",
4296
+ "@type": "@id"
4297
+ },
4298
+ "focalPoint": {
4299
+ "@container": "@list",
4300
+ "@id": "toot:focalPoint"
4301
+ },
4302
+ "blurhash": "toot:blurhash",
4303
+ "discoverable": "toot:discoverable",
4304
+ "indexable": "toot:indexable",
4305
+ "memorial": "toot:memorial",
4306
+ "votersCount": "toot:votersCount",
4307
+ "suspended": "toot:suspended",
4308
+ "attributionDomains": {
4309
+ "@id": "toot:attributionDomains",
4310
+ "@type": "@id"
4311
+ }
4310
4312
  } }
4311
4313
  };
4312
4314
  var contexts_default = preloadedContexts;
@@ -4314,9 +4316,12 @@ var contexts_default = preloadedContexts;
4314
4316
  //#endregion
4315
4317
  //#region deno.json
4316
4318
  var name = "@fedify/vocab-runtime";
4317
- var version = "2.1.0-dev.543+e09fd1b4";
4319
+ var version = "2.1.0-dev.592+6c1f6e6f";
4318
4320
  var license = "MIT";
4319
- var exports$1 = { ".": "./src/mod.ts" };
4321
+ var exports$1 = {
4322
+ ".": "./src/mod.ts",
4323
+ "./jsonld": "./src/jsonld.ts"
4324
+ };
4320
4325
  var description = "Runtime library for @fedify/vocab";
4321
4326
  var author = {
4322
4327
  "name": "Hong Minhee",
@@ -4328,7 +4333,7 @@ var imports = {
4328
4333
  "asn1js": "npm:asn1js@^3.0.6",
4329
4334
  "byte-encodings": "npm:byte-encodings@^1.0.11",
4330
4335
  "fetch-mock": "npm:fetch-mock@^12.5.4",
4331
- "multicodec": "npm:multicodec@^3.2.1",
4336
+ "jsonld": "npm:jsonld@^9.0.0",
4332
4337
  "pkijs": "npm:pkijs@^3.2.5"
4333
4338
  };
4334
4339
  var exclude = ["dist", "node_modules"];
@@ -4843,6 +4848,46 @@ function getDocumentLoader({ allowPrivateAddress, skipPreloadedContexts, userAge
4843
4848
  return load;
4844
4849
  }
4845
4850
 
4851
+ //#endregion
4852
+ //#region src/internal/multicodec.ts
4853
+ const INVALID_MULTICODEC_PREFIX = "Invalid multicodec prefix.";
4854
+ function getMulticodecPrefix(data) {
4855
+ if (data.length < 1) throw new TypeError(INVALID_MULTICODEC_PREFIX);
4856
+ let code = 0;
4857
+ let shift = 0;
4858
+ for (let i = 0; i < data.length; i++) {
4859
+ const byte = data[i];
4860
+ code += (byte & 127) * 2 ** shift;
4861
+ if (code > Number.MAX_SAFE_INTEGER) throw new TypeError(INVALID_MULTICODEC_PREFIX);
4862
+ if ((byte & 128) === 0) return {
4863
+ code,
4864
+ prefixLength: i + 1
4865
+ };
4866
+ shift += 7;
4867
+ if (shift >= 53) throw new TypeError(INVALID_MULTICODEC_PREFIX);
4868
+ }
4869
+ throw new TypeError(INVALID_MULTICODEC_PREFIX);
4870
+ }
4871
+ function removeMulticodecPrefix(data) {
4872
+ const { prefixLength } = getMulticodecPrefix(data);
4873
+ return data.slice(prefixLength);
4874
+ }
4875
+ function addMulticodecPrefix(code, payload) {
4876
+ if (!Number.isSafeInteger(code) || code < 0) throw new TypeError("Invalid multicodec code.");
4877
+ const prefix = [];
4878
+ let value = code;
4879
+ do {
4880
+ let byte = value & 127;
4881
+ value = Math.floor(value / 128);
4882
+ if (value > 0) byte |= 128;
4883
+ prefix.push(byte);
4884
+ } while (value > 0);
4885
+ const prefixed = new Uint8Array(prefix.length + payload.length);
4886
+ prefixed.set(prefix);
4887
+ prefixed.set(payload, prefix.length);
4888
+ return prefixed;
4889
+ }
4890
+
4846
4891
  //#endregion
4847
4892
  //#region src/jwk.ts
4848
4893
  function validateCryptoKey(key, type) {
@@ -5259,8 +5304,8 @@ function importPem(pem) {
5259
5304
  */
5260
5305
  async function importMultibaseKey(key) {
5261
5306
  const decoded = decodeMultibase(key);
5262
- const code = (0, multicodec.getCodeFromData)(decoded);
5263
- const content = (0, multicodec.rmPrefix)(decoded);
5307
+ const { code } = getMulticodecPrefix(decoded);
5308
+ const content = removeMulticodecPrefix(decoded);
5264
5309
  if (code === 4613) {
5265
5310
  const keyObject = (0, node_crypto.createPublicKey)({
5266
5311
  key: content,
@@ -5309,9 +5354,7 @@ async function exportMultibaseKey(key) {
5309
5354
  content = sequence.toBER(false);
5310
5355
  code = 4613;
5311
5356
  } else throw new TypeError("Unsupported key type: " + JSON.stringify(key.algorithm));
5312
- const codeHex = code.toString(16);
5313
- const codeBytes = (0, byte_encodings_hex.decodeHex)(codeHex.length % 2 < 1 ? codeHex : "0" + codeHex);
5314
- const prefixed = (0, multicodec.addPrefix)(codeBytes, new Uint8Array(content));
5357
+ const prefixed = addMulticodecPrefix(code, new Uint8Array(content));
5315
5358
  const encoded = encodeMultibase("base58btc", prefixed);
5316
5359
  return new TextDecoder().decode(encoded);
5317
5360
  }
package/dist/mod.js CHANGED
@@ -6,8 +6,6 @@ import { isIP } from "node:net";
6
6
  import { Integer, Sequence } from "asn1js";
7
7
  import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
8
8
  import { decodeBase64Url } from "byte-encodings/base64url";
9
- import { decodeHex } from "byte-encodings/hex";
10
- import { addPrefix, getCodeFromData, rmPrefix } from "multicodec";
11
9
  import { createPublicKey } from "node:crypto";
12
10
  import { PublicKeyInfo } from "pkijs";
13
11
  import baseX from "@multiformats/base-x";
@@ -4284,6 +4282,32 @@ const preloadedContexts = {
4284
4282
  "@id": "https://w3id.org/fep/5711#likedOf",
4285
4283
  "@type": "@id"
4286
4284
  }
4285
+ } },
4286
+ "http://joinmastodon.org/ns": { "@context": {
4287
+ "toot": "http://joinmastodon.org/ns#",
4288
+ "Emoji": "toot:Emoji",
4289
+ "featured": {
4290
+ "@id": "toot:featured",
4291
+ "@type": "@id"
4292
+ },
4293
+ "featuredTags": {
4294
+ "@id": "toot:featuredTags",
4295
+ "@type": "@id"
4296
+ },
4297
+ "focalPoint": {
4298
+ "@container": "@list",
4299
+ "@id": "toot:focalPoint"
4300
+ },
4301
+ "blurhash": "toot:blurhash",
4302
+ "discoverable": "toot:discoverable",
4303
+ "indexable": "toot:indexable",
4304
+ "memorial": "toot:memorial",
4305
+ "votersCount": "toot:votersCount",
4306
+ "suspended": "toot:suspended",
4307
+ "attributionDomains": {
4308
+ "@id": "toot:attributionDomains",
4309
+ "@type": "@id"
4310
+ }
4287
4311
  } }
4288
4312
  };
4289
4313
  var contexts_default = preloadedContexts;
@@ -4291,9 +4315,12 @@ var contexts_default = preloadedContexts;
4291
4315
  //#endregion
4292
4316
  //#region deno.json
4293
4317
  var name = "@fedify/vocab-runtime";
4294
- var version = "2.1.0-dev.543+e09fd1b4";
4318
+ var version = "2.1.0-dev.592+6c1f6e6f";
4295
4319
  var license = "MIT";
4296
- var exports = { ".": "./src/mod.ts" };
4320
+ var exports = {
4321
+ ".": "./src/mod.ts",
4322
+ "./jsonld": "./src/jsonld.ts"
4323
+ };
4297
4324
  var description = "Runtime library for @fedify/vocab";
4298
4325
  var author = {
4299
4326
  "name": "Hong Minhee",
@@ -4305,7 +4332,7 @@ var imports = {
4305
4332
  "asn1js": "npm:asn1js@^3.0.6",
4306
4333
  "byte-encodings": "npm:byte-encodings@^1.0.11",
4307
4334
  "fetch-mock": "npm:fetch-mock@^12.5.4",
4308
- "multicodec": "npm:multicodec@^3.2.1",
4335
+ "jsonld": "npm:jsonld@^9.0.0",
4309
4336
  "pkijs": "npm:pkijs@^3.2.5"
4310
4337
  };
4311
4338
  var exclude = ["dist", "node_modules"];
@@ -4820,6 +4847,46 @@ function getDocumentLoader({ allowPrivateAddress, skipPreloadedContexts, userAge
4820
4847
  return load;
4821
4848
  }
4822
4849
 
4850
+ //#endregion
4851
+ //#region src/internal/multicodec.ts
4852
+ const INVALID_MULTICODEC_PREFIX = "Invalid multicodec prefix.";
4853
+ function getMulticodecPrefix(data) {
4854
+ if (data.length < 1) throw new TypeError(INVALID_MULTICODEC_PREFIX);
4855
+ let code = 0;
4856
+ let shift = 0;
4857
+ for (let i = 0; i < data.length; i++) {
4858
+ const byte = data[i];
4859
+ code += (byte & 127) * 2 ** shift;
4860
+ if (code > Number.MAX_SAFE_INTEGER) throw new TypeError(INVALID_MULTICODEC_PREFIX);
4861
+ if ((byte & 128) === 0) return {
4862
+ code,
4863
+ prefixLength: i + 1
4864
+ };
4865
+ shift += 7;
4866
+ if (shift >= 53) throw new TypeError(INVALID_MULTICODEC_PREFIX);
4867
+ }
4868
+ throw new TypeError(INVALID_MULTICODEC_PREFIX);
4869
+ }
4870
+ function removeMulticodecPrefix(data) {
4871
+ const { prefixLength } = getMulticodecPrefix(data);
4872
+ return data.slice(prefixLength);
4873
+ }
4874
+ function addMulticodecPrefix(code, payload) {
4875
+ if (!Number.isSafeInteger(code) || code < 0) throw new TypeError("Invalid multicodec code.");
4876
+ const prefix = [];
4877
+ let value = code;
4878
+ do {
4879
+ let byte = value & 127;
4880
+ value = Math.floor(value / 128);
4881
+ if (value > 0) byte |= 128;
4882
+ prefix.push(byte);
4883
+ } while (value > 0);
4884
+ const prefixed = new Uint8Array(prefix.length + payload.length);
4885
+ prefixed.set(prefix);
4886
+ prefixed.set(payload, prefix.length);
4887
+ return prefixed;
4888
+ }
4889
+
4823
4890
  //#endregion
4824
4891
  //#region src/jwk.ts
4825
4892
  function validateCryptoKey(key, type) {
@@ -5236,8 +5303,8 @@ function importPem(pem) {
5236
5303
  */
5237
5304
  async function importMultibaseKey(key) {
5238
5305
  const decoded = decodeMultibase(key);
5239
- const code = getCodeFromData(decoded);
5240
- const content = rmPrefix(decoded);
5306
+ const { code } = getMulticodecPrefix(decoded);
5307
+ const content = removeMulticodecPrefix(decoded);
5241
5308
  if (code === 4613) {
5242
5309
  const keyObject = createPublicKey({
5243
5310
  key: content,
@@ -5286,9 +5353,7 @@ async function exportMultibaseKey(key) {
5286
5353
  content = sequence.toBER(false);
5287
5354
  code = 4613;
5288
5355
  } else throw new TypeError("Unsupported key type: " + JSON.stringify(key.algorithm));
5289
- const codeHex = code.toString(16);
5290
- const codeBytes = decodeHex(codeHex.length % 2 < 1 ? codeHex : "0" + codeHex);
5291
- const prefixed = addPrefix(codeBytes, new Uint8Array(content));
5356
+ const prefixed = addMulticodecPrefix(code, new Uint8Array(content));
5292
5357
  const encoded = encodeMultibase("base58btc", prefixed);
5293
5358
  return new TextDecoder().decode(encoded);
5294
5359
  }
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require('./chunk-DWy1uDak.cjs');
2
- const require_request = require('./request-BJJB7u81.cjs');
2
+ const require_request = require('./request-CK7hgRUX.cjs');
3
3
  const require_link = require('./link-CdFPEo9O.cjs');
4
4
  const require_url = require('./url-C5Vs9nYh.cjs');
5
5
  const node_assert = require_chunk.__toESM(require("node:assert"));
@@ -5513,6 +5513,32 @@ const preloadedContexts = {
5513
5513
  "@id": "https://w3id.org/fep/5711#likedOf",
5514
5514
  "@type": "@id"
5515
5515
  }
5516
+ } },
5517
+ "http://joinmastodon.org/ns": { "@context": {
5518
+ "toot": "http://joinmastodon.org/ns#",
5519
+ "Emoji": "toot:Emoji",
5520
+ "featured": {
5521
+ "@id": "toot:featured",
5522
+ "@type": "@id"
5523
+ },
5524
+ "featuredTags": {
5525
+ "@id": "toot:featuredTags",
5526
+ "@type": "@id"
5527
+ },
5528
+ "focalPoint": {
5529
+ "@container": "@list",
5530
+ "@id": "toot:focalPoint"
5531
+ },
5532
+ "blurhash": "toot:blurhash",
5533
+ "discoverable": "toot:discoverable",
5534
+ "indexable": "toot:indexable",
5535
+ "memorial": "toot:memorial",
5536
+ "votersCount": "toot:votersCount",
5537
+ "suspended": "toot:suspended",
5538
+ "attributionDomains": {
5539
+ "@id": "toot:attributionDomains",
5540
+ "@type": "@id"
5541
+ }
5516
5542
  } }
5517
5543
  };
5518
5544
  var contexts_default = preloadedContexts;
@@ -1,4 +1,4 @@
1
- import { FetchError, createActivityPubRequest, deno_default, logRequest } from "./request-Divb6wDy.js";
1
+ import { FetchError, createActivityPubRequest, deno_default, logRequest } from "./request-DKDE-Rcx.js";
2
2
  import { HttpHeaderLink } from "./link-Ck2yj4dH.js";
3
3
  import { UrlError, validatePublicUrl } from "./url-fW_DHbih.js";
4
4
  import "node:module";
@@ -5539,6 +5539,32 @@ const preloadedContexts = {
5539
5539
  "@id": "https://w3id.org/fep/5711#likedOf",
5540
5540
  "@type": "@id"
5541
5541
  }
5542
+ } },
5543
+ "http://joinmastodon.org/ns": { "@context": {
5544
+ "toot": "http://joinmastodon.org/ns#",
5545
+ "Emoji": "toot:Emoji",
5546
+ "featured": {
5547
+ "@id": "toot:featured",
5548
+ "@type": "@id"
5549
+ },
5550
+ "featuredTags": {
5551
+ "@id": "toot:featuredTags",
5552
+ "@type": "@id"
5553
+ },
5554
+ "focalPoint": {
5555
+ "@container": "@list",
5556
+ "@id": "toot:focalPoint"
5557
+ },
5558
+ "blurhash": "toot:blurhash",
5559
+ "discoverable": "toot:discoverable",
5560
+ "indexable": "toot:indexable",
5561
+ "memorial": "toot:memorial",
5562
+ "votersCount": "toot:votersCount",
5563
+ "suspended": "toot:suspended",
5564
+ "attributionDomains": {
5565
+ "@id": "toot:attributionDomains",
5566
+ "@type": "@id"
5567
+ }
5542
5568
  } }
5543
5569
  };
5544
5570
  var contexts_default = preloadedContexts;
@@ -0,0 +1,77 @@
1
+ const require_chunk = require('../chunk-DWy1uDak.cjs');
2
+ const require_multicodec = require('../multicodec-mHcRzSGY.cjs');
3
+ const node_assert = require_chunk.__toESM(require("node:assert"));
4
+ const node_test = require_chunk.__toESM(require("node:test"));
5
+
6
+ //#region src/internal/multicodec.test.ts
7
+ (0, node_test.test)("getMulticodecPrefix() decodes supported multicodec prefixes", () => {
8
+ (0, node_assert.deepStrictEqual)(require_multicodec.getMulticodecPrefix(Uint8Array.from([
9
+ 237,
10
+ 1,
11
+ 170
12
+ ])), {
13
+ code: 237,
14
+ prefixLength: 2
15
+ });
16
+ (0, node_assert.deepStrictEqual)(require_multicodec.getMulticodecPrefix(Uint8Array.from([
17
+ 133,
18
+ 36,
19
+ 170
20
+ ])), {
21
+ code: 4613,
22
+ prefixLength: 2
23
+ });
24
+ });
25
+ (0, node_test.test)("removeMulticodecPrefix() strips the varint prefix", () => {
26
+ (0, node_assert.deepStrictEqual)(require_multicodec.removeMulticodecPrefix(Uint8Array.from([
27
+ 237,
28
+ 1,
29
+ 17,
30
+ 34
31
+ ])), Uint8Array.from([17, 34]));
32
+ });
33
+ (0, node_test.test)("addMulticodecPrefix() prepends the varint-encoded code", () => {
34
+ (0, node_assert.deepStrictEqual)(require_multicodec.addMulticodecPrefix(237, Uint8Array.from([17, 34])), Uint8Array.from([
35
+ 237,
36
+ 1,
37
+ 17,
38
+ 34
39
+ ]));
40
+ (0, node_assert.deepStrictEqual)(require_multicodec.addMulticodecPrefix(4613, Uint8Array.from([17, 34])), Uint8Array.from([
41
+ 133,
42
+ 36,
43
+ 17,
44
+ 34
45
+ ]));
46
+ });
47
+ (0, node_test.test)("multicodec helpers round-trip prefixed payloads", () => {
48
+ const payload = Uint8Array.from([
49
+ 222,
50
+ 173,
51
+ 190,
52
+ 239
53
+ ]);
54
+ const prefixed = require_multicodec.addMulticodecPrefix(4613, payload);
55
+ (0, node_assert.deepStrictEqual)(require_multicodec.getMulticodecPrefix(prefixed), {
56
+ code: 4613,
57
+ prefixLength: 2
58
+ });
59
+ (0, node_assert.deepStrictEqual)(require_multicodec.removeMulticodecPrefix(prefixed), payload);
60
+ });
61
+ (0, node_test.test)("multicodec helpers reject malformed prefixes", () => {
62
+ (0, node_assert.throws)(() => require_multicodec.getMulticodecPrefix(new Uint8Array([])), /* @__PURE__ */ new TypeError("Invalid multicodec prefix."));
63
+ (0, node_assert.throws)(() => require_multicodec.getMulticodecPrefix(Uint8Array.from([128])), /* @__PURE__ */ new TypeError("Invalid multicodec prefix."));
64
+ (0, node_assert.throws)(() => require_multicodec.getMulticodecPrefix(Uint8Array.from([
65
+ 128,
66
+ 128,
67
+ 128,
68
+ 128,
69
+ 128,
70
+ 128,
71
+ 128,
72
+ 128
73
+ ])), /* @__PURE__ */ new TypeError("Invalid multicodec prefix."));
74
+ (0, node_assert.throws)(() => require_multicodec.addMulticodecPrefix(-1, Uint8Array.from([0])), /* @__PURE__ */ new TypeError("Invalid multicodec code."));
75
+ });
76
+
77
+ //#endregion
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,76 @@
1
+ import { addMulticodecPrefix, getMulticodecPrefix, removeMulticodecPrefix } from "../multicodec-DvC5xnX2.js";
2
+ import { deepStrictEqual, throws } from "node:assert";
3
+ import { test } from "node:test";
4
+
5
+ //#region src/internal/multicodec.test.ts
6
+ test("getMulticodecPrefix() decodes supported multicodec prefixes", () => {
7
+ deepStrictEqual(getMulticodecPrefix(Uint8Array.from([
8
+ 237,
9
+ 1,
10
+ 170
11
+ ])), {
12
+ code: 237,
13
+ prefixLength: 2
14
+ });
15
+ deepStrictEqual(getMulticodecPrefix(Uint8Array.from([
16
+ 133,
17
+ 36,
18
+ 170
19
+ ])), {
20
+ code: 4613,
21
+ prefixLength: 2
22
+ });
23
+ });
24
+ test("removeMulticodecPrefix() strips the varint prefix", () => {
25
+ deepStrictEqual(removeMulticodecPrefix(Uint8Array.from([
26
+ 237,
27
+ 1,
28
+ 17,
29
+ 34
30
+ ])), Uint8Array.from([17, 34]));
31
+ });
32
+ test("addMulticodecPrefix() prepends the varint-encoded code", () => {
33
+ deepStrictEqual(addMulticodecPrefix(237, Uint8Array.from([17, 34])), Uint8Array.from([
34
+ 237,
35
+ 1,
36
+ 17,
37
+ 34
38
+ ]));
39
+ deepStrictEqual(addMulticodecPrefix(4613, Uint8Array.from([17, 34])), Uint8Array.from([
40
+ 133,
41
+ 36,
42
+ 17,
43
+ 34
44
+ ]));
45
+ });
46
+ test("multicodec helpers round-trip prefixed payloads", () => {
47
+ const payload = Uint8Array.from([
48
+ 222,
49
+ 173,
50
+ 190,
51
+ 239
52
+ ]);
53
+ const prefixed = addMulticodecPrefix(4613, payload);
54
+ deepStrictEqual(getMulticodecPrefix(prefixed), {
55
+ code: 4613,
56
+ prefixLength: 2
57
+ });
58
+ deepStrictEqual(removeMulticodecPrefix(prefixed), payload);
59
+ });
60
+ test("multicodec helpers reject malformed prefixes", () => {
61
+ throws(() => getMulticodecPrefix(new Uint8Array([])), /* @__PURE__ */ new TypeError("Invalid multicodec prefix."));
62
+ throws(() => getMulticodecPrefix(Uint8Array.from([128])), /* @__PURE__ */ new TypeError("Invalid multicodec prefix."));
63
+ throws(() => getMulticodecPrefix(Uint8Array.from([
64
+ 128,
65
+ 128,
66
+ 128,
67
+ 128,
68
+ 128,
69
+ 128,
70
+ 128,
71
+ 128
72
+ ])), /* @__PURE__ */ new TypeError("Invalid multicodec prefix."));
73
+ throws(() => addMulticodecPrefix(-1, Uint8Array.from([0])), /* @__PURE__ */ new TypeError("Invalid multicodec code."));
74
+ });
75
+
76
+ //#endregion
@@ -1,12 +1,11 @@
1
1
  const require_chunk = require('./chunk-DWy1uDak.cjs');
2
- const require_multibase = require('./multibase-BFbBiaPE.cjs');
2
+ const require_multicodec = require('./multicodec-mHcRzSGY.cjs');
3
+ const require_multibase = require('./multibase-B2D6B0V4.cjs');
3
4
  const node_assert = require_chunk.__toESM(require("node:assert"));
4
5
  const node_test = require_chunk.__toESM(require("node:test"));
5
6
  const asn1js = require_chunk.__toESM(require("asn1js"));
6
7
  const byte_encodings_base64 = require_chunk.__toESM(require("byte-encodings/base64"));
7
8
  const byte_encodings_base64url = require_chunk.__toESM(require("byte-encodings/base64url"));
8
- const byte_encodings_hex = require_chunk.__toESM(require("byte-encodings/hex"));
9
- const multicodec = require_chunk.__toESM(require("multicodec"));
10
9
  const node_crypto = require_chunk.__toESM(require("node:crypto"));
11
10
  const pkijs = require_chunk.__toESM(require("pkijs"));
12
11
 
@@ -128,8 +127,8 @@ function importPem(pem) {
128
127
  */
129
128
  async function importMultibaseKey(key) {
130
129
  const decoded = require_multibase.decodeMultibase(key);
131
- const code = (0, multicodec.getCodeFromData)(decoded);
132
- const content = (0, multicodec.rmPrefix)(decoded);
130
+ const { code } = require_multicodec.getMulticodecPrefix(decoded);
131
+ const content = require_multicodec.removeMulticodecPrefix(decoded);
133
132
  if (code === 4613) {
134
133
  const keyObject = (0, node_crypto.createPublicKey)({
135
134
  key: content,
@@ -178,9 +177,7 @@ async function exportMultibaseKey(key) {
178
177
  content = sequence.toBER(false);
179
178
  code = 4613;
180
179
  } else throw new TypeError("Unsupported key type: " + JSON.stringify(key.algorithm));
181
- const codeHex = code.toString(16);
182
- const codeBytes = (0, byte_encodings_hex.decodeHex)(codeHex.length % 2 < 1 ? codeHex : "0" + codeHex);
183
- const prefixed = (0, multicodec.addPrefix)(codeBytes, new Uint8Array(content));
180
+ const prefixed = require_multicodec.addMulticodecPrefix(code, new Uint8Array(content));
184
181
  const encoded = require_multibase.encodeMultibase("base58btc", prefixed);
185
182
  return new TextDecoder().decode(encoded);
186
183
  }
@@ -240,6 +237,11 @@ const ed25519Multibase = "z6MksHj1MJnidCtDiyYW9ugNFftoX9fLK4bornTxmMZ6X7vq";
240
237
  const ed25519Key = await importMultibaseKey(ed25519Multibase);
241
238
  (0, node_assert.deepStrictEqual)(await exportJwk(ed25519Key), ed25519Jwk);
242
239
  });
240
+ (0, node_test.test)("importMultibase() rejects malformed multicodec prefixes", async () => {
241
+ const decoder = new TextDecoder();
242
+ await (0, node_assert.rejects)(() => importMultibaseKey(decoder.decode(require_multibase.encodeMultibase("base58btc", new Uint8Array([])))), /* @__PURE__ */ new TypeError("Invalid multicodec prefix."));
243
+ await (0, node_assert.rejects)(() => importMultibaseKey(decoder.decode(require_multibase.encodeMultibase("base58btc", Uint8Array.from([128])))), /* @__PURE__ */ new TypeError("Invalid multicodec prefix."));
244
+ });
243
245
  (0, node_test.test)("exportMultibaseKey()", async () => {
244
246
  const rsaKey = await importJwk(rsaJwk, "public");
245
247
  const rsaMb = await exportMultibaseKey(rsaKey);
@@ -1,11 +1,10 @@
1
- import { decodeMultibase, encodeMultibase } from "./multibase-DStmqni9.js";
2
- import { deepStrictEqual } from "node:assert";
1
+ import { addMulticodecPrefix, getMulticodecPrefix, removeMulticodecPrefix } from "./multicodec-DvC5xnX2.js";
2
+ import { decodeMultibase, encodeMultibase } from "./multibase-BdHCGO4H.js";
3
+ import { deepStrictEqual, rejects } from "node:assert";
3
4
  import { test } from "node:test";
4
5
  import { Integer, Sequence } from "asn1js";
5
6
  import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
6
7
  import { decodeBase64Url } from "byte-encodings/base64url";
7
- import { decodeHex } from "byte-encodings/hex";
8
- import { addPrefix, getCodeFromData, rmPrefix } from "multicodec";
9
8
  import { createPublicKey } from "node:crypto";
10
9
  import { PublicKeyInfo } from "pkijs";
11
10
 
@@ -127,8 +126,8 @@ function importPem(pem) {
127
126
  */
128
127
  async function importMultibaseKey(key) {
129
128
  const decoded = decodeMultibase(key);
130
- const code = getCodeFromData(decoded);
131
- const content = rmPrefix(decoded);
129
+ const { code } = getMulticodecPrefix(decoded);
130
+ const content = removeMulticodecPrefix(decoded);
132
131
  if (code === 4613) {
133
132
  const keyObject = createPublicKey({
134
133
  key: content,
@@ -177,9 +176,7 @@ async function exportMultibaseKey(key) {
177
176
  content = sequence.toBER(false);
178
177
  code = 4613;
179
178
  } else throw new TypeError("Unsupported key type: " + JSON.stringify(key.algorithm));
180
- const codeHex = code.toString(16);
181
- const codeBytes = decodeHex(codeHex.length % 2 < 1 ? codeHex : "0" + codeHex);
182
- const prefixed = addPrefix(codeBytes, new Uint8Array(content));
179
+ const prefixed = addMulticodecPrefix(code, new Uint8Array(content));
183
180
  const encoded = encodeMultibase("base58btc", prefixed);
184
181
  return new TextDecoder().decode(encoded);
185
182
  }
@@ -239,6 +236,11 @@ test("importMultibase()", async () => {
239
236
  const ed25519Key = await importMultibaseKey(ed25519Multibase);
240
237
  deepStrictEqual(await exportJwk(ed25519Key), ed25519Jwk);
241
238
  });
239
+ test("importMultibase() rejects malformed multicodec prefixes", async () => {
240
+ const decoder = new TextDecoder();
241
+ await rejects(() => importMultibaseKey(decoder.decode(encodeMultibase("base58btc", new Uint8Array([])))), /* @__PURE__ */ new TypeError("Invalid multicodec prefix."));
242
+ await rejects(() => importMultibaseKey(decoder.decode(encodeMultibase("base58btc", Uint8Array.from([128])))), /* @__PURE__ */ new TypeError("Invalid multicodec prefix."));
243
+ });
242
244
  test("exportMultibaseKey()", async () => {
243
245
  const rsaKey = await importJwk(rsaJwk, "public");
244
246
  const rsaMb = await exportMultibaseKey(rsaKey);
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require('../chunk-DWy1uDak.cjs');
2
- const require_multibase = require('../multibase-BFbBiaPE.cjs');
2
+ const require_multibase = require('../multibase-B2D6B0V4.cjs');
3
3
  const node_assert = require_chunk.__toESM(require("node:assert"));
4
4
  const node_test = require_chunk.__toESM(require("node:test"));
5
5
 
@@ -1,4 +1,4 @@
1
- import { codes, decodeMultibase, decodeText, encodeMultibase, encodeText, names } from "../multibase-DStmqni9.js";
1
+ import { codes, decodeMultibase, decodeText, encodeMultibase, encodeText, names } from "../multibase-BdHCGO4H.js";
2
2
  import { deepStrictEqual } from "node:assert";
3
3
  import { test } from "node:test";
4
4
 
@@ -0,0 +1,41 @@
1
+ //#region src/internal/multicodec.ts
2
+ const INVALID_MULTICODEC_PREFIX = "Invalid multicodec prefix.";
3
+ function getMulticodecPrefix(data) {
4
+ if (data.length < 1) throw new TypeError(INVALID_MULTICODEC_PREFIX);
5
+ let code = 0;
6
+ let shift = 0;
7
+ for (let i = 0; i < data.length; i++) {
8
+ const byte = data[i];
9
+ code += (byte & 127) * 2 ** shift;
10
+ if (code > Number.MAX_SAFE_INTEGER) throw new TypeError(INVALID_MULTICODEC_PREFIX);
11
+ if ((byte & 128) === 0) return {
12
+ code,
13
+ prefixLength: i + 1
14
+ };
15
+ shift += 7;
16
+ if (shift >= 53) throw new TypeError(INVALID_MULTICODEC_PREFIX);
17
+ }
18
+ throw new TypeError(INVALID_MULTICODEC_PREFIX);
19
+ }
20
+ function removeMulticodecPrefix(data) {
21
+ const { prefixLength } = getMulticodecPrefix(data);
22
+ return data.slice(prefixLength);
23
+ }
24
+ function addMulticodecPrefix(code, payload) {
25
+ if (!Number.isSafeInteger(code) || code < 0) throw new TypeError("Invalid multicodec code.");
26
+ const prefix = [];
27
+ let value = code;
28
+ do {
29
+ let byte = value & 127;
30
+ value = Math.floor(value / 128);
31
+ if (value > 0) byte |= 128;
32
+ prefix.push(byte);
33
+ } while (value > 0);
34
+ const prefixed = new Uint8Array(prefix.length + payload.length);
35
+ prefixed.set(prefix);
36
+ prefixed.set(payload, prefix.length);
37
+ return prefixed;
38
+ }
39
+
40
+ //#endregion
41
+ export { addMulticodecPrefix, getMulticodecPrefix, removeMulticodecPrefix };
@@ -0,0 +1,59 @@
1
+
2
+ //#region src/internal/multicodec.ts
3
+ const INVALID_MULTICODEC_PREFIX = "Invalid multicodec prefix.";
4
+ function getMulticodecPrefix(data) {
5
+ if (data.length < 1) throw new TypeError(INVALID_MULTICODEC_PREFIX);
6
+ let code = 0;
7
+ let shift = 0;
8
+ for (let i = 0; i < data.length; i++) {
9
+ const byte = data[i];
10
+ code += (byte & 127) * 2 ** shift;
11
+ if (code > Number.MAX_SAFE_INTEGER) throw new TypeError(INVALID_MULTICODEC_PREFIX);
12
+ if ((byte & 128) === 0) return {
13
+ code,
14
+ prefixLength: i + 1
15
+ };
16
+ shift += 7;
17
+ if (shift >= 53) throw new TypeError(INVALID_MULTICODEC_PREFIX);
18
+ }
19
+ throw new TypeError(INVALID_MULTICODEC_PREFIX);
20
+ }
21
+ function removeMulticodecPrefix(data) {
22
+ const { prefixLength } = getMulticodecPrefix(data);
23
+ return data.slice(prefixLength);
24
+ }
25
+ function addMulticodecPrefix(code, payload) {
26
+ if (!Number.isSafeInteger(code) || code < 0) throw new TypeError("Invalid multicodec code.");
27
+ const prefix = [];
28
+ let value = code;
29
+ do {
30
+ let byte = value & 127;
31
+ value = Math.floor(value / 128);
32
+ if (value > 0) byte |= 128;
33
+ prefix.push(byte);
34
+ } while (value > 0);
35
+ const prefixed = new Uint8Array(prefix.length + payload.length);
36
+ prefixed.set(prefix);
37
+ prefixed.set(payload, prefix.length);
38
+ return prefixed;
39
+ }
40
+
41
+ //#endregion
42
+ Object.defineProperty(exports, 'addMulticodecPrefix', {
43
+ enumerable: true,
44
+ get: function () {
45
+ return addMulticodecPrefix;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, 'getMulticodecPrefix', {
49
+ enumerable: true,
50
+ get: function () {
51
+ return getMulticodecPrefix;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, 'removeMulticodecPrefix', {
55
+ enumerable: true,
56
+ get: function () {
57
+ return removeMulticodecPrefix;
58
+ }
59
+ });
@@ -3,9 +3,12 @@ const node_process = require_chunk.__toESM(require("node:process"));
3
3
 
4
4
  //#region deno.json
5
5
  var name = "@fedify/vocab-runtime";
6
- var version = "2.1.0-dev.543+e09fd1b4";
6
+ var version = "2.1.0-dev.592+6c1f6e6f";
7
7
  var license = "MIT";
8
- var exports$1 = { ".": "./src/mod.ts" };
8
+ var exports$1 = {
9
+ ".": "./src/mod.ts",
10
+ "./jsonld": "./src/jsonld.ts"
11
+ };
9
12
  var description = "Runtime library for @fedify/vocab";
10
13
  var author = {
11
14
  "name": "Hong Minhee",
@@ -17,7 +20,7 @@ var imports = {
17
20
  "asn1js": "npm:asn1js@^3.0.6",
18
21
  "byte-encodings": "npm:byte-encodings@^1.0.11",
19
22
  "fetch-mock": "npm:fetch-mock@^12.5.4",
20
- "multicodec": "npm:multicodec@^3.2.1",
23
+ "jsonld": "npm:jsonld@^9.0.0",
21
24
  "pkijs": "npm:pkijs@^3.2.5"
22
25
  };
23
26
  var exclude = ["dist", "node_modules"];
@@ -2,9 +2,12 @@ import process from "node:process";
2
2
 
3
3
  //#region deno.json
4
4
  var name = "@fedify/vocab-runtime";
5
- var version = "2.1.0-dev.543+e09fd1b4";
5
+ var version = "2.1.0-dev.592+6c1f6e6f";
6
6
  var license = "MIT";
7
- var exports = { ".": "./src/mod.ts" };
7
+ var exports = {
8
+ ".": "./src/mod.ts",
9
+ "./jsonld": "./src/jsonld.ts"
10
+ };
8
11
  var description = "Runtime library for @fedify/vocab";
9
12
  var author = {
10
13
  "name": "Hong Minhee",
@@ -16,7 +19,7 @@ var imports = {
16
19
  "asn1js": "npm:asn1js@^3.0.6",
17
20
  "byte-encodings": "npm:byte-encodings@^1.0.11",
18
21
  "fetch-mock": "npm:fetch-mock@^12.5.4",
19
- "multicodec": "npm:multicodec@^3.2.1",
22
+ "jsonld": "npm:jsonld@^9.0.0",
20
23
  "pkijs": "npm:pkijs@^3.2.5"
21
24
  };
22
25
  var exclude = ["dist", "node_modules"];
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require('./chunk-DWy1uDak.cjs');
2
- const require_request = require('./request-BJJB7u81.cjs');
2
+ const require_request = require('./request-CK7hgRUX.cjs');
3
3
  const node_assert = require_chunk.__toESM(require("node:assert"));
4
4
  const node_test = require_chunk.__toESM(require("node:test"));
5
5
  const node_process = require_chunk.__toESM(require("node:process"));
@@ -1,4 +1,4 @@
1
- import { deno_default, getUserAgent } from "./request-Divb6wDy.js";
1
+ import { deno_default, getUserAgent } from "./request-DKDE-Rcx.js";
2
2
  import { deepStrictEqual } from "node:assert";
3
3
  import { test } from "node:test";
4
4
  import process from "node:process";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/vocab-runtime",
3
- "version": "2.1.0-dev.543+e09fd1b4",
3
+ "version": "2.1.0-dev.592+6c1f6e6f",
4
4
  "homepage": "https://fedify.dev/",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,6 +35,16 @@
35
35
  "require": "./dist/mod.cjs",
36
36
  "default": "./dist/mod.js"
37
37
  },
38
+ "./jsonld": {
39
+ "types": {
40
+ "import": "./dist/jsonld.d.ts",
41
+ "require": "./dist/jsonld.d.cts",
42
+ "default": "./dist/jsonld.d.ts"
43
+ },
44
+ "import": "./dist/jsonld.js",
45
+ "require": "./dist/jsonld.cjs",
46
+ "default": "./dist/jsonld.js"
47
+ },
38
48
  "./package.json": "./package.json"
39
49
  },
40
50
  "keywords": [
@@ -60,7 +70,7 @@
60
70
  "@opentelemetry/api": "^1.9.0",
61
71
  "asn1js": "^3.0.6",
62
72
  "byte-encodings": "^1.0.11",
63
- "multicodec": "^3.2.1",
73
+ "jsonld": "^9.0.0",
64
74
  "pkijs": "^3.3.3"
65
75
  },
66
76
  "scripts": {
package/src/contexts.ts CHANGED
@@ -4367,6 +4367,44 @@ const preloadedContexts: Record<string, unknown> = {
4367
4367
  },
4368
4368
  },
4369
4369
  },
4370
+
4371
+ // Mastodon's "toot:" namespace. The URL http://joinmastodon.org/ns has
4372
+ // *never* served a real JSON-LD context document—Mastodon has always inlined
4373
+ // these term definitions directly in every outgoing @context array. However,
4374
+ // some ActivityPub implementations (e.g., Bonfire) put the bare URL in their
4375
+ // @context, which causes JSON-LD processors to try to dereference it and fail
4376
+ // with a 404. We ship a built-in copy here so that Fedify can parse such
4377
+ // documents without a network round-trip to a URL that will never resolve.
4378
+ // See: https://github.com/mastodon/joinmastodon/issues/148
4379
+ // https://github.com/fedify-dev/fedify/issues/630
4380
+ "http://joinmastodon.org/ns": {
4381
+ "@context": {
4382
+ "toot": "http://joinmastodon.org/ns#",
4383
+ "Emoji": "toot:Emoji",
4384
+ "featured": {
4385
+ "@id": "toot:featured",
4386
+ "@type": "@id",
4387
+ },
4388
+ "featuredTags": {
4389
+ "@id": "toot:featuredTags",
4390
+ "@type": "@id",
4391
+ },
4392
+ "focalPoint": {
4393
+ "@container": "@list",
4394
+ "@id": "toot:focalPoint",
4395
+ },
4396
+ "blurhash": "toot:blurhash",
4397
+ "discoverable": "toot:discoverable",
4398
+ "indexable": "toot:indexable",
4399
+ "memorial": "toot:memorial",
4400
+ "votersCount": "toot:votersCount",
4401
+ "suspended": "toot:suspended",
4402
+ "attributionDomains": {
4403
+ "@id": "toot:attributionDomains",
4404
+ "@type": "@id",
4405
+ },
4406
+ },
4407
+ },
4370
4408
  };
4371
4409
 
4372
4410
  export default preloadedContexts;
@@ -0,0 +1,68 @@
1
+ import { deepStrictEqual, throws } from "node:assert";
2
+ import { test } from "node:test";
3
+ import {
4
+ addMulticodecPrefix,
5
+ getMulticodecPrefix,
6
+ removeMulticodecPrefix,
7
+ } from "./multicodec.ts";
8
+
9
+ test("getMulticodecPrefix() decodes supported multicodec prefixes", () => {
10
+ deepStrictEqual(
11
+ getMulticodecPrefix(Uint8Array.from([0xed, 0x01, 0xaa])),
12
+ { code: 0xed, prefixLength: 2 },
13
+ );
14
+ deepStrictEqual(
15
+ getMulticodecPrefix(Uint8Array.from([0x85, 0x24, 0xaa])),
16
+ { code: 0x1205, prefixLength: 2 },
17
+ );
18
+ });
19
+
20
+ test("removeMulticodecPrefix() strips the varint prefix", () => {
21
+ deepStrictEqual(
22
+ removeMulticodecPrefix(Uint8Array.from([0xed, 0x01, 0x11, 0x22])),
23
+ Uint8Array.from([0x11, 0x22]),
24
+ );
25
+ });
26
+
27
+ test("addMulticodecPrefix() prepends the varint-encoded code", () => {
28
+ deepStrictEqual(
29
+ addMulticodecPrefix(0xed, Uint8Array.from([0x11, 0x22])),
30
+ Uint8Array.from([0xed, 0x01, 0x11, 0x22]),
31
+ );
32
+ deepStrictEqual(
33
+ addMulticodecPrefix(0x1205, Uint8Array.from([0x11, 0x22])),
34
+ Uint8Array.from([0x85, 0x24, 0x11, 0x22]),
35
+ );
36
+ });
37
+
38
+ test("multicodec helpers round-trip prefixed payloads", () => {
39
+ const payload = Uint8Array.from([0xde, 0xad, 0xbe, 0xef]);
40
+ const prefixed = addMulticodecPrefix(0x1205, payload);
41
+ deepStrictEqual(getMulticodecPrefix(prefixed), {
42
+ code: 0x1205,
43
+ prefixLength: 2,
44
+ });
45
+ deepStrictEqual(removeMulticodecPrefix(prefixed), payload);
46
+ });
47
+
48
+ test("multicodec helpers reject malformed prefixes", () => {
49
+ throws(
50
+ () => getMulticodecPrefix(new Uint8Array([])),
51
+ new TypeError("Invalid multicodec prefix."),
52
+ );
53
+ throws(
54
+ () => getMulticodecPrefix(Uint8Array.from([0x80])),
55
+ new TypeError("Invalid multicodec prefix."),
56
+ );
57
+ throws(
58
+ () =>
59
+ getMulticodecPrefix(
60
+ Uint8Array.from([0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80]),
61
+ ),
62
+ new TypeError("Invalid multicodec prefix."),
63
+ );
64
+ throws(
65
+ () => addMulticodecPrefix(-1, Uint8Array.from([0x00])),
66
+ new TypeError("Invalid multicodec code."),
67
+ );
68
+ });
@@ -0,0 +1,53 @@
1
+ const INVALID_MULTICODEC_PREFIX = "Invalid multicodec prefix.";
2
+
3
+ export interface MulticodecPrefix {
4
+ code: number;
5
+ prefixLength: number;
6
+ }
7
+
8
+ export function getMulticodecPrefix(
9
+ data: Uint8Array,
10
+ ): MulticodecPrefix {
11
+ if (data.length < 1) throw new TypeError(INVALID_MULTICODEC_PREFIX);
12
+ let code = 0;
13
+ let shift = 0;
14
+ for (let i = 0; i < data.length; i++) {
15
+ const byte = data[i];
16
+ code += (byte & 0x7f) * 2 ** shift;
17
+ if (code > Number.MAX_SAFE_INTEGER) {
18
+ throw new TypeError(INVALID_MULTICODEC_PREFIX);
19
+ }
20
+ if ((byte & 0x80) === 0) {
21
+ return { code, prefixLength: i + 1 };
22
+ }
23
+ shift += 7;
24
+ if (shift >= 53) throw new TypeError(INVALID_MULTICODEC_PREFIX);
25
+ }
26
+ throw new TypeError(INVALID_MULTICODEC_PREFIX);
27
+ }
28
+
29
+ export function removeMulticodecPrefix(data: Uint8Array): Uint8Array {
30
+ const { prefixLength } = getMulticodecPrefix(data);
31
+ return data.slice(prefixLength);
32
+ }
33
+
34
+ export function addMulticodecPrefix(
35
+ code: number,
36
+ payload: Uint8Array,
37
+ ): Uint8Array {
38
+ if (!Number.isSafeInteger(code) || code < 0) {
39
+ throw new TypeError("Invalid multicodec code.");
40
+ }
41
+ const prefix: number[] = [];
42
+ let value = code;
43
+ do {
44
+ let byte = value & 0x7f;
45
+ value = Math.floor(value / 0x80);
46
+ if (value > 0) byte |= 0x80;
47
+ prefix.push(byte);
48
+ } while (value > 0);
49
+ const prefixed = new Uint8Array(prefix.length + payload.length);
50
+ prefixed.set(prefix);
51
+ prefixed.set(payload, prefix.length);
52
+ return prefixed;
53
+ }
package/src/jsonld.ts ADDED
@@ -0,0 +1,4 @@
1
+ // @ts-ignore TS7016
2
+ import jsonld from "jsonld/dist/jsonld.esm.js";
3
+
4
+ export default jsonld as typeof import("jsonld");
package/src/key.test.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { deepStrictEqual } from "node:assert";
1
+ import { deepStrictEqual, rejects } from "node:assert";
2
2
  import { test } from "node:test";
3
3
  import { exportJwk, importJwk } from "./jwk.ts";
4
4
  import {
@@ -9,6 +9,7 @@ import {
9
9
  importPkcs1,
10
10
  importSpki,
11
11
  } from "./key.ts";
12
+ import { encodeMultibase } from "./multibase/mod.ts";
12
13
 
13
14
  // cSpell: disable
14
15
  const rsaSpki = "-----BEGIN PUBLIC KEY-----\n" +
@@ -122,6 +123,26 @@ test("importMultibase()", async () => {
122
123
  deepStrictEqual(await exportJwk(ed25519Key), ed25519Jwk);
123
124
  });
124
125
 
126
+ test("importMultibase() rejects malformed multicodec prefixes", async () => {
127
+ const decoder = new TextDecoder();
128
+ await rejects(
129
+ () =>
130
+ importMultibaseKey(
131
+ decoder.decode(encodeMultibase("base58btc", new Uint8Array([]))),
132
+ ),
133
+ new TypeError("Invalid multicodec prefix."),
134
+ );
135
+ await rejects(
136
+ () =>
137
+ importMultibaseKey(
138
+ decoder.decode(
139
+ encodeMultibase("base58btc", Uint8Array.from([0x80])),
140
+ ),
141
+ ),
142
+ new TypeError("Invalid multicodec prefix."),
143
+ );
144
+ });
145
+
125
146
  test("exportMultibaseKey()", async () => {
126
147
  const rsaKey = await importJwk(rsaJwk, "public");
127
148
  const rsaMb = await exportMultibaseKey(rsaKey);
package/src/key.ts CHANGED
@@ -1,10 +1,13 @@
1
1
  import { Integer, Sequence } from "asn1js";
2
2
  import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
3
3
  import { decodeBase64Url } from "byte-encodings/base64url";
4
- import { decodeHex } from "byte-encodings/hex";
5
- import { addPrefix, getCodeFromData, rmPrefix } from "multicodec";
6
4
  import { createPublicKey } from "node:crypto";
7
5
  import { PublicKeyInfo } from "pkijs";
6
+ import {
7
+ addMulticodecPrefix,
8
+ getMulticodecPrefix,
9
+ removeMulticodecPrefix,
10
+ } from "./internal/multicodec.ts";
8
11
  import { validateCryptoKey } from "./jwk.ts";
9
12
  import { decodeMultibase, encodeMultibase } from "./multibase/mod.ts";
10
13
 
@@ -101,8 +104,8 @@ export function importPem(pem: string): Promise<CryptoKey> {
101
104
  */
102
105
  export async function importMultibaseKey(key: string): Promise<CryptoKey> {
103
106
  const decoded = decodeMultibase(key);
104
- const code: number = getCodeFromData(decoded);
105
- const content = rmPrefix(decoded);
107
+ const { code } = getMulticodecPrefix(decoded);
108
+ const content = removeMulticodecPrefix(decoded);
106
109
  if (code === 0x1205) { // rsa-pub
107
110
  const keyObject = createPublicKey({
108
111
  // deno-lint-ignore no-explicit-any
@@ -177,11 +180,9 @@ export async function exportMultibaseKey(key: CryptoKey): Promise<string> {
177
180
  "Unsupported key type: " + JSON.stringify(key.algorithm),
178
181
  );
179
182
  }
180
- const codeHex = code.toString(16);
181
- const codeBytes = decodeHex(codeHex.length % 2 < 1 ? codeHex : "0" + codeHex);
182
- const prefixed = addPrefix(codeBytes, new Uint8Array(content));
183
+ const prefixed = addMulticodecPrefix(code, new Uint8Array(content));
183
184
  const encoded = encodeMultibase("base58btc", prefixed);
184
185
  return new TextDecoder().decode(encoded);
185
186
  }
186
187
 
187
- // cSpell: ignore multicodec pkijs
188
+ // cSpell: ignore pkijs
package/tsdown.config.ts CHANGED
@@ -4,7 +4,7 @@ import { defineConfig } from "tsdown";
4
4
 
5
5
  export default [
6
6
  defineConfig({
7
- entry: ["src/mod.ts"],
7
+ entry: ["src/mod.ts", "src/jsonld.ts"],
8
8
  dts: { compilerOptions: { isolatedDeclarations: true, declaration: true } },
9
9
  format: ["esm", "cjs"],
10
10
  platform: "neutral",
@@ -16,6 +16,6 @@ export default [
16
16
  .map((f) => f.replace(sep, "/")),
17
17
  format: ["esm", "cjs"],
18
18
  platform: "node",
19
- external: [/^node:/],
19
+ external: [/^node:/, "@fedify/fixture"],
20
20
  }),
21
21
  ];