@fedify/vocab-runtime 2.0.7 → 2.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deno.json +1 -1
- package/dist/{chunk-CUT6urMc.cjs → chunk-CKQMccvm.cjs} +7 -9
- package/dist/jsonld.cjs +4 -5
- package/dist/jsonld.d.cts +3 -4
- package/dist/jsonld.d.ts +2 -2
- package/dist/jsonld.js +1 -3
- package/dist/mod.cjs +83 -131
- package/dist/mod.d.cts +1 -5
- package/dist/mod.d.ts +1 -5
- package/dist/mod.js +59 -110
- package/dist/tests/{chunk-DWy1uDak.cjs → chunk-Do9eywBl.cjs} +13 -17
- package/dist/tests/docloader.test.cjs +137 -114
- package/dist/tests/{docloader.test.js → docloader.test.mjs} +132 -115
- package/dist/tests/internal/multicodec.test.cjs +5 -7
- package/dist/tests/internal/{multicodec.test.js → multicodec.test.mjs} +3 -4
- package/dist/tests/key.test.cjs +39 -70
- package/dist/tests/{key.test.js → key.test.mjs} +32 -62
- package/dist/tests/langstr.test.cjs +6 -8
- package/dist/tests/{langstr.test.js → langstr.test.mjs} +2 -4
- package/dist/tests/{link-CdFPEo9O.cjs → link-B6ZWBZhf.cjs} +6 -8
- package/dist/tests/{link-Ck2yj4dH.js → link-B8JGXSS2.mjs} +1 -2
- package/dist/tests/link.test.cjs +5 -7
- package/dist/tests/{link.test.js → link.test.mjs} +3 -4
- package/dist/tests/multibase/multibase.test.cjs +10 -17
- package/dist/tests/multibase/{multibase.test.js → multibase.test.mjs} +10 -18
- package/dist/tests/{multibase-B2D6B0V4.cjs → multibase-CgYqpk4Z.cjs} +43 -49
- package/dist/tests/{multibase-BdHCGO4H.js → multibase-jcKrOpuU.mjs} +5 -12
- package/dist/tests/{multicodec-mHcRzSGY.cjs → multicodec-DeYop8xg.cjs} +16 -18
- package/dist/tests/{multicodec-DvC5xnX2.js → multicodec-aqbZnrNi.mjs} +1 -2
- package/dist/tests/{request-BZixuWv5.js → request-AitXfW_2.mjs} +4 -45
- package/dist/tests/{request-78UEYyIx.cjs → request-C6iSYeYi.cjs} +38 -72
- package/dist/tests/request.test.cjs +23 -24
- package/dist/tests/request.test.mjs +42 -0
- package/dist/tests/{url-C5Vs9nYh.cjs → url-Cr2K-wzd.cjs} +31 -35
- package/dist/tests/{url-fW_DHbih.js → url-Djghaq0m.mjs} +3 -7
- package/dist/tests/url.test.cjs +5 -7
- package/dist/tests/{url.test.js → url.test.mjs} +3 -4
- package/package.json +3 -3
- package/src/docloader.test.ts +67 -0
- package/src/docloader.ts +43 -11
- package/dist/tests/request.test.js +0 -43
- /package/dist/tests/{docloader.test.d.ts → docloader.test.d.mts} +0 -0
- /package/dist/tests/internal/{multicodec.test.d.ts → multicodec.test.d.mts} +0 -0
- /package/dist/tests/{key.test.d.ts → key.test.d.mts} +0 -0
- /package/dist/tests/{langstr.test.d.ts → langstr.test.d.mts} +0 -0
- /package/dist/tests/{link.test.d.ts → link.test.d.mts} +0 -0
- /package/dist/tests/multibase/{multibase.test.d.ts → multibase.test.d.mts} +0 -0
- /package/dist/tests/{request.test.d.ts → request.test.d.mts} +0 -0
- /package/dist/tests/{url.test.d.ts → url.test.d.mts} +0 -0
package/dist/mod.js
CHANGED
|
@@ -9,7 +9,6 @@ import { decodeBase64Url } from "byte-encodings/base64url";
|
|
|
9
9
|
import { createPublicKey } from "node:crypto";
|
|
10
10
|
import { PublicKeyInfo } from "pkijs";
|
|
11
11
|
import baseX from "@multiformats/base-x";
|
|
12
|
-
|
|
13
12
|
//#region src/contexts.ts
|
|
14
13
|
const preloadedContexts = {
|
|
15
14
|
"https://www.w3.org/ns/activitystreams": { "@context": {
|
|
@@ -4257,50 +4256,10 @@ const preloadedContexts = {
|
|
|
4257
4256
|
}
|
|
4258
4257
|
} }
|
|
4259
4258
|
};
|
|
4260
|
-
var contexts_default = preloadedContexts;
|
|
4261
|
-
|
|
4262
4259
|
//#endregion
|
|
4263
4260
|
//#region deno.json
|
|
4264
4261
|
var name = "@fedify/vocab-runtime";
|
|
4265
|
-
var version = "2.0.
|
|
4266
|
-
var license = "MIT";
|
|
4267
|
-
var exports = {
|
|
4268
|
-
".": "./src/mod.ts",
|
|
4269
|
-
"./jsonld": "./src/jsonld.ts"
|
|
4270
|
-
};
|
|
4271
|
-
var description = "Runtime library for @fedify/vocab";
|
|
4272
|
-
var author = {
|
|
4273
|
-
"name": "Hong Minhee",
|
|
4274
|
-
"email": "hong@minhee.org",
|
|
4275
|
-
"url": "https://hongminhee.org/"
|
|
4276
|
-
};
|
|
4277
|
-
var imports = {
|
|
4278
|
-
"@multiformats/base-x": "npm:@multiformats/base-x@^4.0.1",
|
|
4279
|
-
"asn1js": "npm:asn1js@^3.0.6",
|
|
4280
|
-
"byte-encodings": "npm:byte-encodings@^1.0.11",
|
|
4281
|
-
"fetch-mock": "npm:fetch-mock@^12.5.4",
|
|
4282
|
-
"jsonld": "npm:jsonld@^9.0.0",
|
|
4283
|
-
"pkijs": "npm:pkijs@^3.2.5"
|
|
4284
|
-
};
|
|
4285
|
-
var exclude = ["dist", "node_modules"];
|
|
4286
|
-
var publish = { "exclude": ["**/*.test.ts", "tsdown.config.ts"] };
|
|
4287
|
-
var tasks = {
|
|
4288
|
-
"check": "deno fmt --check && deno lint && deno check src/*.ts",
|
|
4289
|
-
"test": "deno test"
|
|
4290
|
-
};
|
|
4291
|
-
var deno_default = {
|
|
4292
|
-
name,
|
|
4293
|
-
version,
|
|
4294
|
-
license,
|
|
4295
|
-
exports,
|
|
4296
|
-
description,
|
|
4297
|
-
author,
|
|
4298
|
-
imports,
|
|
4299
|
-
exclude,
|
|
4300
|
-
publish,
|
|
4301
|
-
tasks
|
|
4302
|
-
};
|
|
4303
|
-
|
|
4262
|
+
var version = "2.0.9";
|
|
4304
4263
|
//#endregion
|
|
4305
4264
|
//#region src/link.ts
|
|
4306
4265
|
const parametersNeedLowerCase = ["rel", "type"];
|
|
@@ -4482,7 +4441,6 @@ var HttpHeaderLink = class HttpHeaderLink {
|
|
|
4482
4441
|
return new this(...inputs).toString();
|
|
4483
4442
|
}
|
|
4484
4443
|
};
|
|
4485
|
-
|
|
4486
4444
|
//#endregion
|
|
4487
4445
|
//#region src/request.ts
|
|
4488
4446
|
/**
|
|
@@ -4528,27 +4486,25 @@ function createActivityPubRequest(url, options = {}) {
|
|
|
4528
4486
|
* @since 1.3.0
|
|
4529
4487
|
*/
|
|
4530
4488
|
function getUserAgent({ software, url } = {}) {
|
|
4531
|
-
const fedify = `Fedify/${
|
|
4489
|
+
const fedify = `Fedify/${version}`;
|
|
4532
4490
|
const runtime = globalThis.Deno?.version?.deno != null ? `Deno/${Deno.version.deno}` : globalThis.process?.versions?.bun != null ? `Bun/${process.versions.bun}` : "navigator" in globalThis && navigator.userAgent === "Cloudflare-Workers" ? navigator.userAgent : globalThis.process?.versions?.node != null ? `Node.js/${process.versions.node}` : null;
|
|
4533
4491
|
const userAgent = software == null ? [fedify] : [software, fedify];
|
|
4534
4492
|
if (runtime != null) userAgent.push(runtime);
|
|
4535
4493
|
if (url != null) userAgent.push(`+${url.toString()}`);
|
|
4536
|
-
|
|
4537
|
-
return `${first} (${userAgent.join("; ")})`;
|
|
4494
|
+
return `${userAgent.shift()} (${userAgent.join("; ")})`;
|
|
4538
4495
|
}
|
|
4539
4496
|
/**
|
|
4540
4497
|
* Logs the request.
|
|
4541
4498
|
* @param request The request to log.
|
|
4542
4499
|
* @internal
|
|
4543
4500
|
*/
|
|
4544
|
-
function logRequest(logger
|
|
4545
|
-
logger
|
|
4501
|
+
function logRequest(logger, request) {
|
|
4502
|
+
logger.debug("Fetching document: {method} {url} {headers}", {
|
|
4546
4503
|
method: request.method,
|
|
4547
4504
|
url: request.url,
|
|
4548
4505
|
headers: Object.fromEntries(request.headers.entries())
|
|
4549
4506
|
});
|
|
4550
4507
|
}
|
|
4551
|
-
|
|
4552
4508
|
//#endregion
|
|
4553
4509
|
//#region src/url.ts
|
|
4554
4510
|
var UrlError = class extends Error {
|
|
@@ -4567,8 +4523,7 @@ async function validatePublicUrl(url) {
|
|
|
4567
4523
|
if (hostname.startsWith("[") && hostname.endsWith("]")) hostname = hostname.substring(1, hostname.length - 2);
|
|
4568
4524
|
if (hostname === "localhost") throw new UrlError("Localhost is not allowed");
|
|
4569
4525
|
if ("Deno" in globalThis && !isIP(hostname)) {
|
|
4570
|
-
|
|
4571
|
-
if (netPermission.state !== "granted") return;
|
|
4526
|
+
if ((await Deno.permissions.query({ name: "net" })).state !== "granted") return;
|
|
4572
4527
|
}
|
|
4573
4528
|
if ("Bun" in globalThis) {
|
|
4574
4529
|
if (hostname === "example.com" || hostname.endsWith(".example.com")) return;
|
|
@@ -4604,10 +4559,8 @@ function expandIPv6Address(address) {
|
|
|
4604
4559
|
if (address.startsWith("::")) address = "0000" + address;
|
|
4605
4560
|
if (address.endsWith("::")) address = address + "0000";
|
|
4606
4561
|
address = address.replace("::", ":0000".repeat(8 - (address.match(/:/g) || []).length) + ":");
|
|
4607
|
-
|
|
4608
|
-
return parts.map((part) => part.padStart(4, "0")).join(":");
|
|
4562
|
+
return address.split(":").map((part) => part.padStart(4, "0")).join(":");
|
|
4609
4563
|
}
|
|
4610
|
-
|
|
4611
4564
|
//#endregion
|
|
4612
4565
|
//#region src/docloader.ts
|
|
4613
4566
|
const logger = getLogger([
|
|
@@ -4615,6 +4568,7 @@ const logger = getLogger([
|
|
|
4615
4568
|
"runtime",
|
|
4616
4569
|
"docloader"
|
|
4617
4570
|
]);
|
|
4571
|
+
const DEFAULT_MAX_REDIRECTION = 20;
|
|
4618
4572
|
/**
|
|
4619
4573
|
* Gets a {@link RemoteDocument} from the given response.
|
|
4620
4574
|
* @param url The URL of the document to load.
|
|
@@ -4624,7 +4578,7 @@ const logger = getLogger([
|
|
|
4624
4578
|
* @throws {FetchError} If the response is not OK.
|
|
4625
4579
|
* @internal
|
|
4626
4580
|
*/
|
|
4627
|
-
async function getRemoteDocument(url, response, fetch
|
|
4581
|
+
async function getRemoteDocument(url, response, fetch) {
|
|
4628
4582
|
const documentUrl = response.url === "" ? url : response.url;
|
|
4629
4583
|
const docUrl = new URL(documentUrl);
|
|
4630
4584
|
if (!response.ok) {
|
|
@@ -4662,7 +4616,7 @@ async function getRemoteDocument(url, response, fetch$1) {
|
|
|
4662
4616
|
alternateUrl: altUri.href,
|
|
4663
4617
|
url: documentUrl
|
|
4664
4618
|
});
|
|
4665
|
-
return await fetch
|
|
4619
|
+
return await fetch(altUri.href);
|
|
4666
4620
|
}
|
|
4667
4621
|
}
|
|
4668
4622
|
}
|
|
@@ -4688,15 +4642,14 @@ async function getRemoteDocument(url, response, fetch$1) {
|
|
|
4688
4642
|
attrPattern.lastIndex = 0;
|
|
4689
4643
|
while ((attrMatch = attrPattern.exec(tagContent)) !== null) {
|
|
4690
4644
|
const key = attrMatch[1].toLowerCase();
|
|
4691
|
-
|
|
4692
|
-
attribs[key] = value;
|
|
4645
|
+
attribs[key] = attrMatch[2] ?? attrMatch[3] ?? attrMatch[4] ?? "";
|
|
4693
4646
|
}
|
|
4694
4647
|
if (attribs.rel === "alternate" && "type" in attribs && (attribs.type === "application/activity+json" || attribs.type === "application/ld+json" || attribs.type.startsWith("application/ld+json;")) && "href" in attribs && new URL(attribs.href, docUrl).href !== docUrl.href) {
|
|
4695
4648
|
logger.debug("Found alternate document: {alternateUrl} from {url}", {
|
|
4696
4649
|
alternateUrl: attribs.href,
|
|
4697
4650
|
url: documentUrl
|
|
4698
4651
|
});
|
|
4699
|
-
return await fetch
|
|
4652
|
+
return await fetch(new URL(attribs.href, docUrl).href);
|
|
4700
4653
|
}
|
|
4701
4654
|
}
|
|
4702
4655
|
document = JSON.parse(html);
|
|
@@ -4731,33 +4684,34 @@ async function getRemoteDocument(url, response, fetch$1) {
|
|
|
4731
4684
|
* @since 1.3.0
|
|
4732
4685
|
*/
|
|
4733
4686
|
function getDocumentLoader({ allowPrivateAddress, skipPreloadedContexts, userAgent } = {}) {
|
|
4734
|
-
const
|
|
4735
|
-
|
|
4736
|
-
async function load(url, options) {
|
|
4687
|
+
const tracer = trace.getTracerProvider().getTracer(name, version);
|
|
4688
|
+
async function load(url, options, redirected = 0, visited = /* @__PURE__ */ new Set()) {
|
|
4737
4689
|
options?.signal?.throwIfAborted();
|
|
4738
|
-
|
|
4739
|
-
|
|
4690
|
+
const currentUrl = new URL(url).href;
|
|
4691
|
+
if (!skipPreloadedContexts && currentUrl in preloadedContexts) {
|
|
4692
|
+
logger.debug("Using preloaded context: {url}.", { url: currentUrl });
|
|
4740
4693
|
return {
|
|
4741
4694
|
contextUrl: null,
|
|
4742
|
-
document:
|
|
4743
|
-
documentUrl:
|
|
4695
|
+
document: preloadedContexts[currentUrl],
|
|
4696
|
+
documentUrl: currentUrl
|
|
4744
4697
|
};
|
|
4745
4698
|
}
|
|
4746
4699
|
if (!allowPrivateAddress) try {
|
|
4747
|
-
await validatePublicUrl(
|
|
4700
|
+
await validatePublicUrl(currentUrl);
|
|
4748
4701
|
} catch (error) {
|
|
4749
4702
|
if (error instanceof UrlError) logger.error("Disallowed private URL: {url}", {
|
|
4750
|
-
url,
|
|
4703
|
+
url: currentUrl,
|
|
4751
4704
|
error
|
|
4752
4705
|
});
|
|
4753
4706
|
throw error;
|
|
4754
4707
|
}
|
|
4708
|
+
visited.add(currentUrl);
|
|
4755
4709
|
return await tracer.startActiveSpan("activitypub.fetch_document", {
|
|
4756
4710
|
kind: SpanKind.CLIENT,
|
|
4757
|
-
attributes: { "url.full":
|
|
4711
|
+
attributes: { "url.full": currentUrl }
|
|
4758
4712
|
}, async (span) => {
|
|
4759
4713
|
try {
|
|
4760
|
-
const request = createActivityPubRequest(
|
|
4714
|
+
const request = createActivityPubRequest(currentUrl, { userAgent });
|
|
4761
4715
|
logRequest(logger, request);
|
|
4762
4716
|
const response = await fetch(request, {
|
|
4763
4717
|
redirect: "manual",
|
|
@@ -4765,11 +4719,25 @@ function getDocumentLoader({ allowPrivateAddress, skipPreloadedContexts, userAge
|
|
|
4765
4719
|
});
|
|
4766
4720
|
span.setAttribute("http.response.status_code", response.status);
|
|
4767
4721
|
if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
|
|
4768
|
-
|
|
4722
|
+
if (redirected >= DEFAULT_MAX_REDIRECTION) {
|
|
4723
|
+
logger.error("Too many redirections ({redirections}) while fetching document.", {
|
|
4724
|
+
redirections: redirected + 1,
|
|
4725
|
+
url: currentUrl
|
|
4726
|
+
});
|
|
4727
|
+
throw new FetchError(currentUrl, `Too many redirections (${redirected + 1})`);
|
|
4728
|
+
}
|
|
4729
|
+
const redirectUrl = new URL(response.headers.get("Location"), response.url === "" ? currentUrl : response.url).href;
|
|
4769
4730
|
span.setAttribute("http.redirect.url", redirectUrl);
|
|
4770
|
-
|
|
4731
|
+
if (visited.has(redirectUrl)) {
|
|
4732
|
+
logger.error("Detected a redirect loop while fetching document: {url} -> {redirectUrl}", {
|
|
4733
|
+
url: currentUrl,
|
|
4734
|
+
redirectUrl
|
|
4735
|
+
});
|
|
4736
|
+
throw new FetchError(currentUrl, `Redirect loop detected: ${redirectUrl}`);
|
|
4737
|
+
}
|
|
4738
|
+
return await load(redirectUrl, options, redirected + 1, visited);
|
|
4771
4739
|
}
|
|
4772
|
-
const result = await getRemoteDocument(
|
|
4740
|
+
const result = await getRemoteDocument(currentUrl, response, load);
|
|
4773
4741
|
span.setAttribute("docloader.document_url", result.documentUrl);
|
|
4774
4742
|
if (result.contextUrl != null) span.setAttribute("docloader.context_url", result.contextUrl);
|
|
4775
4743
|
return result;
|
|
@@ -4787,7 +4755,6 @@ function getDocumentLoader({ allowPrivateAddress, skipPreloadedContexts, userAge
|
|
|
4787
4755
|
}
|
|
4788
4756
|
return load;
|
|
4789
4757
|
}
|
|
4790
|
-
|
|
4791
4758
|
//#endregion
|
|
4792
4759
|
//#region src/internal/multicodec.ts
|
|
4793
4760
|
const INVALID_MULTICODEC_PREFIX = "Invalid multicodec prefix.";
|
|
@@ -4827,7 +4794,6 @@ function addMulticodecPrefix(code, payload) {
|
|
|
4827
4794
|
prefixed.set(payload, prefix.length);
|
|
4828
4795
|
return prefixed;
|
|
4829
4796
|
}
|
|
4830
|
-
|
|
4831
4797
|
//#endregion
|
|
4832
4798
|
//#region src/jwk.ts
|
|
4833
4799
|
function validateCryptoKey(key, type) {
|
|
@@ -4835,11 +4801,9 @@ function validateCryptoKey(key, type) {
|
|
|
4835
4801
|
if (!key.extractable) throw new TypeError("The key is not extractable.");
|
|
4836
4802
|
if (key.algorithm.name !== "RSASSA-PKCS1-v1_5" && key.algorithm.name !== "Ed25519") throw new TypeError("Currently only RSASSA-PKCS1-v1_5 and Ed25519 keys are supported. More algorithms will be added in the future!");
|
|
4837
4803
|
if (key.algorithm.name === "RSASSA-PKCS1-v1_5") {
|
|
4838
|
-
|
|
4839
|
-
if (algorithm.hash.name !== "SHA-256") throw new TypeError("For compatibility with the existing Fediverse software (e.g., Mastodon), hash algorithm for RSASSA-PKCS1-v1_5 keys must be SHA-256.");
|
|
4804
|
+
if (key.algorithm.hash.name !== "SHA-256") throw new TypeError("For compatibility with the existing Fediverse software (e.g., Mastodon), hash algorithm for RSASSA-PKCS1-v1_5 keys must be SHA-256.");
|
|
4840
4805
|
}
|
|
4841
4806
|
}
|
|
4842
|
-
|
|
4843
4807
|
//#endregion
|
|
4844
4808
|
//#region src/multibase/util.ts
|
|
4845
4809
|
const textDecoder = new TextDecoder();
|
|
@@ -4855,7 +4819,6 @@ function concat(arrs, length) {
|
|
|
4855
4819
|
}
|
|
4856
4820
|
return output;
|
|
4857
4821
|
}
|
|
4858
|
-
|
|
4859
4822
|
//#endregion
|
|
4860
4823
|
//#region src/multibase/base.ts
|
|
4861
4824
|
/**
|
|
@@ -4864,8 +4827,8 @@ function concat(arrs, length) {
|
|
|
4864
4827
|
var Base = class {
|
|
4865
4828
|
codeBuf;
|
|
4866
4829
|
codec;
|
|
4867
|
-
constructor(name
|
|
4868
|
-
this.name = name
|
|
4830
|
+
constructor(name, code, factory, alphabet) {
|
|
4831
|
+
this.name = name;
|
|
4869
4832
|
this.code = code;
|
|
4870
4833
|
this.alphabet = alphabet;
|
|
4871
4834
|
this.codeBuf = encodeText(this.code);
|
|
@@ -4880,12 +4843,11 @@ var Base = class {
|
|
|
4880
4843
|
return this.codec.decode(string);
|
|
4881
4844
|
}
|
|
4882
4845
|
};
|
|
4883
|
-
|
|
4884
4846
|
//#endregion
|
|
4885
4847
|
//#region src/multibase/rfc4648.ts
|
|
4886
4848
|
const decode = (string, alphabet, bitsPerChar) => {
|
|
4887
|
-
const codes
|
|
4888
|
-
for (let i = 0; i < alphabet.length; ++i) codes
|
|
4849
|
+
const codes = {};
|
|
4850
|
+
for (let i = 0; i < alphabet.length; ++i) codes[alphabet[i]] = i;
|
|
4889
4851
|
let end = string.length;
|
|
4890
4852
|
while (string[end - 1] === "=") --end;
|
|
4891
4853
|
const out = new Uint8Array(end * bitsPerChar / 8 | 0);
|
|
@@ -4893,7 +4855,7 @@ const decode = (string, alphabet, bitsPerChar) => {
|
|
|
4893
4855
|
let buffer = 0;
|
|
4894
4856
|
let written = 0;
|
|
4895
4857
|
for (let i = 0; i < end; ++i) {
|
|
4896
|
-
const value = codes
|
|
4858
|
+
const value = codes[string[i]];
|
|
4897
4859
|
if (value === void 0) throw new SyntaxError("Invalid character " + string[i]);
|
|
4898
4860
|
buffer = buffer << bitsPerChar | value;
|
|
4899
4861
|
bits += bitsPerChar;
|
|
@@ -4936,7 +4898,6 @@ const rfc4648 = (bitsPerChar) => (alphabet) => {
|
|
|
4936
4898
|
}
|
|
4937
4899
|
};
|
|
4938
4900
|
};
|
|
4939
|
-
|
|
4940
4901
|
//#endregion
|
|
4941
4902
|
//#region src/multibase/constants.ts
|
|
4942
4903
|
const identity = () => {
|
|
@@ -5098,7 +5059,6 @@ const codes = constants.reduce((prev, tupple) => {
|
|
|
5098
5059
|
prev[tupple[1]] = names[tupple[0]];
|
|
5099
5060
|
return prev;
|
|
5100
5061
|
}, {});
|
|
5101
|
-
|
|
5102
5062
|
//#endregion
|
|
5103
5063
|
//#region src/multibase/mod.ts
|
|
5104
5064
|
/**
|
|
@@ -5135,8 +5095,7 @@ function decodeMultibase(data) {
|
|
|
5135
5095
|
"k",
|
|
5136
5096
|
"K"
|
|
5137
5097
|
].includes(prefix)) data = data.toLowerCase();
|
|
5138
|
-
|
|
5139
|
-
return enc.decode(data.substring(1));
|
|
5098
|
+
return encoding(data[0]).decode(data.substring(1));
|
|
5140
5099
|
}
|
|
5141
5100
|
/**
|
|
5142
5101
|
* Get the encoding by name or code
|
|
@@ -5158,7 +5117,6 @@ function encodingFromBaseData(data) {
|
|
|
5158
5117
|
if (data instanceof Uint8Array) data = decodeText(data);
|
|
5159
5118
|
return encoding(data[0]);
|
|
5160
5119
|
}
|
|
5161
|
-
|
|
5162
5120
|
//#endregion
|
|
5163
5121
|
//#region src/key.ts
|
|
5164
5122
|
const algorithms = {
|
|
@@ -5183,8 +5141,7 @@ async function importSpki(pem) {
|
|
|
5183
5141
|
} catch (_) {
|
|
5184
5142
|
throw new TypeError("Invalid PEM-SPKI format.");
|
|
5185
5143
|
}
|
|
5186
|
-
const
|
|
5187
|
-
const oid = pki.algorithm.algorithmId;
|
|
5144
|
+
const oid = PublicKeyInfo.fromBER(spki).algorithm.algorithmId;
|
|
5188
5145
|
const algorithm = algorithms[oid];
|
|
5189
5146
|
if (algorithm == null) throw new TypeError("Unsupported algorithm: " + oid);
|
|
5190
5147
|
return await crypto.subtle.importKey("spki", spki, algorithm, true, ["verify"]);
|
|
@@ -5198,8 +5155,7 @@ async function importSpki(pem) {
|
|
|
5198
5155
|
*/
|
|
5199
5156
|
async function exportSpki(key) {
|
|
5200
5157
|
validateCryptoKey(key);
|
|
5201
|
-
|
|
5202
|
-
let pem = encodeBase64(spki);
|
|
5158
|
+
let pem = encodeBase64(await crypto.subtle.exportKey("spki", key));
|
|
5203
5159
|
pem = (pem.match(/.{1,64}/g) || []).join("\n");
|
|
5204
5160
|
return `-----BEGIN PUBLIC KEY-----\n${pem}\n-----END PUBLIC KEY-----\n`;
|
|
5205
5161
|
}
|
|
@@ -5211,16 +5167,14 @@ async function exportSpki(key) {
|
|
|
5211
5167
|
* @since 1.5.0
|
|
5212
5168
|
*/
|
|
5213
5169
|
function importPkcs1(pem) {
|
|
5214
|
-
|
|
5170
|
+
return importSpki(createPublicKey({
|
|
5215
5171
|
key: pem,
|
|
5216
5172
|
format: "pem",
|
|
5217
5173
|
type: "pkcs1"
|
|
5218
|
-
})
|
|
5219
|
-
const spki = key.export({
|
|
5174
|
+
}).export({
|
|
5220
5175
|
type: "spki",
|
|
5221
5176
|
format: "pem"
|
|
5222
|
-
});
|
|
5223
|
-
return importSpki(spki);
|
|
5177
|
+
}));
|
|
5224
5178
|
}
|
|
5225
5179
|
const PKCS1_HEADER = /^\s*-----BEGIN\s+RSA\s+PUBLIC\s+KEY-----\s*\n/;
|
|
5226
5180
|
/**
|
|
@@ -5247,12 +5201,11 @@ async function importMultibaseKey(key) {
|
|
|
5247
5201
|
const { code } = getMulticodecPrefix(decoded);
|
|
5248
5202
|
const content = removeMulticodecPrefix(decoded);
|
|
5249
5203
|
if (code === 4613) {
|
|
5250
|
-
const
|
|
5204
|
+
const exported = createPublicKey({
|
|
5251
5205
|
key: content,
|
|
5252
5206
|
format: "der",
|
|
5253
5207
|
type: "pkcs1"
|
|
5254
|
-
})
|
|
5255
|
-
const exported = keyObject.export({
|
|
5208
|
+
}).export({
|
|
5256
5209
|
type: "spki",
|
|
5257
5210
|
format: "der"
|
|
5258
5211
|
});
|
|
@@ -5284,21 +5237,18 @@ async function exportMultibaseKey(key) {
|
|
|
5284
5237
|
const decodedN = decodeBase64Url(jwk.n);
|
|
5285
5238
|
const n = new Uint8Array(decodedN.length + 1);
|
|
5286
5239
|
n.set(decodedN, 1);
|
|
5287
|
-
|
|
5240
|
+
content = new Sequence({ value: [new Integer({
|
|
5288
5241
|
isHexOnly: true,
|
|
5289
5242
|
valueHex: n
|
|
5290
5243
|
}), new Integer({
|
|
5291
5244
|
isHexOnly: true,
|
|
5292
5245
|
valueHex: decodeBase64Url(jwk.e)
|
|
5293
|
-
})] });
|
|
5294
|
-
content = sequence.toBER(false);
|
|
5246
|
+
})] }).toBER(false);
|
|
5295
5247
|
code = 4613;
|
|
5296
5248
|
} else throw new TypeError("Unsupported key type: " + JSON.stringify(key.algorithm));
|
|
5297
|
-
const
|
|
5298
|
-
const encoded = encodeMultibase("base58btc", prefixed);
|
|
5249
|
+
const encoded = encodeMultibase("base58btc", addMulticodecPrefix(code, new Uint8Array(content)));
|
|
5299
5250
|
return new TextDecoder().decode(encoded);
|
|
5300
5251
|
}
|
|
5301
|
-
|
|
5302
5252
|
//#endregion
|
|
5303
5253
|
//#region src/langstr.ts
|
|
5304
5254
|
/**
|
|
@@ -5327,6 +5277,5 @@ LanguageString.prototype[Symbol.for("Deno.customInspect")] = function(inspect, o
|
|
|
5327
5277
|
LanguageString.prototype[Symbol.for("nodejs.util.inspect.custom")] = function(_depth, options, inspect) {
|
|
5328
5278
|
return `<${this.locale.baseName}> ${inspect(this.toString(), options)}`;
|
|
5329
5279
|
};
|
|
5330
|
-
|
|
5331
5280
|
//#endregion
|
|
5332
|
-
export { FetchError, LanguageString, UrlError, createActivityPubRequest, decodeMultibase, encodeMultibase, encodingFromBaseData, expandIPv6Address, exportMultibaseKey, exportSpki, getDocumentLoader, getRemoteDocument, getUserAgent, importMultibaseKey, importPem, importPkcs1, importSpki, isValidPublicIPv4Address, isValidPublicIPv6Address, logRequest,
|
|
5281
|
+
export { FetchError, LanguageString, UrlError, createActivityPubRequest, decodeMultibase, encodeMultibase, encodingFromBaseData, expandIPv6Address, exportMultibaseKey, exportSpki, getDocumentLoader, getRemoteDocument, getUserAgent, importMultibaseKey, importPem, importPkcs1, importSpki, isValidPublicIPv4Address, isValidPublicIPv6Address, logRequest, preloadedContexts, validatePublicUrl };
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
//#region
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var
|
|
9
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
-
};
|
|
8
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
11
9
|
var __copyProps = (to, from, except, desc) => {
|
|
12
10
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
13
11
|
key = keys[i];
|
|
@@ -22,18 +20,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
20
|
value: mod,
|
|
23
21
|
enumerable: true
|
|
24
22
|
}) : target, mod));
|
|
25
|
-
|
|
26
23
|
//#endregion
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
Object.defineProperty(exports, "__commonJSMin", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function() {
|
|
27
|
+
return __commonJSMin;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "__toESM", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function() {
|
|
33
|
+
return __toESM;
|
|
34
|
+
}
|
|
33
35
|
});
|
|
34
|
-
Object.defineProperty(exports, '__toESM', {
|
|
35
|
-
enumerable: true,
|
|
36
|
-
get: function () {
|
|
37
|
-
return __toESM;
|
|
38
|
-
}
|
|
39
|
-
});
|