@powerhousedao/reactor 6.0.0-dev.36 → 6.0.0-dev.37
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/src/cache/kysely-operation-index.js +1 -1
- package/dist/src/cache/kysely-operation-index.js.map +1 -1
- package/dist/src/core/reactor-builder.d.ts.map +1 -1
- package/dist/src/core/reactor-builder.js +1 -3
- package/dist/src/core/reactor-builder.js.map +1 -1
- package/dist/src/executor/document-action-handler.d.ts +37 -0
- package/dist/src/executor/document-action-handler.d.ts.map +1 -0
- package/dist/src/executor/document-action-handler.js +349 -0
- package/dist/src/executor/document-action-handler.js.map +1 -0
- package/dist/src/executor/signature-verifier.d.ts +9 -0
- package/dist/src/executor/signature-verifier.d.ts.map +1 -0
- package/dist/src/executor/signature-verifier.js +70 -0
- package/dist/src/executor/signature-verifier.js.map +1 -0
- package/dist/src/executor/simple-job-executor.d.ts +3 -39
- package/dist/src/executor/simple-job-executor.d.ts.map +1 -1
- package/dist/src/executor/simple-job-executor.js +32 -510
- package/dist/src/executor/simple-job-executor.js.map +1 -1
- package/dist/src/executor/util.d.ts +11 -1
- package/dist/src/executor/util.d.ts.map +1 -1
- package/dist/src/executor/util.js +47 -1
- package/dist/src/executor/util.js.map +1 -1
- package/dist/src/sync/sync-manager.d.ts.map +1 -1
- package/dist/src/sync/sync-manager.js +11 -11
- package/dist/src/sync/sync-manager.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { deriveOperationId } from "document-model/core";
|
|
2
|
+
import { InvalidSignatureError } from "../shared/errors.js";
|
|
3
|
+
export class SignatureVerifier {
|
|
4
|
+
verifier;
|
|
5
|
+
constructor(verifier) {
|
|
6
|
+
this.verifier = verifier;
|
|
7
|
+
}
|
|
8
|
+
async verifyActions(documentId, branch, actions) {
|
|
9
|
+
if (!this.verifier) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
for (const action of actions) {
|
|
13
|
+
const signer = action.context?.signer;
|
|
14
|
+
if (!signer) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (signer.signatures.length === 0) {
|
|
18
|
+
throw new InvalidSignatureError(documentId, `Action ${action.id} has signer but no signatures`);
|
|
19
|
+
}
|
|
20
|
+
const publicKey = signer.app.key;
|
|
21
|
+
let isValid = false;
|
|
22
|
+
try {
|
|
23
|
+
const tempOperation = {
|
|
24
|
+
id: deriveOperationId(documentId, action.scope, branch, action.id),
|
|
25
|
+
index: 0,
|
|
26
|
+
timestampUtcMs: action.timestampUtcMs || new Date().toISOString(),
|
|
27
|
+
hash: "",
|
|
28
|
+
skip: 0,
|
|
29
|
+
action: action,
|
|
30
|
+
};
|
|
31
|
+
isValid = await this.verifier(tempOperation, publicKey);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
35
|
+
throw new InvalidSignatureError(documentId, `Action ${action.id} verification failed: ${errorMessage}`);
|
|
36
|
+
}
|
|
37
|
+
if (!isValid) {
|
|
38
|
+
throw new InvalidSignatureError(documentId, `Action ${action.id} signature verification returned false`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async verifyOperations(documentId, operations) {
|
|
43
|
+
if (!this.verifier) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
for (let i = 0; i < operations.length; i++) {
|
|
47
|
+
const operation = operations[i];
|
|
48
|
+
const signer = operation.action.context?.signer;
|
|
49
|
+
if (!signer) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (signer.signatures.length === 0) {
|
|
53
|
+
throw new InvalidSignatureError(documentId, `Operation ${operation.id} at index ${operation.index} has signer but no signatures`);
|
|
54
|
+
}
|
|
55
|
+
const publicKey = signer.app.key;
|
|
56
|
+
let isValid = false;
|
|
57
|
+
try {
|
|
58
|
+
isValid = await this.verifier(operation, publicKey);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
62
|
+
throw new InvalidSignatureError(documentId, `Operation ${operation.id} at index ${operation.index} verification failed: ${errorMessage}`);
|
|
63
|
+
}
|
|
64
|
+
if (!isValid) {
|
|
65
|
+
throw new InvalidSignatureError(documentId, `Operation ${operation.id} at index ${operation.index} signature verification returned false`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=signature-verifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature-verifier.js","sourceRoot":"","sources":["../../../src/executor/signature-verifier.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAG5D,MAAM,OAAO,iBAAiB;IACR;IAApB,YAAoB,QAAuC;QAAvC,aAAQ,GAAR,QAAQ,CAA+B;IAAG,CAAC;IAE/D,KAAK,CAAC,aAAa,CACjB,UAAkB,EAClB,MAAc,EACd,OAAiB;QAEjB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,OAAO;QACT,CAAC;QAED,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC;YAEtC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,SAAS;YACX,CAAC;YAED,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACnC,MAAM,IAAI,qBAAqB,CAC7B,UAAU,EACV,UAAU,MAAM,CAAC,EAAE,+BAA+B,CACnD,CAAC;YACJ,CAAC;YAED,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;YACjC,IAAI,OAAO,GAAG,KAAK,CAAC;YAEp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MAAM,EAAE,CAAC;gBACZ,SAAS;YACX,CAAC;YAED,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACnC,MAAM,IAAI,qBAAqB,CAC7B,UAAU,EACV,aAAa,SAAS,CAAC,EAAE,aAAa,SAAS,CAAC,KAAK,+BAA+B,CACrF,CAAC;YACJ,CAAC;YAED,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;YACjC,IAAI,OAAO,GAAG,KAAK,CAAC;YAEpB,IAAI,CAAC;gBACH,OAAO,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;YACtD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,YAAY,GAChB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACzD,MAAM,IAAI,qBAAqB,CAC7B,UAAU,EACV,aAAa,SAAS,CAAC,EAAE,aAAa,SAAS,CAAC,KAAK,yBAAyB,YAAY,EAAE,CAC7F,CAAC;YACJ,CAAC;YAED,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,MAAM,IAAI,qBAAqB,CAC7B,UAAU,EACV,aAAa,SAAS,CAAC,EAAE,aAAa,SAAS,CAAC,KAAK,wCAAwC,CAC9F,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -22,9 +22,10 @@ export declare class SimpleJobExecutor implements IJobExecutor {
|
|
|
22
22
|
private operationIndex;
|
|
23
23
|
private documentMetaCache;
|
|
24
24
|
private collectionMembershipCache;
|
|
25
|
-
private signatureVerifier?;
|
|
26
25
|
private config;
|
|
27
|
-
|
|
26
|
+
private signatureVerifierModule;
|
|
27
|
+
private documentActionHandler;
|
|
28
|
+
constructor(logger: ILogger, registry: IDocumentModelRegistry, operationStore: IOperationStore, eventBus: IEventBus, writeCache: IWriteCache, operationIndex: IOperationIndex, documentMetaCache: IDocumentMetaCache, collectionMembershipCache: ICollectionMembershipCache, config: JobExecutorConfig, signatureVerifier?: SignatureVerificationHandler);
|
|
28
29
|
/**
|
|
29
30
|
* Execute a single job by applying all its actions through the appropriate reducers.
|
|
30
31
|
* Actions are processed sequentially in order.
|
|
@@ -32,45 +33,8 @@ export declare class SimpleJobExecutor implements IJobExecutor {
|
|
|
32
33
|
executeJob(job: Job): Promise<JobResult>;
|
|
33
34
|
private getCollectionMembershipsForOperations;
|
|
34
35
|
private processActions;
|
|
35
|
-
/**
|
|
36
|
-
* Execute a document scope action (CREATE_DOCUMENT, DELETE_DOCUMENT, UPGRADE_DOCUMENT,
|
|
37
|
-
* ADD_RELATIONSHIP, REMOVE_RELATIONSHIP) by dispatching to the appropriate handler.
|
|
38
|
-
*/
|
|
39
|
-
private executeDocumentAction;
|
|
40
|
-
/**
|
|
41
|
-
* Execute a CREATE_DOCUMENT system action.
|
|
42
|
-
* This creates a new document in storage along with its initial operation.
|
|
43
|
-
* For a new document, the operation index is always 0.
|
|
44
|
-
*/
|
|
45
|
-
private executeCreateDocumentAction;
|
|
46
|
-
/**
|
|
47
|
-
* Execute a DELETE_DOCUMENT system action.
|
|
48
|
-
* This deletes a document from legacy storage and writes the operation to IOperationStore.
|
|
49
|
-
* The operation index is determined from the document's current operation count.
|
|
50
|
-
*/
|
|
51
|
-
private executeDeleteDocumentAction;
|
|
52
|
-
/**
|
|
53
|
-
* Execute an UPGRADE_DOCUMENT system action.
|
|
54
|
-
* Handles initial upgrades (version 0 to N), same-version no-ops, and multi-step upgrade chains.
|
|
55
|
-
* The operation index is determined from the document's current operation count.
|
|
56
|
-
*/
|
|
57
|
-
private executeUpgradeDocumentAction;
|
|
58
|
-
private executeAddRelationshipAction;
|
|
59
|
-
private executeRemoveRelationshipAction;
|
|
60
|
-
/**
|
|
61
|
-
* Execute a regular document action by applying it through the document model reducer.
|
|
62
|
-
* If sourceOperation is provided (for load jobs), its id and timestamp are preserved.
|
|
63
|
-
*/
|
|
64
36
|
private executeRegularAction;
|
|
65
|
-
private createOperation;
|
|
66
37
|
private executeLoadJob;
|
|
67
|
-
private writeOperationToStore;
|
|
68
|
-
private updateDocumentRevision;
|
|
69
|
-
private writeCacheState;
|
|
70
|
-
private buildSuccessResult;
|
|
71
|
-
private buildErrorResult;
|
|
72
|
-
private verifyOperationSignatures;
|
|
73
|
-
private verifyActionSignatures;
|
|
74
38
|
private accumulateResultOrReturnError;
|
|
75
39
|
}
|
|
76
40
|
//# sourceMappingURL=simple-job-executor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple-job-executor.d.ts","sourceRoot":"","sources":["../../../src/executor/simple-job-executor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"simple-job-executor.d.ts","sourceRoot":"","sources":["../../../src/executor/simple-job-executor.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AAC1F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,KAAK,EACV,eAAe,EAEhB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAExE,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,KAAK,EACV,eAAe,EAEhB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,KA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