@fedify/fedify 2.0.36-dev.2551 → 2.0.36-dev.2637
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/dist/{builder-Dndt590h.mjs → builder-BC3eRIbe.mjs} +3 -3
- package/dist/compat/mod.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{context-lxjaUTAI.d.ts → context-C00pWP8x.d.ts} +6 -0
- package/dist/{context-CnoWxuoB.d.cts → context-ao-qb3eP.d.cts} +6 -0
- package/dist/{deno-D_rTMbAD.mjs → deno-Dv6PIwH_.mjs} +1 -1
- package/dist/{docloader-DpTrZ5sA.mjs → docloader-BgHM-JLc.mjs} +2 -2
- package/dist/federation/builder.test.mjs +1 -1
- package/dist/federation/handler.test.mjs +8 -8
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/inbox.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +696 -8
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.d.cts +2 -2
- package/dist/federation/mod.d.ts +2 -2
- package/dist/federation/mod.js +1 -1
- package/dist/federation/send.test.mjs +3 -3
- package/dist/federation/temporal.test.mjs +1 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{http-DGD9d8-A.mjs → http-BWoAqky4.mjs} +2 -2
- package/dist/{http-BS1CmlZ6.js → http-CrEB4I8A.js} +1 -1
- package/dist/{http-DbDnj-Q7.cjs → http-D69BMfAn.cjs} +1 -1
- package/dist/{inbox-BwpBTbhH.mjs → inbox-0Dbv0QVc.mjs} +1 -1
- package/dist/{key-1Gf85RN1.mjs → key-ChKDZfvS.mjs} +1 -1
- package/dist/{kv-cache-BdA7HpfF.cjs → kv-cache-B0JZ30EF.cjs} +1 -1
- package/dist/{kv-cache-BARiicPE.js → kv-cache-CDvE8__9.js} +1 -1
- package/dist/{ld-BuuOR_Ms.mjs → ld-DbSNiv8Q.mjs} +99 -10
- package/dist/{middleware-C5Nypx4Z.mjs → middleware-BA9cM-vz.mjs} +1 -1
- package/dist/{middleware-DDM0j-X6.mjs → middleware-C849kmHB.mjs} +160 -29
- package/dist/{middleware-CQRCnFB4.js → middleware-CEufJR5k.js} +152 -21
- package/dist/{middleware-DThg01d8.cjs → middleware-C_fDk_dx.cjs} +153 -22
- package/dist/{middleware-D9TWYyT_.cjs → middleware-DCtCNota.cjs} +1 -1
- package/dist/{mod-w1oyHseQ.d.cts → mod-6uJWdCc0.d.cts} +1 -1
- package/dist/{mod-DVPS4yam.d.cts → mod-BA6vqC2S.d.cts} +19 -7
- package/dist/{mod-BS-jg3Wx.d.ts → mod-CL9Ep0uo.d.ts} +19 -7
- package/dist/{mod-I-34OMN3.d.ts → mod-DtRh015i.d.ts} +1 -1
- package/dist/mod.cjs +4 -4
- package/dist/mod.d.cts +3 -3
- package/dist/mod.d.ts +3 -3
- package/dist/mod.js +4 -4
- package/dist/nodeinfo/handler.test.mjs +1 -1
- package/dist/{owner-BI33UeIv.mjs → owner-BJeJfxnT.mjs} +2 -2
- package/dist/{proof-GM73LJjx.mjs → proof-CaMBdk_x.mjs} +36 -12
- package/dist/{proof-vVwkNRv4.cjs → proof-DNgQwz9E.cjs} +131 -18
- package/dist/{proof-BBHUW8ev.js → proof-DwooE8kV.js} +132 -19
- package/dist/{send-nImUK91D.mjs → send-CYrAOC1K.mjs} +2 -2
- package/dist/sig/http.test.mjs +2 -2
- package/dist/sig/key.test.mjs +2 -2
- package/dist/sig/ld.test.mjs +198 -4
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.d.cts +1 -1
- package/dist/sig/mod.d.ts +1 -1
- package/dist/sig/mod.js +2 -2
- package/dist/sig/owner.test.mjs +1 -1
- package/dist/sig/proof.test.mjs +71 -2
- package/dist/{temporal-CfNFB7M_.mjs → temporal-BJoGKOXy.mjs} +1 -1
- package/dist/utils/docloader.test.mjs +2 -2
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +5 -5
|
@@ -10,7 +10,7 @@ import { TracerProvider } from "@opentelemetry/api";
|
|
|
10
10
|
* @since 1.0.0
|
|
11
11
|
*/
|
|
12
12
|
interface Signature {
|
|
13
|
-
"@context"?: "https://w3id.org/identity/v1";
|
|
13
|
+
"@context"?: "https://w3id.org/identity/v1" | "https://w3id.org/security/v1";
|
|
14
14
|
type: "RsaSignature2017";
|
|
15
15
|
id?: string;
|
|
16
16
|
creator: string;
|
|
@@ -19,16 +19,26 @@ interface Signature {
|
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Attaches a LD signature to the given JSON-LD document.
|
|
22
|
+
*
|
|
23
|
+
* When the document's context does not already define the `signature`
|
|
24
|
+
* property, the returned document adds a minimal inline context for it.
|
|
25
|
+
* Without that definition, expanding the attached signature would produce a
|
|
26
|
+
* blank node predicate, which is not valid RDF. Documents that already carry
|
|
27
|
+
* a `proof` are left unchanged, since a new context definition would invalidate
|
|
28
|
+
* the proof. Documents whose context includes an unrecognized remote context
|
|
29
|
+
* are also left unchanged, since that context may already define `signature`.
|
|
22
30
|
* @param jsonLd The JSON-LD document to attach the signature to. It is not
|
|
23
31
|
* modified.
|
|
24
32
|
* @param signature The signature to attach.
|
|
25
33
|
* @returns The JSON-LD document with the attached signature.
|
|
26
34
|
* @throws {TypeError} If the input document is not a valid JSON-LD document.
|
|
35
|
+
* Top-level arrays are rejected, since a Linked Data
|
|
36
|
+
* Signature is attached to a single node.
|
|
27
37
|
* @since 1.0.0
|
|
28
38
|
*/
|
|
29
39
|
declare function attachSignature(jsonLd: unknown, signature: Signature): {
|
|
30
40
|
signature: Signature;
|
|
31
|
-
}
|
|
41
|
+
} & Record<string, unknown>;
|
|
32
42
|
/**
|
|
33
43
|
* Options for creating Linked Data Signatures.
|
|
34
44
|
* @since 1.0.0
|
|
@@ -46,6 +56,12 @@ interface CreateSignatureOptions {
|
|
|
46
56
|
}
|
|
47
57
|
/**
|
|
48
58
|
* Creates a LD signature for the given JSON-LD document.
|
|
59
|
+
*
|
|
60
|
+
* If the document's context does not define the `signature` property, the
|
|
61
|
+
* signature is computed over the document with a minimal inline definition
|
|
62
|
+
* added. Use {@link attachSignature} to attach the signature to that exact
|
|
63
|
+
* document. Documents that already carry a `proof`, or whose context includes
|
|
64
|
+
* an unrecognized remote context, are hashed unchanged.
|
|
49
65
|
* @param jsonLd The JSON-LD document to sign.
|
|
50
66
|
* @param privateKey The private key to sign the document.
|
|
51
67
|
* @param keyId The ID of the public key that corresponds to the private key.
|
|
@@ -173,11 +189,7 @@ interface CreateProofOptions {
|
|
|
173
189
|
* @throws {TypeError} If the private key is invalid or unsupported.
|
|
174
190
|
* @since 0.10.0
|
|
175
191
|
*/
|
|
176
|
-
declare function createProof(object: Object$1, privateKey: CryptoKey, keyId: URL,
|
|
177
|
-
contextLoader,
|
|
178
|
-
context,
|
|
179
|
-
created
|
|
180
|
-
}?: CreateProofOptions): Promise<DataIntegrityProof>;
|
|
192
|
+
declare function createProof(object: Object$1, privateKey: CryptoKey, keyId: URL, options?: CreateProofOptions): Promise<DataIntegrityProof>;
|
|
181
193
|
/**
|
|
182
194
|
* Options for {@link signObject}.
|
|
183
195
|
* @since 0.10.0
|
|
@@ -10,7 +10,7 @@ import { DocumentLoader } from "@fedify/vocab-runtime";
|
|
|
10
10
|
* @since 1.0.0
|
|
11
11
|
*/
|
|
12
12
|
interface Signature {
|
|
13
|
-
"@context"?: "https://w3id.org/identity/v1";
|
|
13
|
+
"@context"?: "https://w3id.org/identity/v1" | "https://w3id.org/security/v1";
|
|
14
14
|
type: "RsaSignature2017";
|
|
15
15
|
id?: string;
|
|
16
16
|
creator: string;
|
|
@@ -19,16 +19,26 @@ interface Signature {
|
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Attaches a LD signature to the given JSON-LD document.
|
|
22
|
+
*
|
|
23
|
+
* When the document's context does not already define the `signature`
|
|
24
|
+
* property, the returned document adds a minimal inline context for it.
|
|
25
|
+
* Without that definition, expanding the attached signature would produce a
|
|
26
|
+
* blank node predicate, which is not valid RDF. Documents that already carry
|
|
27
|
+
* a `proof` are left unchanged, since a new context definition would invalidate
|
|
28
|
+
* the proof. Documents whose context includes an unrecognized remote context
|
|
29
|
+
* are also left unchanged, since that context may already define `signature`.
|
|
22
30
|
* @param jsonLd The JSON-LD document to attach the signature to. It is not
|
|
23
31
|
* modified.
|
|
24
32
|
* @param signature The signature to attach.
|
|
25
33
|
* @returns The JSON-LD document with the attached signature.
|
|
26
34
|
* @throws {TypeError} If the input document is not a valid JSON-LD document.
|
|
35
|
+
* Top-level arrays are rejected, since a Linked Data
|
|
36
|
+
* Signature is attached to a single node.
|
|
27
37
|
* @since 1.0.0
|
|
28
38
|
*/
|
|
29
39
|
declare function attachSignature(jsonLd: unknown, signature: Signature): {
|
|
30
40
|
signature: Signature;
|
|
31
|
-
}
|
|
41
|
+
} & Record<string, unknown>;
|
|
32
42
|
/**
|
|
33
43
|
* Options for creating Linked Data Signatures.
|
|
34
44
|
* @since 1.0.0
|
|
@@ -46,6 +56,12 @@ interface CreateSignatureOptions {
|
|
|
46
56
|
}
|
|
47
57
|
/**
|
|
48
58
|
* Creates a LD signature for the given JSON-LD document.
|
|
59
|
+
*
|
|
60
|
+
* If the document's context does not define the `signature` property, the
|
|
61
|
+
* signature is computed over the document with a minimal inline definition
|
|
62
|
+
* added. Use {@link attachSignature} to attach the signature to that exact
|
|
63
|
+
* document. Documents that already carry a `proof`, or whose context includes
|
|
64
|
+
* an unrecognized remote context, are hashed unchanged.
|
|
49
65
|
* @param jsonLd The JSON-LD document to sign.
|
|
50
66
|
* @param privateKey The private key to sign the document.
|
|
51
67
|
* @param keyId The ID of the public key that corresponds to the private key.
|
|
@@ -173,11 +189,7 @@ interface CreateProofOptions {
|
|
|
173
189
|
* @throws {TypeError} If the private key is invalid or unsupported.
|
|
174
190
|
* @since 0.10.0
|
|
175
191
|
*/
|
|
176
|
-
declare function createProof(object: Object$1, privateKey: CryptoKey, keyId: URL,
|
|
177
|
-
contextLoader,
|
|
178
|
-
context,
|
|
179
|
-
created
|
|
180
|
-
}?: CreateProofOptions): Promise<DataIntegrityProof>;
|
|
192
|
+
declare function createProof(object: Object$1, privateKey: CryptoKey, keyId: URL, options?: CreateProofOptions): Promise<DataIntegrityProof>;
|
|
181
193
|
/**
|
|
182
194
|
* Options for {@link signObject}.
|
|
183
195
|
* @since 0.10.0
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { X as ActorDispatcher, Y as ActorAliasMapper, Z as ActorHandleMapper, mt as WebFingerLinksDispatcher, s as RequestContext } from "./context-
|
|
2
|
+
import { X as ActorDispatcher, Y as ActorAliasMapper, Z as ActorHandleMapper, mt as WebFingerLinksDispatcher, s as RequestContext } from "./context-C00pWP8x.js";
|
|
3
3
|
import { Span, Tracer } from "@opentelemetry/api";
|
|
4
4
|
|
|
5
5
|
//#region src/federation/webfinger.d.ts
|
package/dist/mod.cjs
CHANGED
|
@@ -4,11 +4,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
4
4
|
require("./chunk-DDcVe30Y.cjs");
|
|
5
5
|
const require_transformers = require("./transformers-NeAONrAq.cjs");
|
|
6
6
|
require("./compat/mod.cjs");
|
|
7
|
-
const require_http = require("./http-
|
|
8
|
-
const require_middleware = require("./middleware-
|
|
7
|
+
const require_http = require("./http-D69BMfAn.cjs");
|
|
8
|
+
const require_middleware = require("./middleware-C_fDk_dx.cjs");
|
|
9
9
|
const require_types = require("./types-DOvyymM4.cjs");
|
|
10
|
-
const require_proof = require("./proof-
|
|
11
|
-
const require_kv_cache = require("./kv-cache-
|
|
10
|
+
const require_proof = require("./proof-DNgQwz9E.cjs");
|
|
11
|
+
const require_kv_cache = require("./kv-cache-B0JZ30EF.cjs");
|
|
12
12
|
const require_federation_mod = require("./federation/mod.cjs");
|
|
13
13
|
require("./nodeinfo/mod.cjs");
|
|
14
14
|
require("./runtime/mod.cjs");
|
package/dist/mod.d.cts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
import { a as InboundService, c as OutboundService, d as Software, f as Usage, i as parseNodeInfo, l as Protocol, n as ParseNodeInfoOptions, o as JsonValue, p as nodeInfoToJson, r as getNodeInfo, s as NodeInfo, t as GetNodeInfoOptions, u as Services } from "./client-BIBzqEIp.cjs";
|
|
3
3
|
import { a as signRequest, c as FetchKeyResult, d as fetchKey, f as generateCryptoKeyPair, i as VerifyRequestOptions, l as KeyCache, n as HttpMessageSignaturesSpecDeterminer, o as verifyRequest, p as importJwk, r as SignRequestOptions, s as FetchKeyOptions, t as HttpMessageSignaturesSpec, u as exportJwk } from "./http-DFqAb11b.cjs";
|
|
4
4
|
import { i as getKeyOwner, n as GetKeyOwnerOptions, r as doesActorOwnKey, t as DoesActorOwnKeyOptions } from "./owner-B3hNQCG8.cjs";
|
|
5
|
-
import { $ as AuthorizePredicate, A as CreateExponentialBackoffPolicyOptions, B as RespondWithObjectOptions, C as InboxListenerSetters, D as FederationOrigin, E as FederationKvPrefixes, F as createFederationBuilder, G as MessageQueue, H as respondWithObjectIfAcceptable, I as Router, J as ParallelMessageQueue, K as MessageQueueEnqueueOptions, L as RouterError, M as RetryPolicy, N as createExponentialBackoffPolicy, O as FederationQueueOptions, P as Message, Q as ActorKeyPairsDispatcher, R as RouterOptions, S as IdempotencyStrategy, T as Rfc6570Expression, U as InProcessMessageQueue, V as respondWithObject, W as InProcessMessageQueueOptions, X as ActorDispatcher, Y as ActorAliasMapper, Z as ActorHandleMapper, _ as FederationBuilder, _t as PageItems, a as InboxContext, at as CustomCollectionDispatcher, b as FederationStartQueueOptions, bt as ActivityTransformer, c as RouteActivityOptions, ct as NodeInfoDispatcher, d as ActorCallbackSetters, dt as OutboxErrorHandler, et as CollectionCounter, f as CollectionCallbackSetters, ft as OutboxPermanentFailureHandler, g as Federation, gt as SenderKeyPair, h as Federatable, ht as SendActivityError, i as GetSignedKeyOptions, it as CustomCollectionCursor, j as RetryContext, k as createFederation, l as SendActivityOptions, lt as ObjectAuthorizePredicate, m as CustomCollectionCallbackSetters, mt as WebFingerLinksDispatcher, n as Context, nt as CollectionDispatcher, o as ParseUriResult, ot as InboxErrorHandler, p as ConstructorWithTypeId, pt as SharedInboxKeyDispatcher, q as MessageQueueListenOptions, r as ForwardActivityOptions, rt as CustomCollectionCounter, s as RequestContext, st as InboxListener, t as ActorKeyPair, tt as CollectionCursor, u as SendActivityOptionsForCollection, ut as ObjectDispatcher, v as FederationFetchOptions, vt as buildCollectionSynchronizationHeader, w as ObjectCallbackSetters, x as IdempotencyKeyCallback, y as FederationOptions, yt as digest, z as RouterRouteResult } from "./context-
|
|
5
|
+
import { $ as AuthorizePredicate, A as CreateExponentialBackoffPolicyOptions, B as RespondWithObjectOptions, C as InboxListenerSetters, D as FederationOrigin, E as FederationKvPrefixes, F as createFederationBuilder, G as MessageQueue, H as respondWithObjectIfAcceptable, I as Router, J as ParallelMessageQueue, K as MessageQueueEnqueueOptions, L as RouterError, M as RetryPolicy, N as createExponentialBackoffPolicy, O as FederationQueueOptions, P as Message, Q as ActorKeyPairsDispatcher, R as RouterOptions, S as IdempotencyStrategy, T as Rfc6570Expression, U as InProcessMessageQueue, V as respondWithObject, W as InProcessMessageQueueOptions, X as ActorDispatcher, Y as ActorAliasMapper, Z as ActorHandleMapper, _ as FederationBuilder, _t as PageItems, a as InboxContext, at as CustomCollectionDispatcher, b as FederationStartQueueOptions, bt as ActivityTransformer, c as RouteActivityOptions, ct as NodeInfoDispatcher, d as ActorCallbackSetters, dt as OutboxErrorHandler, et as CollectionCounter, f as CollectionCallbackSetters, ft as OutboxPermanentFailureHandler, g as Federation, gt as SenderKeyPair, h as Federatable, ht as SendActivityError, i as GetSignedKeyOptions, it as CustomCollectionCursor, j as RetryContext, k as createFederation, l as SendActivityOptions, lt as ObjectAuthorizePredicate, m as CustomCollectionCallbackSetters, mt as WebFingerLinksDispatcher, n as Context, nt as CollectionDispatcher, o as ParseUriResult, ot as InboxErrorHandler, p as ConstructorWithTypeId, pt as SharedInboxKeyDispatcher, q as MessageQueueListenOptions, r as ForwardActivityOptions, rt as CustomCollectionCounter, s as RequestContext, st as InboxListener, t as ActorKeyPair, tt as CollectionCursor, u as SendActivityOptionsForCollection, ut as ObjectDispatcher, v as FederationFetchOptions, vt as buildCollectionSynchronizationHeader, w as ObjectCallbackSetters, x as IdempotencyKeyCallback, y as FederationOptions, yt as digest, z as RouterRouteResult } from "./context-ao-qb3eP.cjs";
|
|
6
6
|
import { a as MemoryKvStore, i as KvStoreSetOptions, n as KvStore, r as KvStoreListEntry, t as KvKey } from "./kv-CZKl1IUS.cjs";
|
|
7
7
|
import { actorDehydrator, autoIdAssigner, getDefaultActivityTransformers } from "./compat/mod.cjs";
|
|
8
|
-
import { n as handleWebFinger, t as WebFingerHandlerParameters } from "./mod-
|
|
9
|
-
import { _ as verifyJsonLd, a as createProof, c as verifyProof, d as VerifyJsonLdOptions, f as VerifySignatureOptions, g as signJsonLd, h as detachSignature, i as VerifyProofOptions, l as CreateSignatureOptions, m as createSignature, n as SignObjectOptions, o as signObject, p as attachSignature, r as VerifyObjectOptions, s as verifyObject, t as CreateProofOptions, u as SignJsonLdOptions, v as verifySignature } from "./mod-
|
|
8
|
+
import { n as handleWebFinger, t as WebFingerHandlerParameters } from "./mod-6uJWdCc0.cjs";
|
|
9
|
+
import { _ as verifyJsonLd, a as createProof, c as verifyProof, d as VerifyJsonLdOptions, f as VerifySignatureOptions, g as signJsonLd, h as detachSignature, i as VerifyProofOptions, l as CreateSignatureOptions, m as createSignature, n as SignObjectOptions, o as signObject, p as attachSignature, r as VerifyObjectOptions, s as verifyObject, t as CreateProofOptions, u as SignJsonLdOptions, v as verifySignature } from "./mod-BA6vqC2S.cjs";
|
|
10
10
|
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./mod-BPDfu4Ey.cjs";
|
|
11
11
|
export * from "@fedify/vocab-runtime";
|
|
12
12
|
|
package/dist/mod.d.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
import { a as InboundService, c as OutboundService, d as Software, f as Usage, i as parseNodeInfo, l as Protocol, n as ParseNodeInfoOptions, o as JsonValue, p as nodeInfoToJson, r as getNodeInfo, s as NodeInfo, t as GetNodeInfoOptions, u as Services } from "./client-jE7oGvRh.js";
|
|
3
3
|
import { a as signRequest, c as FetchKeyResult, d as fetchKey, f as generateCryptoKeyPair, i as VerifyRequestOptions, l as KeyCache, n as HttpMessageSignaturesSpecDeterminer, o as verifyRequest, p as importJwk, r as SignRequestOptions, s as FetchKeyOptions, t as HttpMessageSignaturesSpec, u as exportJwk } from "./http-Cd8UD1ym.js";
|
|
4
4
|
import { i as getKeyOwner, n as GetKeyOwnerOptions, r as doesActorOwnKey, t as DoesActorOwnKeyOptions } from "./owner-CiBPcC6F.js";
|
|
5
|
-
import { $ as AuthorizePredicate, A as CreateExponentialBackoffPolicyOptions, B as RespondWithObjectOptions, C as InboxListenerSetters, D as FederationOrigin, E as FederationKvPrefixes, F as createFederationBuilder, G as MessageQueue, H as respondWithObjectIfAcceptable, I as Router, J as ParallelMessageQueue, K as MessageQueueEnqueueOptions, L as RouterError, M as RetryPolicy, N as createExponentialBackoffPolicy, O as FederationQueueOptions, P as Message, Q as ActorKeyPairsDispatcher, R as RouterOptions, S as IdempotencyStrategy, T as Rfc6570Expression, U as InProcessMessageQueue, V as respondWithObject, W as InProcessMessageQueueOptions, X as ActorDispatcher, Y as ActorAliasMapper, Z as ActorHandleMapper, _ as FederationBuilder, _t as PageItems, a as InboxContext, at as CustomCollectionDispatcher, b as FederationStartQueueOptions, bt as ActivityTransformer, c as RouteActivityOptions, ct as NodeInfoDispatcher, d as ActorCallbackSetters, dt as OutboxErrorHandler, et as CollectionCounter, f as CollectionCallbackSetters, ft as OutboxPermanentFailureHandler, g as Federation, gt as SenderKeyPair, h as Federatable, ht as SendActivityError, i as GetSignedKeyOptions, it as CustomCollectionCursor, j as RetryContext, k as createFederation, l as SendActivityOptions, lt as ObjectAuthorizePredicate, m as CustomCollectionCallbackSetters, mt as WebFingerLinksDispatcher, n as Context, nt as CollectionDispatcher, o as ParseUriResult, ot as InboxErrorHandler, p as ConstructorWithTypeId, pt as SharedInboxKeyDispatcher, q as MessageQueueListenOptions, r as ForwardActivityOptions, rt as CustomCollectionCounter, s as RequestContext, st as InboxListener, t as ActorKeyPair, tt as CollectionCursor, u as SendActivityOptionsForCollection, ut as ObjectDispatcher, v as FederationFetchOptions, vt as buildCollectionSynchronizationHeader, w as ObjectCallbackSetters, x as IdempotencyKeyCallback, y as FederationOptions, yt as digest, z as RouterRouteResult } from "./context-
|
|
5
|
+
import { $ as AuthorizePredicate, A as CreateExponentialBackoffPolicyOptions, B as RespondWithObjectOptions, C as InboxListenerSetters, D as FederationOrigin, E as FederationKvPrefixes, F as createFederationBuilder, G as MessageQueue, H as respondWithObjectIfAcceptable, I as Router, J as ParallelMessageQueue, K as MessageQueueEnqueueOptions, L as RouterError, M as RetryPolicy, N as createExponentialBackoffPolicy, O as FederationQueueOptions, P as Message, Q as ActorKeyPairsDispatcher, R as RouterOptions, S as IdempotencyStrategy, T as Rfc6570Expression, U as InProcessMessageQueue, V as respondWithObject, W as InProcessMessageQueueOptions, X as ActorDispatcher, Y as ActorAliasMapper, Z as ActorHandleMapper, _ as FederationBuilder, _t as PageItems, a as InboxContext, at as CustomCollectionDispatcher, b as FederationStartQueueOptions, bt as ActivityTransformer, c as RouteActivityOptions, ct as NodeInfoDispatcher, d as ActorCallbackSetters, dt as OutboxErrorHandler, et as CollectionCounter, f as CollectionCallbackSetters, ft as OutboxPermanentFailureHandler, g as Federation, gt as SenderKeyPair, h as Federatable, ht as SendActivityError, i as GetSignedKeyOptions, it as CustomCollectionCursor, j as RetryContext, k as createFederation, l as SendActivityOptions, lt as ObjectAuthorizePredicate, m as CustomCollectionCallbackSetters, mt as WebFingerLinksDispatcher, n as Context, nt as CollectionDispatcher, o as ParseUriResult, ot as InboxErrorHandler, p as ConstructorWithTypeId, pt as SharedInboxKeyDispatcher, q as MessageQueueListenOptions, r as ForwardActivityOptions, rt as CustomCollectionCounter, s as RequestContext, st as InboxListener, t as ActorKeyPair, tt as CollectionCursor, u as SendActivityOptionsForCollection, ut as ObjectDispatcher, v as FederationFetchOptions, vt as buildCollectionSynchronizationHeader, w as ObjectCallbackSetters, x as IdempotencyKeyCallback, y as FederationOptions, yt as digest, z as RouterRouteResult } from "./context-C00pWP8x.js";
|
|
6
6
|
import { a as MemoryKvStore, i as KvStoreSetOptions, n as KvStore, r as KvStoreListEntry, t as KvKey } from "./kv-CxaI4eGo.js";
|
|
7
7
|
import { actorDehydrator, autoIdAssigner, getDefaultActivityTransformers } from "./compat/mod.js";
|
|
8
|
-
import { n as handleWebFinger, t as WebFingerHandlerParameters } from "./mod-
|
|
9
|
-
import { _ as verifyJsonLd, a as createProof, c as verifyProof, d as VerifyJsonLdOptions, f as VerifySignatureOptions, g as signJsonLd, h as detachSignature, i as VerifyProofOptions, l as CreateSignatureOptions, m as createSignature, n as SignObjectOptions, o as signObject, p as attachSignature, r as VerifyObjectOptions, s as verifyObject, t as CreateProofOptions, u as SignJsonLdOptions, v as verifySignature } from "./mod-
|
|
8
|
+
import { n as handleWebFinger, t as WebFingerHandlerParameters } from "./mod-DtRh015i.js";
|
|
9
|
+
import { _ as verifyJsonLd, a as createProof, c as verifyProof, d as VerifyJsonLdOptions, f as VerifySignatureOptions, g as signJsonLd, h as detachSignature, i as VerifyProofOptions, l as CreateSignatureOptions, m as createSignature, n as SignObjectOptions, o as signObject, p as attachSignature, r as VerifyObjectOptions, s as verifyObject, t as CreateProofOptions, u as SignJsonLdOptions, v as verifySignature } from "./mod-CL9Ep0uo.js";
|
|
10
10
|
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./mod-DGP89q0u.js";
|
|
11
11
|
export * from "@fedify/vocab-runtime";
|
|
12
12
|
|
package/dist/mod.js
CHANGED
|
@@ -3,11 +3,11 @@ import { URLPattern } from "urlpattern-polyfill";
|
|
|
3
3
|
import "./chunk-CRNNMoPX.js";
|
|
4
4
|
import { n as autoIdAssigner, r as getDefaultActivityTransformers, t as actorDehydrator } from "./transformers-BGMIq1cs.js";
|
|
5
5
|
import "./compat/mod.js";
|
|
6
|
-
import { c as importJwk, i as exportJwk, n as signRequest, o as fetchKey, r as verifyRequest, s as generateCryptoKeyPair } from "./http-
|
|
7
|
-
import { a as createExponentialBackoffPolicy, c as buildCollectionSynchronizationHeader, d as Router, f as RouterError, i as SendActivityError, l as digest, o as respondWithObject, r as handleWebFinger, s as respondWithObjectIfAcceptable, t as createFederation, u as createFederationBuilder } from "./middleware-
|
|
6
|
+
import { c as importJwk, i as exportJwk, n as signRequest, o as fetchKey, r as verifyRequest, s as generateCryptoKeyPair } from "./http-CrEB4I8A.js";
|
|
7
|
+
import { a as createExponentialBackoffPolicy, c as buildCollectionSynchronizationHeader, d as Router, f as RouterError, i as SendActivityError, l as digest, o as respondWithObject, r as handleWebFinger, s as respondWithObjectIfAcceptable, t as createFederation, u as createFederationBuilder } from "./middleware-CEufJR5k.js";
|
|
8
8
|
import { n as getNodeInfo, r as parseNodeInfo, t as nodeInfoToJson } from "./types-B1_pRFE_.js";
|
|
9
|
-
import { _ as signJsonLd, a as doesActorOwnKey, b as verifySignature, d as createSignature, f as detachSignature, i as verifyProof, l as attachSignature, n as signObject, o as getKeyOwner, r as verifyObject, t as createProof, y as verifyJsonLd } from "./proof-
|
|
10
|
-
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./kv-cache-
|
|
9
|
+
import { _ as signJsonLd, a as doesActorOwnKey, b as verifySignature, d as createSignature, f as detachSignature, i as verifyProof, l as attachSignature, n as signObject, o as getKeyOwner, r as verifyObject, t as createProof, y as verifyJsonLd } from "./proof-DwooE8kV.js";
|
|
10
|
+
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./kv-cache-CDvE8__9.js";
|
|
11
11
|
import { InProcessMessageQueue, MemoryKvStore, ParallelMessageQueue } from "./federation/mod.js";
|
|
12
12
|
import "./nodeinfo/mod.js";
|
|
13
13
|
import "./runtime/mod.js";
|
|
@@ -5,7 +5,7 @@ import { n as createRequestContext } from "../context-Juj6bdHC.mjs";
|
|
|
5
5
|
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
6
6
|
import "../std__assert-DflMZha5.mjs";
|
|
7
7
|
import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
|
|
8
|
-
import { a as createFederation, h as handleNodeInfoJrd, m as handleNodeInfo } from "../middleware-
|
|
8
|
+
import { a as createFederation, h as handleNodeInfoJrd, m as handleNodeInfo } from "../middleware-C849kmHB.mjs";
|
|
9
9
|
import { test } from "@fedify/fixture";
|
|
10
10
|
//#region src/nodeinfo/handler.test.ts
|
|
11
11
|
test("handleNodeInfo()", async () => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { n as version, t as name } from "./deno-
|
|
5
|
-
import { n as fetchActorDocument, s as verifyKeyOwnership, t as exportJwk } from "./key-
|
|
4
|
+
import { n as version, t as name } from "./deno-Dv6PIwH_.mjs";
|
|
5
|
+
import { n as fetchActorDocument, s as verifyKeyOwnership, t as exportJwk } from "./key-ChKDZfvS.mjs";
|
|
6
6
|
import { CryptographicKey, Object as Object$1, isActor } from "@fedify/vocab";
|
|
7
7
|
import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
8
8
|
import { getDocumentLoader } from "@fedify/vocab-runtime";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { n as version, t as name } from "./deno-
|
|
5
|
-
import { o as validateCryptoKey, r as fetchKey } from "./key-
|
|
4
|
+
import { n as version, t as name } from "./deno-Dv6PIwH_.mjs";
|
|
5
|
+
import { o as validateCryptoKey, r as fetchKey } from "./key-ChKDZfvS.mjs";
|
|
6
6
|
import { Activity, DataIntegrityProof, Multikey, getTypeId } from "@fedify/vocab";
|
|
7
7
|
import { SpanStatusCode, trace } from "@opentelemetry/api";
|
|
8
8
|
import { getLogger } from "@logtape/logtape";
|
|
@@ -24,7 +24,10 @@ const logger = getLogger([
|
|
|
24
24
|
* @throws {TypeError} If the private key is invalid or unsupported.
|
|
25
25
|
* @since 0.10.0
|
|
26
26
|
*/
|
|
27
|
-
async function createProof(object, privateKey, keyId,
|
|
27
|
+
async function createProof(object, privateKey, keyId, options = {}) {
|
|
28
|
+
return (await createProofInternal(object, privateKey, keyId, options)).proof;
|
|
29
|
+
}
|
|
30
|
+
async function createProofInternal(object, privateKey, keyId, { contextLoader, context, created } = {}) {
|
|
28
31
|
validateCryptoKey(privateKey, "private");
|
|
29
32
|
if (privateKey.algorithm.name !== "Ed25519") throw new TypeError("Unsupported algorithm: " + privateKey.algorithm.name);
|
|
30
33
|
const compactMsg = await object.clone({ proofs: [] }).toJsonLd({
|
|
@@ -51,13 +54,25 @@ async function createProof(object, privateKey, keyId, { contextLoader, context,
|
|
|
51
54
|
digest.set(new Uint8Array(proofDigest), 0);
|
|
52
55
|
digest.set(new Uint8Array(msgDigest), proofDigest.byteLength);
|
|
53
56
|
const sig = await crypto.subtle.sign("Ed25519", privateKey, digest);
|
|
54
|
-
return
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
return {
|
|
58
|
+
proof: new DataIntegrityProof({
|
|
59
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
60
|
+
verificationMethod: keyId,
|
|
61
|
+
proofPurpose: "assertionMethod",
|
|
62
|
+
created: created ?? Temporal.Now.instant(),
|
|
63
|
+
proofValue: new Uint8Array(sig)
|
|
64
|
+
}),
|
|
65
|
+
jsonLd: compactMsg
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function getJsonLdContextKey(value) {
|
|
69
|
+
const context = typeof value === "object" && value != null && !Array.isArray(value) ? value["@context"] ?? null : null;
|
|
70
|
+
return JSON.stringify(sortJsonKeys(context));
|
|
71
|
+
}
|
|
72
|
+
function sortJsonKeys(value) {
|
|
73
|
+
if (Array.isArray(value)) return value.map(sortJsonKeys);
|
|
74
|
+
if (typeof value !== "object" || value == null) return value;
|
|
75
|
+
return globalThis.Object.fromEntries(globalThis.Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, item]) => [key, sortJsonKeys(item)]));
|
|
61
76
|
}
|
|
62
77
|
/**
|
|
63
78
|
* Signs the given object with the private key and returns the signed object.
|
|
@@ -73,9 +88,18 @@ async function signObject(object, privateKey, keyId, options = {}) {
|
|
|
73
88
|
return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).startActiveSpan("object_integrity_proofs.sign", { attributes: { "activitypub.object.type": getTypeId(object).href } }, async (span) => {
|
|
74
89
|
try {
|
|
75
90
|
if (object.id != null) span.setAttribute("activitypub.object.id", object.id.href);
|
|
91
|
+
const { proof, jsonLd } = await createProofInternal(object, privateKey, keyId, options);
|
|
76
92
|
const existingProofs = [];
|
|
77
|
-
|
|
78
|
-
|
|
93
|
+
let hasProofs = object.proofIds.length > 0;
|
|
94
|
+
if (!hasProofs) for await (const _ of object.getProofs(options)) {
|
|
95
|
+
hasProofs = true;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
if (hasProofs) {
|
|
99
|
+
let sameContext = true;
|
|
100
|
+
if (options.context == null) sameContext = getJsonLdContextKey(await object.toJsonLd({ contextLoader: options.contextLoader })) === getJsonLdContextKey(jsonLd);
|
|
101
|
+
if (sameContext) for await (const existingProof of object.getProofs(options)) existingProofs.push(existingProof);
|
|
102
|
+
}
|
|
79
103
|
if (span.isRecording()) {
|
|
80
104
|
if (proof.cryptosuite != null) span.setAttribute("object_integrity_proofs.cryptosuite", proof.cryptosuite);
|
|
81
105
|
if (proof.verificationMethodId != null) span.setAttribute("object_integrity_proofs.key_id", proof.verificationMethodId.href);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { Temporal } = require("@js-temporal/polyfill");
|
|
2
2
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
3
3
|
const require_chunk = require("./chunk-DDcVe30Y.cjs");
|
|
4
|
-
const require_http = require("./http-
|
|
4
|
+
const require_http = require("./http-D69BMfAn.cjs");
|
|
5
5
|
let _logtape_logtape = require("@logtape/logtape");
|
|
6
6
|
let _fedify_vocab = require("@fedify/vocab");
|
|
7
7
|
let _opentelemetry_api = require("@opentelemetry/api");
|
|
@@ -300,24 +300,110 @@ function assertSafeJsonLd(jsonLd) {
|
|
|
300
300
|
}
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
|
+
const signatureTermDefinition = { "signature": "https://w3id.org/security#signature" };
|
|
304
|
+
const signatureDefiningContexts = new Set(["https://w3id.org/identity/v1", "https://w3id.org/security/v1"]);
|
|
305
|
+
const signatureFreeContexts = getSignatureFreeContexts();
|
|
306
|
+
function getSignatureFreeContexts() {
|
|
307
|
+
const urls = /* @__PURE__ */ new Set();
|
|
308
|
+
for (const [url, document] of globalThis.Object.entries(_fedify_vocab_runtime.preloadedContexts)) {
|
|
309
|
+
if (typeof document !== "object" || document == null) continue;
|
|
310
|
+
const context = document["@context"];
|
|
311
|
+
if (typeof context !== "object" || context == null || Array.isArray(context)) continue;
|
|
312
|
+
const record = context;
|
|
313
|
+
if (!globalThis.Object.prototype.hasOwnProperty.call(record, "signature")) urls.add(url);
|
|
314
|
+
}
|
|
315
|
+
return urls;
|
|
316
|
+
}
|
|
317
|
+
function getContextEntryEffect(entry) {
|
|
318
|
+
if (entry == null) return "resets";
|
|
319
|
+
if (typeof entry === "string") {
|
|
320
|
+
if (signatureDefiningContexts.has(entry)) return "defines";
|
|
321
|
+
if (signatureFreeContexts.has(entry)) return "absent";
|
|
322
|
+
return "unknown";
|
|
323
|
+
}
|
|
324
|
+
if (typeof entry !== "object") return "absent";
|
|
325
|
+
const record = entry;
|
|
326
|
+
if (globalThis.Object.prototype.hasOwnProperty.call(record, "signature")) {
|
|
327
|
+
const definition = record["signature"];
|
|
328
|
+
const contextProtected = record["@protected"] === true;
|
|
329
|
+
const imported = globalThis.Object.prototype.hasOwnProperty.call(record, "@import");
|
|
330
|
+
if (definition == null) {
|
|
331
|
+
if (contextProtected) return "defines";
|
|
332
|
+
return imported ? "unknown" : "resets";
|
|
333
|
+
}
|
|
334
|
+
if (typeof definition === "object" && !Array.isArray(definition)) {
|
|
335
|
+
const term = definition;
|
|
336
|
+
const protectedTerm = contextProtected || term["@protected"] === true;
|
|
337
|
+
if (globalThis.Object.prototype.hasOwnProperty.call(term, "@id") && term["@id"] == null) {
|
|
338
|
+
if (protectedTerm) return "defines";
|
|
339
|
+
return imported ? "unknown" : "resets";
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return "defines";
|
|
343
|
+
}
|
|
344
|
+
if (globalThis.Object.prototype.hasOwnProperty.call(record, "@import")) return "unknown";
|
|
345
|
+
return "absent";
|
|
346
|
+
}
|
|
347
|
+
function getSignatureTermState(context) {
|
|
348
|
+
if (context == null) return "absent";
|
|
349
|
+
if (!Array.isArray(context)) {
|
|
350
|
+
const effect = getContextEntryEffect(context);
|
|
351
|
+
return effect === "defines" ? "defined" : effect === "unknown" ? "unknown" : "absent";
|
|
352
|
+
}
|
|
353
|
+
let state = "absent";
|
|
354
|
+
for (const entry of context) {
|
|
355
|
+
const effect = getContextEntryEffect(entry);
|
|
356
|
+
if (effect === "defines") state = "defined";
|
|
357
|
+
else if (effect === "resets") state = "absent";
|
|
358
|
+
else if (effect === "unknown" && state !== "defined") state = "unknown";
|
|
359
|
+
}
|
|
360
|
+
return state;
|
|
361
|
+
}
|
|
362
|
+
function prepareSignatureDocument(jsonLd) {
|
|
363
|
+
if (typeof jsonLd !== "object" || jsonLd == null || Array.isArray(jsonLd)) return jsonLd;
|
|
364
|
+
const document = jsonLd;
|
|
365
|
+
if (document["proof"] != null) return { ...document };
|
|
366
|
+
const context = document["@context"];
|
|
367
|
+
if (getSignatureTermState(context) !== "absent") return { ...document };
|
|
368
|
+
const definition = { ...signatureTermDefinition };
|
|
369
|
+
return {
|
|
370
|
+
...document,
|
|
371
|
+
"@context": context == null ? [definition] : Array.isArray(context) ? [...context, definition] : [context, definition]
|
|
372
|
+
};
|
|
373
|
+
}
|
|
303
374
|
/**
|
|
304
375
|
* Attaches a LD signature to the given JSON-LD document.
|
|
376
|
+
*
|
|
377
|
+
* When the document's context does not already define the `signature`
|
|
378
|
+
* property, the returned document adds a minimal inline context for it.
|
|
379
|
+
* Without that definition, expanding the attached signature would produce a
|
|
380
|
+
* blank node predicate, which is not valid RDF. Documents that already carry
|
|
381
|
+
* a `proof` are left unchanged, since a new context definition would invalidate
|
|
382
|
+
* the proof. Documents whose context includes an unrecognized remote context
|
|
383
|
+
* are also left unchanged, since that context may already define `signature`.
|
|
305
384
|
* @param jsonLd The JSON-LD document to attach the signature to. It is not
|
|
306
385
|
* modified.
|
|
307
386
|
* @param signature The signature to attach.
|
|
308
387
|
* @returns The JSON-LD document with the attached signature.
|
|
309
388
|
* @throws {TypeError} If the input document is not a valid JSON-LD document.
|
|
389
|
+
* Top-level arrays are rejected, since a Linked Data
|
|
390
|
+
* Signature is attached to a single node.
|
|
310
391
|
* @since 1.0.0
|
|
311
392
|
*/
|
|
312
393
|
function attachSignature(jsonLd, signature) {
|
|
313
|
-
if (typeof jsonLd !== "object" || jsonLd == null) throw new TypeError("Failed to attach signature; invalid JSON-LD document.");
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
};
|
|
394
|
+
if (typeof jsonLd !== "object" || jsonLd == null || Array.isArray(jsonLd)) throw new TypeError("Failed to attach signature; invalid JSON-LD document.");
|
|
395
|
+
const output = prepareSignatureDocument(jsonLd);
|
|
396
|
+
output.signature = signature;
|
|
397
|
+
return output;
|
|
318
398
|
}
|
|
319
399
|
/**
|
|
320
400
|
* Creates a LD signature for the given JSON-LD document.
|
|
401
|
+
*
|
|
402
|
+
* If the document's context does not define the `signature` property, the
|
|
403
|
+
* signature is computed over the document with a minimal inline definition
|
|
404
|
+
* added. Use {@link attachSignature} to attach the signature to that exact
|
|
405
|
+
* document. Documents that already carry a `proof`, or whose context includes
|
|
406
|
+
* an unrecognized remote context, are hashed unchanged.
|
|
321
407
|
* @param jsonLd The JSON-LD document to sign.
|
|
322
408
|
* @param privateKey The private key to sign the document.
|
|
323
409
|
* @param keyId The ID of the public key that corresponds to the private key.
|
|
@@ -331,14 +417,17 @@ async function createSignature(jsonLd, privateKey, keyId, { contextLoader, creat
|
|
|
331
417
|
require_http.validateCryptoKey(privateKey, "private");
|
|
332
418
|
if (privateKey.algorithm.name !== "RSASSA-PKCS1-v1_5") throw new TypeError("Unsupported algorithm: " + privateKey.algorithm.name);
|
|
333
419
|
const options = {
|
|
334
|
-
"@context": "https://w3id.org/identity/v1",
|
|
335
420
|
creator: keyId.href,
|
|
336
421
|
created: created?.toString() ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
337
422
|
};
|
|
338
|
-
const message = await hashJsonLd(
|
|
423
|
+
const message = await hashJsonLd({
|
|
424
|
+
"@context": "https://w3id.org/identity/v1",
|
|
425
|
+
...options
|
|
426
|
+
}, contextLoader) + await hashJsonLd(prepareSignatureDocument(jsonLd), contextLoader);
|
|
339
427
|
const messageBytes = new TextEncoder().encode(message);
|
|
340
428
|
const signature = await crypto.subtle.sign("RSASSA-PKCS1-v1_5", privateKey, messageBytes);
|
|
341
429
|
return {
|
|
430
|
+
"@context": "https://w3id.org/security/v1",
|
|
342
431
|
...options,
|
|
343
432
|
type: "RsaSignature2017",
|
|
344
433
|
signatureValue: (0, byte_encodings_base64.encodeBase64)(signature)
|
|
@@ -730,7 +819,10 @@ const logger = (0, _logtape_logtape.getLogger)([
|
|
|
730
819
|
* @throws {TypeError} If the private key is invalid or unsupported.
|
|
731
820
|
* @since 0.10.0
|
|
732
821
|
*/
|
|
733
|
-
async function createProof(object, privateKey, keyId,
|
|
822
|
+
async function createProof(object, privateKey, keyId, options = {}) {
|
|
823
|
+
return (await createProofInternal(object, privateKey, keyId, options)).proof;
|
|
824
|
+
}
|
|
825
|
+
async function createProofInternal(object, privateKey, keyId, { contextLoader, context, created } = {}) {
|
|
734
826
|
require_http.validateCryptoKey(privateKey, "private");
|
|
735
827
|
if (privateKey.algorithm.name !== "Ed25519") throw new TypeError("Unsupported algorithm: " + privateKey.algorithm.name);
|
|
736
828
|
const compactMsg = await object.clone({ proofs: [] }).toJsonLd({
|
|
@@ -757,13 +849,25 @@ async function createProof(object, privateKey, keyId, { contextLoader, context,
|
|
|
757
849
|
digest.set(new Uint8Array(proofDigest), 0);
|
|
758
850
|
digest.set(new Uint8Array(msgDigest), proofDigest.byteLength);
|
|
759
851
|
const sig = await crypto.subtle.sign("Ed25519", privateKey, digest);
|
|
760
|
-
return
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
852
|
+
return {
|
|
853
|
+
proof: new _fedify_vocab.DataIntegrityProof({
|
|
854
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
855
|
+
verificationMethod: keyId,
|
|
856
|
+
proofPurpose: "assertionMethod",
|
|
857
|
+
created: created ?? Temporal.Now.instant(),
|
|
858
|
+
proofValue: new Uint8Array(sig)
|
|
859
|
+
}),
|
|
860
|
+
jsonLd: compactMsg
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
function getJsonLdContextKey(value) {
|
|
864
|
+
const context = typeof value === "object" && value != null && !Array.isArray(value) ? value["@context"] ?? null : null;
|
|
865
|
+
return JSON.stringify(sortJsonKeys(context));
|
|
866
|
+
}
|
|
867
|
+
function sortJsonKeys(value) {
|
|
868
|
+
if (Array.isArray(value)) return value.map(sortJsonKeys);
|
|
869
|
+
if (typeof value !== "object" || value == null) return value;
|
|
870
|
+
return globalThis.Object.fromEntries(globalThis.Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, item]) => [key, sortJsonKeys(item)]));
|
|
767
871
|
}
|
|
768
872
|
/**
|
|
769
873
|
* Signs the given object with the private key and returns the signed object.
|
|
@@ -779,9 +883,18 @@ async function signObject(object, privateKey, keyId, options = {}) {
|
|
|
779
883
|
return await (options.tracerProvider ?? _opentelemetry_api.trace.getTracerProvider()).getTracer(require_http.name, require_http.version).startActiveSpan("object_integrity_proofs.sign", { attributes: { "activitypub.object.type": (0, _fedify_vocab.getTypeId)(object).href } }, async (span) => {
|
|
780
884
|
try {
|
|
781
885
|
if (object.id != null) span.setAttribute("activitypub.object.id", object.id.href);
|
|
886
|
+
const { proof, jsonLd } = await createProofInternal(object, privateKey, keyId, options);
|
|
782
887
|
const existingProofs = [];
|
|
783
|
-
|
|
784
|
-
|
|
888
|
+
let hasProofs = object.proofIds.length > 0;
|
|
889
|
+
if (!hasProofs) for await (const _ of object.getProofs(options)) {
|
|
890
|
+
hasProofs = true;
|
|
891
|
+
break;
|
|
892
|
+
}
|
|
893
|
+
if (hasProofs) {
|
|
894
|
+
let sameContext = true;
|
|
895
|
+
if (options.context == null) sameContext = getJsonLdContextKey(await object.toJsonLd({ contextLoader: options.contextLoader })) === getJsonLdContextKey(jsonLd);
|
|
896
|
+
if (sameContext) for await (const existingProof of object.getProofs(options)) existingProofs.push(existingProof);
|
|
897
|
+
}
|
|
785
898
|
if (span.isRecording()) {
|
|
786
899
|
if (proof.cryptosuite != null) span.setAttribute("object_integrity_proofs.cryptosuite", proof.cryptosuite);
|
|
787
900
|
if (proof.verificationMethodId != null) span.setAttribute("object_integrity_proofs.key_id", proof.verificationMethodId.href);
|