@zktx.io/sui-mcp 0.5.0
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/LICENSE +21 -0
- package/LICENSES/@mysten-bcs-2.0.5-Apache-2.0.txt +205 -0
- package/LICENSES/@mysten-sui-2.17.0-Apache-2.0.txt +201 -0
- package/LICENSES/@mysten-utils-0.3.3-Apache-2.0.txt +205 -0
- package/LICENSES/fancy-canvas-2.1.0-MIT.txt +7 -0
- package/LICENSES/lightweight-charts-5.2.0-NOTICE.txt +2 -0
- package/README.md +288 -0
- package/dist/adapters/adapterLifecycleValidators.js +5 -0
- package/dist/adapters/adapterPromptSurfaces.js +60 -0
- package/dist/adapters/deepbook/deepbookHumanReviewProducer.js +178 -0
- package/dist/adapters/deepbook/deepbookQuotePolicy.js +112 -0
- package/dist/adapters/deepbook/deepbookReviewEvidence.js +507 -0
- package/dist/adapters/deepbook/deepbookReviewLifecycle.js +85 -0
- package/dist/adapters/deepbook/deepbookSwapIntent.js +79 -0
- package/dist/adapters/deepbook/deepbookTransactionMaterialProducer.js +254 -0
- package/dist/adapters/intentPlanFactories.js +51 -0
- package/dist/adapters/reviewAdapters.js +47 -0
- package/dist/core/action/adapterLifecycleValidation.js +12 -0
- package/dist/core/action/contractNameRegistry.js +151 -0
- package/dist/core/action/forbiddenFields.js +43 -0
- package/dist/core/action/humanReadableReviewEvidence.js +193 -0
- package/dist/core/action/humanReadableReviewProjectionVerifier.js +29 -0
- package/dist/core/action/ptbVisualizationProducer.js +71 -0
- package/dist/core/action/receiptPtbGraph.js +29 -0
- package/dist/core/action/reviewCheckResults.js +6 -0
- package/dist/core/action/reviewStateValidation.js +11 -0
- package/dist/core/action/reviewTimeSimulationEvidence.js +470 -0
- package/dist/core/action/schemas.js +491 -0
- package/dist/core/action/signableAdapterContract.js +998 -0
- package/dist/core/action/suiChainReceiptEvidence.js +106 -0
- package/dist/core/action/suiChainReceiptMapping.js +107 -0
- package/dist/core/action/suiChainReceiptReader.js +211 -0
- package/dist/core/action/suiChainReceiptVerifier.js +178 -0
- package/dist/core/action/swapHumanReadableReviewProjection.js +130 -0
- package/dist/core/action/swapQuotePolicyEvidence.js +271 -0
- package/dist/core/action/transactionFunding.js +244 -0
- package/dist/core/action/transactionObjectOwnershipEvidence.js +256 -0
- package/dist/core/action/transactionObjectOwnershipProducer.js +323 -0
- package/dist/core/action/types.js +33 -0
- package/dist/core/action/walletReviewContractAssembler.js +286 -0
- package/dist/core/activity/accountAssetTimeline.js +157 -0
- package/dist/core/activity/accountAssetTimelineUsdcReferences.js +120 -0
- package/dist/core/activity/activityStore.js +16 -0
- package/dist/core/activity/externalActivityCoverage.js +76 -0
- package/dist/core/activity/externalActivityTransactionStream.js +82 -0
- package/dist/core/activity/localDataService.js +296 -0
- package/dist/core/activity/localDataTypes.js +11 -0
- package/dist/core/activity/localDataValidation.js +439 -0
- package/dist/core/activity/schemaVersion.js +2 -0
- package/dist/core/activity/sqliteActivityStore.js +1068 -0
- package/dist/core/activity/sqliteActivityStoreRows.js +389 -0
- package/dist/core/activity/sqliteActivityStoreSchema.js +367 -0
- package/dist/core/activity/sqliteActivityStoreTypes.js +5 -0
- package/dist/core/activity/suiFunctionTarget.js +43 -0
- package/dist/core/activity/transactionActivityAccountEffects.js +186 -0
- package/dist/core/activity/transactionActivityAnalysis.js +295 -0
- package/dist/core/activity/transactionActivityClassifier.js +306 -0
- package/dist/core/activity/transactionActivityDetails.js +229 -0
- package/dist/core/activity/transactionActivityProtocolRules.js +218 -0
- package/dist/core/activity/transactionActivityScanPolicy.js +170 -0
- package/dist/core/activity/transactionActivityService.js +379 -0
- package/dist/core/activity/transactionActivityTypes.js +18 -0
- package/dist/core/eventlog/sink.js +35 -0
- package/dist/core/evidence/settlementFamilies.js +85 -0
- package/dist/core/evidence/userAnswerUse.js +1 -0
- package/dist/core/numeric/rawU64.js +63 -0
- package/dist/core/preferences/preferencesStore.js +26 -0
- package/dist/core/preferences/sqlitePreferencesRepository.js +136 -0
- package/dist/core/proposal/externalProposalReview.js +347 -0
- package/dist/core/proposal/schemas.js +208 -0
- package/dist/core/proposal/types.js +35 -0
- package/dist/core/read/amounts.js +14 -0
- package/dist/core/read/coinMetadata.js +60 -0
- package/dist/core/read/deepbookOfficialIndexerSource.js +373 -0
- package/dist/core/read/deepbookRawQuoteClient.js +86 -0
- package/dist/core/read/deepbookReadHelpers.js +321 -0
- package/dist/core/read/deepbookRegistry.js +157 -0
- package/dist/core/read/deepbookSourceOwners.js +159 -0
- package/dist/core/read/deepbookUsdcChartService.js +342 -0
- package/dist/core/read/intentEvidenceResponseFormatting.js +228 -0
- package/dist/core/read/readCardInputs.js +19 -0
- package/dist/core/read/readCardResult.js +40 -0
- package/dist/core/read/readResponseGuidance.js +402 -0
- package/dist/core/read/readService.js +1639 -0
- package/dist/core/read/readServiceTypes.js +88 -0
- package/dist/core/read/settlementParityFormatting.js +82 -0
- package/dist/core/read/walletReadHelpers.js +99 -0
- package/dist/core/review/reviewChecks.js +45 -0
- package/dist/core/review/reviewComputation.js +38 -0
- package/dist/core/review/reviewComputationResult.js +87 -0
- package/dist/core/session/cardSession.js +31 -0
- package/dist/core/session/cardSessionStore.js +204 -0
- package/dist/core/session/keyedRecordStore.js +18 -0
- package/dist/core/session/liveReviewSessionContract.js +3 -0
- package/dist/core/session/localSession.js +31 -0
- package/dist/core/session/privateReviewArtifacts.js +75 -0
- package/dist/core/session/reviewValidity.js +49 -0
- package/dist/core/session/sessionErrors.js +9 -0
- package/dist/core/session/sessionRecordStore.js +40 -0
- package/dist/core/session/sessionStore.js +655 -0
- package/dist/core/session/settingsSession.js +1 -0
- package/dist/core/session/settingsSessions.js +45 -0
- package/dist/core/session/sqliteCardStore.js +88 -0
- package/dist/core/session/sqliteSessionStore.js +213 -0
- package/dist/core/session/sqliteTransactionMaterialStore.js +64 -0
- package/dist/core/session/sqliteWalletWorkflowStore.js +821 -0
- package/dist/core/session/status.js +60 -0
- package/dist/core/session/transactionMaterialStore.js +221 -0
- package/dist/core/session/transactionRequest.js +72 -0
- package/dist/core/session/wait.js +79 -0
- package/dist/core/session/walletConnection.js +92 -0
- package/dist/core/session/walletRuntime.js +38 -0
- package/dist/core/session/walletWorkflow.js +608 -0
- package/dist/core/session/workflowState.js +80 -0
- package/dist/core/session/workflowView.js +150 -0
- package/dist/core/suiAddress.js +18 -0
- package/dist/core/suiEndpoint.js +72 -0
- package/dist/mcp/activeAccountResponse.js +24 -0
- package/dist/mcp/prompts.js +146 -0
- package/dist/mcp/registerTool.js +19 -0
- package/dist/mcp/resources.js +72 -0
- package/dist/mcp/responseGuidance.js +326 -0
- package/dist/mcp/result.js +17 -0
- package/dist/mcp/schemas.js +11 -0
- package/dist/mcp/server.js +32 -0
- package/dist/mcp/serverInfo.js +131 -0
- package/dist/mcp/toolErrors.js +118 -0
- package/dist/mcp/toolNames.js +58 -0
- package/dist/mcp/tools/account/index.js +44 -0
- package/dist/mcp/tools/action/prepareSuiActionReview.js +126 -0
- package/dist/mcp/tools/read/commonSchemas.js +43 -0
- package/dist/mcp/tools/read/deepbookReadTools.js +686 -0
- package/dist/mcp/tools/read/index.js +14 -0
- package/dist/mcp/tools/read/readToolHelpers.js +97 -0
- package/dist/mcp/tools/read/reviewActivityTools.js +179 -0
- package/dist/mcp/tools/read/serverStatusTools.js +100 -0
- package/dist/mcp/tools/read/transactionActivityOutput.js +371 -0
- package/dist/mcp/tools/read/transactionActivityTools.js +858 -0
- package/dist/mcp/tools/read/walletReadTools.js +734 -0
- package/dist/mcp/tools/session/executionResultTools.js +44 -0
- package/dist/mcp/tools/session/index.js +8 -0
- package/dist/mcp/tools/session/shared.js +36 -0
- package/dist/mcp/tools/session/statusTools.js +69 -0
- package/dist/mcp/tools/session/walletConnectionTools.js +69 -0
- package/dist/mcp/tools/settings/index.js +66 -0
- package/dist/mcp-app/account.html +3133 -0
- package/dist/mcp-app/account.notices.txt +973 -0
- package/dist/mcp-app/chart.html +3354 -0
- package/dist/mcp-app/chart.notices.txt +1194 -0
- package/dist/mcp-app/connect.html +3179 -0
- package/dist/mcp-app/connect.notices.txt +1012 -0
- package/dist/mcp-app/receipt.html +8430 -0
- package/dist/mcp-app/receipt.notices.txt +3549 -0
- package/dist/mcp-app/review.html +8430 -0
- package/dist/mcp-app/review.notices.txt +3549 -0
- package/dist/mcp-ui/contracts.js +31 -0
- package/dist/mcp-ui/readCards.js +28 -0
- package/dist/mcp-ui/tools.js +134 -0
- package/dist/review-app/brand-dark.svg +1 -0
- package/dist/review-app/brand-light.svg +1 -0
- package/dist/review-app/favicon.svg +1 -0
- package/dist/review-app/settings.css +1 -0
- package/dist/review-app/settings.js +1 -0
- package/dist/review-app/ui.css +809 -0
- package/dist/review-server/assets.js +48 -0
- package/dist/review-server/html.js +45 -0
- package/dist/review-server/http.js +47 -0
- package/dist/review-server/middleware/hostOrigin.js +48 -0
- package/dist/review-server/middleware/reviewToken.js +7 -0
- package/dist/review-server/reviewServerPolicy.js +1 -0
- package/dist/review-server/server.js +72 -0
- package/dist/review-server/settingsApi.js +158 -0
- package/dist/runtime/application.js +203 -0
- package/dist/runtime/config.js +97 -0
- package/dist/runtime/localSettingsService.js +198 -0
- package/dist/runtime/logger.js +66 -0
- package/dist/runtime/reviewDependencies.js +58 -0
- package/dist/runtime/reviewServerAcquire.js +93 -0
- package/dist/runtime/runtimeTermination.js +60 -0
- package/dist/runtime/shared/authenticatedFetch.js +127 -0
- package/dist/runtime/shared/control.js +93 -0
- package/dist/runtime/shared/dataAccess.js +66 -0
- package/dist/runtime/shared/mcpHttp.js +84 -0
- package/dist/runtime/shared/ownerLease.js +50 -0
- package/dist/runtime/shared/server.js +98 -0
- package/dist/runtime/shared/stdio.js +113 -0
- package/dist/runtime/smokeMainnetRead.js +391 -0
- package/dist/runtime/smokeMainnetReadAssertions.js +306 -0
- package/dist/runtime/smokeReview.js +40 -0
- package/dist/runtime/start.js +90 -0
- package/dist/runtime/suiEndpoint.js +97 -0
- package/dist/runtime/suiTransactionGraphqlMapping.js +200 -0
- package/dist/runtime/suiTransactionGraphqlQueries.js +231 -0
- package/dist/runtime/suiTransactionGraphqlSource.js +148 -0
- package/dist/runtime/walletConnectConfig.js +3 -0
- package/dist/runtime/walletConnectStorage.js +99 -0
- package/dist/runtime/walletConnectTransport.js +128 -0
- package/dist/runtime/walletSdkChild.js +3 -0
- package/dist/runtime/walletSdkChildRuntime.js +160 -0
- package/dist/runtime/walletSdkIpc.js +26 -0
- package/dist/runtime/walletSdkProcess.js +358 -0
- package/docs/AGENT_BEHAVIOR.md +524 -0
- package/docs/AGENT_DEVELOPMENT_POLICY.md +815 -0
- package/docs/FRONTEND_POLICY.md +534 -0
- package/docs/LOCAL_DB_ARCHITECTURE.md +381 -0
- package/docs/MCP_SETUP.md +742 -0
- package/docs/MCP_TOOLS.md +1318 -0
- package/docs/SDK_API.md +206 -0
- package/docs/SIGNABLE_ADAPTER_CONTRACT.md +396 -0
- package/docs/TRANSACTION_ACTIVITY_LOG.md +194 -0
- package/docs/UTILITY_INDEX.md +275 -0
- package/docs/WALLET_CONNECTION.md +238 -0
- package/docs/golden-scenarios/BEHAVIOR_MATRIX.md +166 -0
- package/docs/golden-scenarios/INTENT_EVIDENCE_GOLDEN_ANSWERS.md +161 -0
- package/docs/golden-scenarios/INTENT_EVIDENCE_MATRIX.md +259 -0
- package/package.json +79 -0
- package/protocols/deepbook-margin.md +15 -0
- package/protocols/deepbook-v3.md +24 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class InMemoryKeyedRecordStore {
|
|
2
|
+
records = new Map();
|
|
3
|
+
get(id) {
|
|
4
|
+
return this.records.get(id);
|
|
5
|
+
}
|
|
6
|
+
set(id, value) {
|
|
7
|
+
this.records.set(id, value);
|
|
8
|
+
}
|
|
9
|
+
delete(id) {
|
|
10
|
+
this.records.delete(id);
|
|
11
|
+
}
|
|
12
|
+
ids() {
|
|
13
|
+
return [...this.records.keys()];
|
|
14
|
+
}
|
|
15
|
+
clear() {
|
|
16
|
+
this.records.clear();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export const LIVE_REVIEW_SESSION_WRITE_CONTRACT_VERSION = "shared_sqlite_review_session_v1";
|
|
2
|
+
export const LIVE_REVIEW_SESSION_INSERT_TRIGGER = "trg_live_review_sessions_contract_insert";
|
|
3
|
+
export const LIVE_REVIEW_SESSION_UPDATE_TRIGGER = "trg_live_review_sessions_contract_update";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
2
|
+
export const DEFAULT_SESSION_TTL_MS = 30 * 60 * 1000;
|
|
3
|
+
export function createLocalSessionBase(now, ttlMs) {
|
|
4
|
+
const id = randomBytes(18).toString("base64url");
|
|
5
|
+
const token = randomBytes(32).toString("base64url");
|
|
6
|
+
const createdAt = now.toISOString();
|
|
7
|
+
return {
|
|
8
|
+
base: {
|
|
9
|
+
id,
|
|
10
|
+
tokenHash: hashToken(token),
|
|
11
|
+
createdAt,
|
|
12
|
+
expiresAt: new Date(now.getTime() + ttlMs).toISOString(),
|
|
13
|
+
lastActivityAt: createdAt
|
|
14
|
+
},
|
|
15
|
+
token
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function hashToken(token) {
|
|
19
|
+
return createHash("sha256").update(token).digest("hex");
|
|
20
|
+
}
|
|
21
|
+
export function tokenMatchesHash(tokenHash, token) {
|
|
22
|
+
const expected = Buffer.from(tokenHash, "hex");
|
|
23
|
+
const actual = Buffer.from(hashToken(token), "hex");
|
|
24
|
+
return expected.length === actual.length && timingSafeEqual(expected, actual);
|
|
25
|
+
}
|
|
26
|
+
export function isLocalSessionExpired(session, now) {
|
|
27
|
+
return new Date(session.expiresAt).getTime() <= now.getTime();
|
|
28
|
+
}
|
|
29
|
+
export function cloneLocalSession(value) {
|
|
30
|
+
return structuredClone(value);
|
|
31
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { transactionFundingEvidenceSchema } from "../action/transactionFunding.js";
|
|
2
|
+
import { parseHumanReadableReviewEvidence } from "../action/humanReadableReviewEvidence.js";
|
|
3
|
+
import { parseReviewTimeSimulationEvidence } from "../action/reviewTimeSimulationEvidence.js";
|
|
4
|
+
export function clonePrivateReviewArtifacts(artifacts) {
|
|
5
|
+
return {
|
|
6
|
+
...(artifacts.transactionMaterial
|
|
7
|
+
? { transactionMaterial: { ...artifacts.transactionMaterial } }
|
|
8
|
+
: {}),
|
|
9
|
+
...(artifacts.transactionMaterialDigest
|
|
10
|
+
? { transactionMaterialDigest: { ...artifacts.transactionMaterialDigest } }
|
|
11
|
+
: {}),
|
|
12
|
+
...(artifacts.swapQuotePolicy
|
|
13
|
+
? {
|
|
14
|
+
swapQuotePolicy: {
|
|
15
|
+
...artifacts.swapQuotePolicy,
|
|
16
|
+
quoteSource: { ...artifacts.swapQuotePolicy.quoteSource },
|
|
17
|
+
sourceAmount: {
|
|
18
|
+
...artifacts.swapQuotePolicy.sourceAmount,
|
|
19
|
+
asset: { ...artifacts.swapQuotePolicy.sourceAmount.asset }
|
|
20
|
+
},
|
|
21
|
+
expectedOutput: {
|
|
22
|
+
...artifacts.swapQuotePolicy.expectedOutput,
|
|
23
|
+
asset: { ...artifacts.swapQuotePolicy.expectedOutput.asset }
|
|
24
|
+
},
|
|
25
|
+
minimumOutput: {
|
|
26
|
+
...artifacts.swapQuotePolicy.minimumOutput,
|
|
27
|
+
asset: { ...artifacts.swapQuotePolicy.minimumOutput.asset }
|
|
28
|
+
},
|
|
29
|
+
protocolFee: {
|
|
30
|
+
...artifacts.swapQuotePolicy.protocolFee,
|
|
31
|
+
asset: { ...artifacts.swapQuotePolicy.protocolFee.asset }
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
: {}),
|
|
36
|
+
...(artifacts.transactionObjectOwnership
|
|
37
|
+
? {
|
|
38
|
+
transactionObjectOwnership: {
|
|
39
|
+
...artifacts.transactionObjectOwnership,
|
|
40
|
+
funding: transactionFundingEvidenceSchema.parse(structuredClone(artifacts.transactionObjectOwnership.funding)),
|
|
41
|
+
objects: artifacts.transactionObjectOwnership.objects.map((object) => ({
|
|
42
|
+
...object,
|
|
43
|
+
roles: [...object.roles]
|
|
44
|
+
}))
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
: {}),
|
|
48
|
+
...(artifacts.humanReadableReview
|
|
49
|
+
? {
|
|
50
|
+
humanReadableReview: parseHumanReadableReviewEvidence(structuredClone(artifacts.humanReadableReview))
|
|
51
|
+
}
|
|
52
|
+
: {}),
|
|
53
|
+
...(artifacts.reviewTimeSimulation
|
|
54
|
+
? {
|
|
55
|
+
reviewTimeSimulation: parseReviewTimeSimulationEvidence(structuredClone(artifacts.reviewTimeSimulation))
|
|
56
|
+
}
|
|
57
|
+
: {})
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export class InMemoryPrivateReviewArtifactStore {
|
|
61
|
+
artifacts = new Map();
|
|
62
|
+
get(reviewSessionId) {
|
|
63
|
+
const artifacts = this.artifacts.get(reviewSessionId);
|
|
64
|
+
return artifacts ? clonePrivateReviewArtifacts(artifacts) : undefined;
|
|
65
|
+
}
|
|
66
|
+
set(reviewSessionId, artifacts) {
|
|
67
|
+
this.artifacts.set(reviewSessionId, clonePrivateReviewArtifacts(artifacts));
|
|
68
|
+
}
|
|
69
|
+
delete(reviewSessionId) {
|
|
70
|
+
this.artifacts.delete(reviewSessionId);
|
|
71
|
+
}
|
|
72
|
+
clear() {
|
|
73
|
+
this.artifacts.clear();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
|
+
import { REVIEW_MATERIAL_DERIVED_FIELDS } from "../action/types.js";
|
|
3
|
+
import { sameHandle } from "./transactionMaterialStore.js";
|
|
4
|
+
import { SessionStoreError } from "./sessionErrors.js";
|
|
5
|
+
export function needsReviewMaterial(session, admitted) {
|
|
6
|
+
return !admitted && !session.preparationId && session.status !== "expired" &&
|
|
7
|
+
!!session.reviewState && REVIEW_MATERIAL_DERIVED_FIELDS.some((field) => session.reviewState[field] !== undefined);
|
|
8
|
+
}
|
|
9
|
+
export function invalidateReviewEvidence(session, now) {
|
|
10
|
+
if (session.reviewState && session.reviewState.status !== "ready_for_wallet_review") {
|
|
11
|
+
const state = { ...session.reviewState, evidenceValidity: "invalidated", updatedAt: now.toISOString() };
|
|
12
|
+
for (const field of REVIEW_MATERIAL_DERIVED_FIELDS)
|
|
13
|
+
delete state[field];
|
|
14
|
+
// Keep the computation's failure reason, checks and stage provenance. Their
|
|
15
|
+
// presence describes that failed attempt, not currently usable material.
|
|
16
|
+
return { ...session, lastActivityAt: now.toISOString(), reviewState: state };
|
|
17
|
+
}
|
|
18
|
+
return { ...session, status: "refresh_required", lastActivityAt: now.toISOString(),
|
|
19
|
+
...(session.reviewState ? { reviewState: {
|
|
20
|
+
planId: session.reviewState.planId, reviewSessionId: session.id, account: session.reviewState.account,
|
|
21
|
+
status: "refresh_required", refreshReason: "review_evidence_stale",
|
|
22
|
+
checks: [{ id: "private_review_artifacts_refresh_required", label: "Review details out of date", status: "fail",
|
|
23
|
+
message: "These review details are no longer current.", source: "adapter" }],
|
|
24
|
+
updatedAt: now.toISOString()
|
|
25
|
+
} } : {}) };
|
|
26
|
+
}
|
|
27
|
+
export function materialStillMatches(verified, session, rowRevision, artifacts, material, now) {
|
|
28
|
+
return session.id === verified.reviewSessionId && session.reviewRevision === verified.reviewRevision &&
|
|
29
|
+
rowRevision === verified.rowRevision && session.account === verified.account &&
|
|
30
|
+
session.reviewState?.planId === verified.planId &&
|
|
31
|
+
isDeepStrictEqual(artifacts, verified.artifacts) && !!artifacts?.transactionMaterial && sameHandle(artifacts.transactionMaterial, verified.transactionMaterial) &&
|
|
32
|
+
isDeepStrictEqual(artifacts.transactionMaterialDigest, verified.transactionMaterialDigest) &&
|
|
33
|
+
!!material && sameHandle(material, verified.transactionMaterial) && Date.parse(material.expiresAt) > now.getTime() &&
|
|
34
|
+
Buffer.from(material.transactionBytes).toString("base64") === verified.transactionBytesBase64;
|
|
35
|
+
}
|
|
36
|
+
// The caller owns a synchronous transaction and supplies its one decision time.
|
|
37
|
+
export function decideReviewEvaluation(candidate, current, rowRevision, artifacts, material, admitted, now) {
|
|
38
|
+
if (current.status !== "expired" && Date.parse(current.expiresAt) <= now.getTime()) {
|
|
39
|
+
return { ...current, status: "expired" };
|
|
40
|
+
}
|
|
41
|
+
if (!needsReviewMaterial(current, admitted))
|
|
42
|
+
return current;
|
|
43
|
+
if (candidate.rowRevision !== rowRevision || !isDeepStrictEqual(candidate.session, current) ||
|
|
44
|
+
!isDeepStrictEqual(candidate.artifacts, artifacts)) {
|
|
45
|
+
throw new SessionStoreError("invalid_session_transition", "The review changed while it was being checked.", { reason: "review_changed_during_verification", message: "The review changed while it was being checked." });
|
|
46
|
+
}
|
|
47
|
+
return candidate.material && materialStillMatches(candidate.material, current, rowRevision, artifacts, material, now)
|
|
48
|
+
? current : invalidateReviewEvidence(current, now);
|
|
49
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
|
+
import { cloneLocalSession } from "./localSession.js";
|
|
3
|
+
export class InMemorySessionRecordStore {
|
|
4
|
+
sessions = new Map();
|
|
5
|
+
revisions = new Map();
|
|
6
|
+
usesActivityStoreLiveSessionMutations = false;
|
|
7
|
+
get(id) {
|
|
8
|
+
const session = this.sessions.get(id);
|
|
9
|
+
return session ? cloneLocalSession(session) : undefined;
|
|
10
|
+
}
|
|
11
|
+
revision(id) { return this.revisions.get(id); }
|
|
12
|
+
hasAdmittedRevision(_id, _reviewRevision) { return false; }
|
|
13
|
+
create(id, session) {
|
|
14
|
+
if (this.sessions.has(id)) {
|
|
15
|
+
throw new Error(`Review session already exists: ${id}`);
|
|
16
|
+
}
|
|
17
|
+
this.sessions.set(id, cloneLocalSession(session));
|
|
18
|
+
this.revisions.set(id, 0);
|
|
19
|
+
}
|
|
20
|
+
commitReviewSessionTransition(id, expected, next) {
|
|
21
|
+
const current = this.sessions.get(id);
|
|
22
|
+
if (!current || !isDeepStrictEqual(current, expected)) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
this.sessions.set(id, cloneLocalSession(next));
|
|
26
|
+
this.revisions.set(id, this.revisions.get(id) + 1);
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
ids() {
|
|
30
|
+
return [...this.sessions.keys()];
|
|
31
|
+
}
|
|
32
|
+
clear() {
|
|
33
|
+
this.sessions.clear();
|
|
34
|
+
this.revisions.clear();
|
|
35
|
+
}
|
|
36
|
+
hasUnsettledRequest(_id, _now) {
|
|
37
|
+
// This preparation-only fixture owns no wallet request records.
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|