@wowok/agent-mcp 2.4.3 → 2.5.1
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/config/runtime.d.ts +4 -0
- package/dist/config/runtime.js +29 -5
- package/dist/harness/auto-escalation.d.ts +27 -0
- package/dist/harness/auto-escalation.js +68 -0
- package/dist/index.js +21 -0
- package/dist/knowledge/allocation-confirm.d.ts +115 -0
- package/dist/knowledge/allocation-confirm.js +534 -0
- package/dist/knowledge/allocation-context.d.ts +58 -0
- package/dist/knowledge/allocation-context.js +249 -0
- package/dist/knowledge/allocation-ledger.d.ts +67 -0
- package/dist/knowledge/allocation-ledger.js +463 -0
- package/dist/knowledge/allocation-puzzle.d.ts +135 -0
- package/dist/knowledge/allocation-puzzle.js +298 -0
- package/dist/knowledge/allocation-risk.d.ts +78 -0
- package/dist/knowledge/allocation-risk.js +568 -0
- package/dist/knowledge/allocation-templates.d.ts +38 -0
- package/dist/knowledge/allocation-templates.js +970 -0
- package/dist/knowledge/allocation-translation.d.ts +72 -0
- package/dist/knowledge/allocation-translation.js +585 -0
- package/dist/knowledge/arb-risk.d.ts +37 -0
- package/dist/knowledge/arb-risk.js +210 -0
- package/dist/knowledge/arbitration-confirm.d.ts +135 -0
- package/dist/knowledge/arbitration-confirm.js +559 -0
- package/dist/knowledge/arbitration-context.d.ts +81 -0
- package/dist/knowledge/arbitration-context.js +505 -0
- package/dist/knowledge/arbitration-ledger.d.ts +62 -0
- package/dist/knowledge/arbitration-ledger.js +521 -0
- package/dist/knowledge/arbitration-puzzle.d.ts +84 -0
- package/dist/knowledge/arbitration-puzzle.js +304 -0
- package/dist/knowledge/arbitration-risk.d.ts +112 -0
- package/dist/knowledge/arbitration-risk.js +433 -0
- package/dist/knowledge/arbitration-templates.d.ts +38 -0
- package/dist/knowledge/arbitration-templates.js +276 -0
- package/dist/knowledge/arbitration-translation.d.ts +91 -0
- package/dist/knowledge/arbitration-translation.js +487 -0
- package/dist/knowledge/bridge-risk.d.ts +36 -0
- package/dist/knowledge/bridge-risk.js +263 -0
- package/dist/knowledge/contact-risk.d.ts +32 -0
- package/dist/knowledge/contact-risk.js +200 -0
- package/dist/knowledge/demand-confirm.d.ts +32 -0
- package/dist/knowledge/demand-confirm.js +206 -0
- package/dist/knowledge/demand-risk.d.ts +30 -0
- package/dist/knowledge/demand-risk.js +240 -0
- package/dist/knowledge/demand-translation.d.ts +55 -0
- package/dist/knowledge/demand-translation.js +354 -0
- package/dist/knowledge/deployment-scanner.d.ts +63 -0
- package/dist/knowledge/deployment-scanner.js +762 -0
- package/dist/knowledge/examples-scanner-cli.d.ts +1 -0
- package/dist/knowledge/examples-scanner-cli.js +26 -0
- package/dist/knowledge/examples-scanner.d.ts +121 -0
- package/dist/knowledge/examples-scanner.js +825 -0
- package/dist/knowledge/flywheel-loop.d.ts +3 -0
- package/dist/knowledge/flywheel-loop.js +32 -3
- package/dist/knowledge/glossary.js +3 -1
- package/dist/knowledge/guard-confirm.d.ts +86 -0
- package/dist/knowledge/guard-confirm.js +406 -0
- package/dist/knowledge/guard-context.d.ts +56 -0
- package/dist/knowledge/guard-context.js +287 -0
- package/dist/knowledge/guard-design-patterns.d.ts +37 -0
- package/dist/knowledge/guard-design-patterns.js +257 -0
- package/dist/knowledge/guard-puzzle.js +3 -2
- package/dist/knowledge/guard-risk.d.ts +1 -1
- package/dist/knowledge/guard-risk.js +12 -14
- package/dist/knowledge/guard-templates.js +1 -1
- package/dist/knowledge/guard-translation.js +6 -5
- package/dist/knowledge/index.d.ts +342 -0
- package/dist/knowledge/index.js +344 -0
- package/dist/knowledge/machine-confirm.d.ts +102 -0
- package/dist/knowledge/machine-confirm.js +559 -0
- package/dist/knowledge/machine-context.d.ts +160 -0
- package/dist/knowledge/machine-context.js +812 -0
- package/dist/knowledge/machine-ledger.d.ts +41 -0
- package/dist/knowledge/machine-ledger.js +315 -0
- package/dist/knowledge/machine-puzzle.d.ts +206 -0
- package/dist/knowledge/machine-puzzle.js +494 -0
- package/dist/knowledge/machine-risk.d.ts +75 -0
- package/dist/knowledge/machine-risk.js +644 -0
- package/dist/knowledge/machine-templates.d.ts +92 -0
- package/dist/knowledge/machine-templates.js +1592 -0
- package/dist/knowledge/machine-topology.d.ts +57 -0
- package/dist/knowledge/machine-topology.js +234 -0
- package/dist/knowledge/machine-translation.d.ts +96 -0
- package/dist/knowledge/machine-translation.js +513 -0
- package/dist/knowledge/mcp-schema-audit-cli.d.ts +1 -0
- package/dist/knowledge/mcp-schema-audit-cli.js +45 -0
- package/dist/knowledge/mcp-schema-audit.d.ts +90 -0
- package/dist/knowledge/mcp-schema-audit.js +772 -0
- package/dist/knowledge/onchain-constants.d.ts +4 -0
- package/dist/knowledge/onchain-constants.js +35 -0
- package/dist/knowledge/order-confirm.d.ts +115 -0
- package/dist/knowledge/order-confirm.js +573 -0
- package/dist/knowledge/order-context.d.ts +66 -0
- package/dist/knowledge/order-context.js +390 -0
- package/dist/knowledge/order-ledger.d.ts +69 -0
- package/dist/knowledge/order-ledger.js +341 -0
- package/dist/knowledge/order-puzzle.d.ts +159 -0
- package/dist/knowledge/order-puzzle.js +255 -0
- package/dist/knowledge/order-risk.d.ts +66 -0
- package/dist/knowledge/order-risk.js +653 -0
- package/dist/knowledge/order-templates.d.ts +50 -0
- package/dist/knowledge/order-templates.js +368 -0
- package/dist/knowledge/order-translation.d.ts +78 -0
- package/dist/knowledge/order-translation.js +550 -0
- package/dist/knowledge/passport-confirm.d.ts +130 -0
- package/dist/knowledge/passport-confirm.js +531 -0
- package/dist/knowledge/passport-context.d.ts +59 -0
- package/dist/knowledge/passport-context.js +306 -0
- package/dist/knowledge/passport-ledger.d.ts +48 -0
- package/dist/knowledge/passport-ledger.js +282 -0
- package/dist/knowledge/passport-puzzle.d.ts +108 -0
- package/dist/knowledge/passport-puzzle.js +333 -0
- package/dist/knowledge/passport-risk.d.ts +70 -0
- package/dist/knowledge/passport-risk.js +450 -0
- package/dist/knowledge/passport-templates.d.ts +40 -0
- package/dist/knowledge/passport-templates.js +568 -0
- package/dist/knowledge/passport-translation.d.ts +68 -0
- package/dist/knowledge/passport-translation.js +516 -0
- package/dist/knowledge/payment-risk.d.ts +33 -0
- package/dist/knowledge/payment-risk.js +182 -0
- package/dist/knowledge/permission-confirm.d.ts +110 -0
- package/dist/knowledge/permission-confirm.js +426 -0
- package/dist/knowledge/permission-context.d.ts +58 -0
- package/dist/knowledge/permission-context.js +224 -0
- package/dist/knowledge/permission-ledger.d.ts +38 -0
- package/dist/knowledge/permission-ledger.js +403 -0
- package/dist/knowledge/permission-puzzle.d.ts +122 -0
- package/dist/knowledge/permission-puzzle.js +173 -0
- package/dist/knowledge/permission-risk.d.ts +76 -0
- package/dist/knowledge/permission-risk.js +411 -0
- package/dist/knowledge/permission-templates.d.ts +38 -0
- package/dist/knowledge/permission-templates.js +234 -0
- package/dist/knowledge/permission-translation.d.ts +57 -0
- package/dist/knowledge/permission-translation.js +350 -0
- package/dist/knowledge/personal-risk.d.ts +36 -0
- package/dist/knowledge/personal-risk.js +212 -0
- package/dist/knowledge/progress-confirm.d.ts +108 -0
- package/dist/knowledge/progress-confirm.js +456 -0
- package/dist/knowledge/progress-context.d.ts +123 -0
- package/dist/knowledge/progress-context.js +452 -0
- package/dist/knowledge/progress-ledger.d.ts +63 -0
- package/dist/knowledge/progress-ledger.js +327 -0
- package/dist/knowledge/progress-puzzle.d.ts +82 -0
- package/dist/knowledge/progress-puzzle.js +219 -0
- package/dist/knowledge/progress-risk.d.ts +74 -0
- package/dist/knowledge/progress-risk.js +461 -0
- package/dist/knowledge/progress-templates.d.ts +38 -0
- package/dist/knowledge/progress-templates.js +228 -0
- package/dist/knowledge/progress-translation.d.ts +52 -0
- package/dist/knowledge/progress-translation.js +401 -0
- package/dist/knowledge/proof-confirm.d.ts +31 -0
- package/dist/knowledge/proof-confirm.js +187 -0
- package/dist/knowledge/proof-risk.d.ts +33 -0
- package/dist/knowledge/proof-risk.js +207 -0
- package/dist/knowledge/proof-translation.d.ts +52 -0
- package/dist/knowledge/proof-translation.js +283 -0
- package/dist/knowledge/registrar-risk.d.ts +34 -0
- package/dist/knowledge/registrar-risk.js +217 -0
- package/dist/knowledge/repository-confirm.d.ts +36 -0
- package/dist/knowledge/repository-confirm.js +242 -0
- package/dist/knowledge/repository-risk.d.ts +40 -0
- package/dist/knowledge/repository-risk.js +312 -0
- package/dist/knowledge/repository-translation.d.ts +58 -0
- package/dist/knowledge/repository-translation.js +422 -0
- package/dist/knowledge/resource-risk.d.ts +32 -0
- package/dist/knowledge/resource-risk.js +157 -0
- package/dist/knowledge/reward-confirm.d.ts +113 -0
- package/dist/knowledge/reward-confirm.js +496 -0
- package/dist/knowledge/reward-context.d.ts +127 -0
- package/dist/knowledge/reward-context.js +504 -0
- package/dist/knowledge/reward-ledger.d.ts +96 -0
- package/dist/knowledge/reward-ledger.js +502 -0
- package/dist/knowledge/reward-puzzle.d.ts +97 -0
- package/dist/knowledge/reward-puzzle.js +288 -0
- package/dist/knowledge/reward-risk.d.ts +84 -0
- package/dist/knowledge/reward-risk.js +545 -0
- package/dist/knowledge/reward-translation.d.ts +58 -0
- package/dist/knowledge/reward-translation.js +501 -0
- package/dist/knowledge/safety-rules.js +11 -3
- package/dist/knowledge/scenario-modes.d.ts +53 -0
- package/dist/knowledge/scenario-modes.js +302 -0
- package/dist/knowledge/service-confirm.d.ts +152 -0
- package/dist/knowledge/service-confirm.js +699 -0
- package/dist/knowledge/service-context.d.ts +66 -0
- package/dist/knowledge/service-context.js +403 -0
- package/dist/knowledge/service-ledger.d.ts +71 -0
- package/dist/knowledge/service-ledger.js +609 -0
- package/dist/knowledge/service-puzzle.d.ts +158 -0
- package/dist/knowledge/service-puzzle.js +236 -0
- package/dist/knowledge/service-risk.d.ts +108 -0
- package/dist/knowledge/service-risk.js +615 -0
- package/dist/knowledge/service-templates.d.ts +39 -0
- package/dist/knowledge/service-templates.js +418 -0
- package/dist/knowledge/service-translation.d.ts +103 -0
- package/dist/knowledge/service-translation.js +622 -0
- package/dist/knowledge/tools-reference.d.ts +17 -0
- package/dist/knowledge/tools-reference.js +151 -0
- package/dist/knowledge/treasury-confirm.d.ts +133 -0
- package/dist/knowledge/treasury-confirm.js +512 -0
- package/dist/knowledge/treasury-context.d.ts +64 -0
- package/dist/knowledge/treasury-context.js +363 -0
- package/dist/knowledge/treasury-ledger.d.ts +42 -0
- package/dist/knowledge/treasury-ledger.js +300 -0
- package/dist/knowledge/treasury-puzzle.d.ts +163 -0
- package/dist/knowledge/treasury-puzzle.js +216 -0
- package/dist/knowledge/treasury-risk.d.ts +86 -0
- package/dist/knowledge/treasury-risk.js +440 -0
- package/dist/knowledge/treasury-templates.d.ts +38 -0
- package/dist/knowledge/treasury-templates.js +316 -0
- package/dist/knowledge/treasury-translation.d.ts +78 -0
- package/dist/knowledge/treasury-translation.js +498 -0
- package/dist/knowledge/util-risk.d.ts +30 -0
- package/dist/knowledge/util-risk.js +135 -0
- package/dist/project/business-puzzle.d.ts +47 -0
- package/dist/project/business-puzzle.js +372 -0
- package/dist/project/deployment-doc.d.ts +61 -0
- package/dist/project/deployment-doc.js +432 -0
- package/dist/project/risk-aggregator.d.ts +50 -0
- package/dist/project/risk-aggregator.js +280 -0
- package/dist/project/substep-trace.d.ts +130 -0
- package/dist/project/substep-trace.js +332 -0
- package/dist/schema/call/allocation.d.ts +34 -34
- package/dist/schema/call/arbitration.d.ts +141 -141
- package/dist/schema/call/base.d.ts +386 -386
- package/dist/schema/call/base.js +3 -3
- package/dist/schema/call/bridge-handler.d.ts +5 -2
- package/dist/schema/call/bridge.d.ts +159 -159
- package/dist/schema/call/contact.d.ts +110 -110
- package/dist/schema/call/demand.d.ts +76 -76
- package/dist/schema/call/handler.d.ts +2 -3
- package/dist/schema/call/handler.js +1 -1
- package/dist/schema/call/machine.d.ts +58 -58
- package/dist/schema/call/order.d.ts +98 -110
- package/dist/schema/call/permission-handler.d.ts +5 -0
- package/dist/schema/call/permission-handler.js +54 -0
- package/dist/schema/call/permission.d.ts +108 -108
- package/dist/schema/call/personal.d.ts +14 -14
- package/dist/schema/call/progress.d.ts +57 -72
- package/dist/schema/call/progress.js +7 -4
- package/dist/schema/call/proof.d.ts +18 -18
- package/dist/schema/call/proof.js +12 -7
- package/dist/schema/call/repository.d.ts +154 -154
- package/dist/schema/call/reward.d.ts +55 -55
- package/dist/schema/call/service.d.ts +231 -231
- package/dist/schema/call/treasury.d.ts +93 -93
- package/dist/schema/config/index.d.ts +178 -5
- package/dist/schema/config/index.js +52 -1
- package/dist/schema/local/index.d.ts +3554 -836
- package/dist/schema/local/index.js +2 -1
- package/dist/schema/messenger/index.d.ts +162 -162
- package/dist/schema/operations.d.ts +1058 -1074
- package/dist/schema/operations.js +7 -1
- package/dist/schema/project/index.d.ts +1412 -6
- package/dist/schema/project/index.js +441 -3
- package/dist/schema/query/index.d.ts +672 -672
- package/dist/schema/schema-query/index.d.ts +23 -3
- package/dist/schema/schema-query/index.js +13 -2
- package/dist/schema/sync-layer4.d.ts +21 -0
- package/dist/schema/sync-layer4.js +261 -0
- package/dist/schema/trust/index.d.ts +26 -26
- package/dist/schemas/account_operation.output.json +718 -0
- package/dist/schemas/config_operation.output.json +173 -0
- package/dist/schemas/index.json +9 -1
- package/dist/schemas/local_info_operation.output.json +718 -0
- package/dist/schemas/local_mark_operation.output.json +718 -0
- package/dist/schemas/onchain_operations.output.json +3 -2
- package/dist/schemas/onchain_operations.schema.json +1809 -336
- package/dist/schemas/onchain_operations_allocation.schema.json +2 -1
- package/dist/schemas/onchain_operations_arbitration.schema.json +2 -1
- package/dist/schemas/onchain_operations_contact.schema.json +2 -1
- package/dist/schemas/onchain_operations_demand.schema.json +2 -1
- package/dist/schemas/onchain_operations_gen_passport.schema.json +878 -872
- package/dist/schemas/onchain_operations_gen_proof.schema.json +273 -0
- package/dist/schemas/onchain_operations_guard.schema.json +578 -579
- package/dist/schemas/onchain_operations_machine.schema.json +2 -1
- package/dist/schemas/onchain_operations_order.schema.json +13 -9
- package/dist/schemas/onchain_operations_payment.schema.json +0 -514
- package/dist/schemas/onchain_operations_permission.schema.json +0 -514
- package/dist/schemas/onchain_operations_personal.schema.json +0 -514
- package/dist/schemas/onchain_operations_progress.schema.json +14 -10
- package/dist/schemas/onchain_operations_proof.schema.json +699 -0
- package/dist/schemas/onchain_operations_repository.schema.json +2 -1
- package/dist/schemas/onchain_operations_reward.schema.json +2 -1
- package/dist/schemas/onchain_operations_service.schema.json +2 -1
- package/dist/schemas/onchain_operations_treasury.schema.json +2 -1
- package/dist/schemas/onchain_table_data.schema.json +32 -1
- package/dist/schemas/project_operation.output.json +918 -0
- package/dist/schemas/project_operation.schema.json +474 -3
- package/dist/schemas/query_toolkit.output.json +14906 -6
- package/dist/schemas/schema_query.output.json +38 -1
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/tools/handlers/config.d.ts +1 -1
- package/dist/tools/handlers/config.js +21 -18
- package/dist/tools/handlers/file-export.d.ts +2 -2
- package/dist/tools/handlers/local.d.ts +3 -30
- package/dist/tools/handlers/local.js +14 -3
- package/dist/tools/handlers/messenger.d.ts +1 -1
- package/dist/tools/handlers/messenger.js +2 -1
- package/dist/tools/handlers/onchain.d.ts +1 -1
- package/dist/tools/handlers/onchain.js +24 -22
- package/dist/tools/handlers/project.d.ts +1 -1
- package/dist/tools/handlers/project.js +262 -18
- package/dist/tools/handlers/query.d.ts +4 -4
- package/dist/tools/handlers/schema-query.d.ts +1 -1
- package/dist/tools/handlers/schema-query.js +21 -20
- package/dist/tools/handlers/trust.d.ts +1 -1
- package/dist/tools/handlers/trust.js +2 -2
- package/dist/tools/handlers/wip.d.ts +1 -1
- package/dist/tools/handlers/wip.js +1 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.js +96 -25
- package/dist/tools/rules-hook.d.ts +1 -1
- package/dist/tools/rules-hook.js +3 -2
- package/dist/tools/shared.d.ts +13 -22
- package/dist/tools/types.d.ts +5 -5
- package/dist/tools/wrap.d.ts +10 -2
- package/dist/tools/wrap.js +212 -0
- package/package.json +3 -3
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
import { MAX_POLICY_COUNT, MAX_POLICY_DESCRIPTION_LEN, MAX_POLICY_GUARD_COUNT, MAX_DATA_SIZE, MAX_ID_COUNT_ONCE, MAX_REWARD_COUNT, } from "@wowok/wowok";
|
|
2
|
+
export const SEMANTIC_TO_REPOSITORY_SCHEMA_RULES = [
|
|
3
|
+
{
|
|
4
|
+
id: "P-REP-01",
|
|
5
|
+
pattern_name: "Clock-routed data (id=timestamp)",
|
|
6
|
+
routing_mode: "clock",
|
|
7
|
+
semantic_intent: "Data is keyed by current timestamp (id_from=Clock). Each write produces a unique timestamp-keyed entry. " +
|
|
8
|
+
"Suitable for append-only logs, time-series records, and audit trails. write_guard may be empty (id is " +
|
|
9
|
+
"auto-generated and predictable) or non-empty with data_from_submission set (guard supplies the data " +
|
|
10
|
+
"payload while id comes from the clock — e.g. oracle-fed time-series).",
|
|
11
|
+
match_keywords: ["timestamp", "log", "audit trail", "time-series", "append-only", "clock"],
|
|
12
|
+
schema_elements: {
|
|
13
|
+
id_from_value: 1,
|
|
14
|
+
required_policy_fields: ["name", "description", "id_from", "value_type", "write_guard"],
|
|
15
|
+
write_guard_requirement: "either",
|
|
16
|
+
move_entry_point: "data_when_id_from_set",
|
|
17
|
+
caller_input_shape: "{ name, data } — no id, no write_guard, no Passport",
|
|
18
|
+
},
|
|
19
|
+
constraints: [
|
|
20
|
+
"id_from MUST be Clock (1)",
|
|
21
|
+
"write_guard MAY be empty OR non-empty (R-D-1 refined)",
|
|
22
|
+
"If write_guard is non-empty, every PolicyGuard.id_from_submission MUST be None (E_POLICY_ID_FROM_SUBMISSION_FORBIDDEN=23)",
|
|
23
|
+
"data_from_submission MAY be set (used by data_when_id_from_set_with_passport)",
|
|
24
|
+
"Caller uses data_when_id_from_set (no guard) or data_when_id_from_set_with_passport (with guard)",
|
|
25
|
+
"ID is auto-generated from clock::timestamp_ms",
|
|
26
|
+
],
|
|
27
|
+
example: {
|
|
28
|
+
name: "audit_log",
|
|
29
|
+
description: "Append-only audit log keyed by timestamp",
|
|
30
|
+
id_from: "Clock",
|
|
31
|
+
value_type: 0,
|
|
32
|
+
write_guard: [],
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: "P-REP-02",
|
|
37
|
+
pattern_name: "Signer-routed data (id=signer address)",
|
|
38
|
+
routing_mode: "signer",
|
|
39
|
+
semantic_intent: "Data is keyed by signer address (id_from=Signer). Each user has at most one data entry per policy. " +
|
|
40
|
+
"Suitable for user profiles, KYC attestations, per-user settings. write_guard may be empty (signer " +
|
|
41
|
+
"writes their own data) or non-empty with data_from_submission set (guard supplies the data payload " +
|
|
42
|
+
"while id comes from the signer — e.g. verified credential insertion).",
|
|
43
|
+
match_keywords: ["profile", "user data", "kyc", "per-user", "signer", "identity"],
|
|
44
|
+
schema_elements: {
|
|
45
|
+
id_from_value: 2,
|
|
46
|
+
required_policy_fields: ["name", "description", "id_from", "value_type", "write_guard"],
|
|
47
|
+
write_guard_requirement: "either",
|
|
48
|
+
move_entry_point: "data_when_id_from_set",
|
|
49
|
+
caller_input_shape: "{ name, data } — no id, no write_guard, no Passport",
|
|
50
|
+
},
|
|
51
|
+
constraints: [
|
|
52
|
+
"id_from MUST be Signer (2)",
|
|
53
|
+
"write_guard MAY be empty OR non-empty (R-D-1 refined)",
|
|
54
|
+
"If write_guard is non-empty, every PolicyGuard.id_from_submission MUST be None (E_POLICY_ID_FROM_SUBMISSION_FORBIDDEN=23)",
|
|
55
|
+
"data_from_submission MAY be set (used by data_when_id_from_set_with_passport)",
|
|
56
|
+
"Caller uses data_when_id_from_set (no guard) or data_when_id_from_set_with_passport (with guard)",
|
|
57
|
+
"ID is auto-generated from ctx.sender()",
|
|
58
|
+
],
|
|
59
|
+
example: {
|
|
60
|
+
name: "user_profile",
|
|
61
|
+
description: "Per-user profile data keyed by signer address",
|
|
62
|
+
id_from: "Signer",
|
|
63
|
+
value_type: 0,
|
|
64
|
+
write_guard: [],
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
id: "P-REP-03",
|
|
69
|
+
pattern_name: "Guard-protected with caller-provided id (Mode 4)",
|
|
70
|
+
routing_mode: "guard_caller",
|
|
71
|
+
semantic_intent: "Data is keyed by caller-provided id (id_from=None). Write authorization requires a Passport submission " +
|
|
72
|
+
"verifying the guard. Suitable for application-specific keys (order IDs, content hashes, custom identifiers). " +
|
|
73
|
+
"The guard enforces WHO can write; the caller decides WHAT id to use.",
|
|
74
|
+
match_keywords: ["custom id", "order id", "content hash", "application key", "guard protected", "passport"],
|
|
75
|
+
schema_elements: {
|
|
76
|
+
id_from_value: 0,
|
|
77
|
+
required_policy_fields: ["name", "description", "id_from", "value_type", "write_guard"],
|
|
78
|
+
write_guard_requirement: "non_empty",
|
|
79
|
+
move_entry_point: "id_data_with_passport",
|
|
80
|
+
caller_input_shape: "{ name, items: [{ id, data, write_guard }] } — id and data provided by caller, Passport verifies guard",
|
|
81
|
+
},
|
|
82
|
+
constraints: [
|
|
83
|
+
"id_from MUST be None (0)",
|
|
84
|
+
"write_guard MUST be non-empty (R-D-1: E_POLICY_WRITE_GUARD_REQUIRED=22)",
|
|
85
|
+
"Each PolicyGuard MUST have id_from_submission=None AND data_from_submission=None",
|
|
86
|
+
"Caller uses id_data_with_passport entry point",
|
|
87
|
+
"Passport must verify one of the policy's write_guards",
|
|
88
|
+
],
|
|
89
|
+
example: {
|
|
90
|
+
name: "order_metadata",
|
|
91
|
+
description: "Order-specific metadata keyed by order id, guard-protected",
|
|
92
|
+
id_from: "None",
|
|
93
|
+
value_type: 0,
|
|
94
|
+
write_guard: [
|
|
95
|
+
{ guard: "0xguard_addr...", id_from_submission: null, data_from_submission: null },
|
|
96
|
+
],
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
id: "P-REP-04",
|
|
101
|
+
pattern_name: "Guard-protected with submission-derived id/data (Mode 5)",
|
|
102
|
+
routing_mode: "guard_submission",
|
|
103
|
+
semantic_intent: "Data id and/or data payload are derived from Guard submission values in the Passport. This is the most " +
|
|
104
|
+
"flexible mode: the guard can compute both the key and the value from its internal table. Suitable for " +
|
|
105
|
+
"bridges (where the guard verifies an external event and outputs the bridged amount), oracle-fed data, " +
|
|
106
|
+
"and complex authorization patterns.",
|
|
107
|
+
match_keywords: ["oracle", "bridge", "submission", "guard derived", "computed id", "computed data"],
|
|
108
|
+
schema_elements: {
|
|
109
|
+
id_from_value: 0,
|
|
110
|
+
required_policy_fields: ["name", "description", "id_from", "value_type", "write_guard"],
|
|
111
|
+
write_guard_requirement: "non_empty",
|
|
112
|
+
move_entry_point: "id_data_mixed_with_passport",
|
|
113
|
+
caller_input_shape: "{ name, items: [{ write_guard, id?, data? }] } — id/data omitted where submission provides them",
|
|
114
|
+
},
|
|
115
|
+
constraints: [
|
|
116
|
+
"id_from MUST be None (0)",
|
|
117
|
+
"write_guard MUST be non-empty (R-D-1: E_POLICY_WRITE_GUARD_REQUIRED=22)",
|
|
118
|
+
"Each PolicyGuard may have id_from_submission and/or data_from_submission set",
|
|
119
|
+
"Caller uses id_data_mixed_with_passport entry point",
|
|
120
|
+
"SDK hasSubmissionSettings must check BOTH id_from_submission AND data_from_submission (P1-1 fix)",
|
|
121
|
+
"Passport must verify the specified write_guards",
|
|
122
|
+
],
|
|
123
|
+
example: {
|
|
124
|
+
name: "oracle_price",
|
|
125
|
+
description: "Oracle-fed price data, id and data both from guard submission",
|
|
126
|
+
id_from: "None",
|
|
127
|
+
value_type: 0,
|
|
128
|
+
write_guard: [
|
|
129
|
+
{
|
|
130
|
+
guard: "0xoracle_guard_addr...",
|
|
131
|
+
id_from_submission: 0,
|
|
132
|
+
data_from_submission: 1,
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
];
|
|
138
|
+
export const REPOSITORY_FIELD_TRANSLATIONS = [
|
|
139
|
+
{
|
|
140
|
+
field_name: "policies",
|
|
141
|
+
value_type: "PolicyRule[]",
|
|
142
|
+
semantic: "List of policy rules defining data write permissions and routing. Each policy is a named data slot " +
|
|
143
|
+
"with its own write_guard list and id_from routing mode. Operations (data_add/data_remove) reference " +
|
|
144
|
+
"policies by name.",
|
|
145
|
+
format_example: "[{ name: 'audit_log', id_from: 'Clock', ... }]",
|
|
146
|
+
validation_rules: [
|
|
147
|
+
`Array length ≤ MAX_POLICY_COUNT (${MAX_POLICY_COUNT})`,
|
|
148
|
+
"Each policy name must be unique within the Repository",
|
|
149
|
+
"Move aborts with E_POLICY_COUNT_EXCEEDED (3) on overflow",
|
|
150
|
+
"Move aborts with E_POLICY_NOT_FOUND (7) when name not found",
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
field_name: "policies[].name",
|
|
155
|
+
move_field: "PolicyRule.name",
|
|
156
|
+
value_type: "string",
|
|
157
|
+
semantic: "Policy name. Acts as the key for data_add/data_remove operations. Must be unique within the Repository. " +
|
|
158
|
+
"Cannot be empty if NAME_ALLOW_EMPTY is not set.",
|
|
159
|
+
format_example: "audit_log",
|
|
160
|
+
validation_rules: [
|
|
161
|
+
"Non-empty string (unless NAME_ALLOW_EMPTY)",
|
|
162
|
+
"Must match an existing policy name in data_add/data_remove operations",
|
|
163
|
+
],
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
field_name: "policies[].description",
|
|
167
|
+
move_field: "PolicyRule.description",
|
|
168
|
+
value_type: "string",
|
|
169
|
+
semantic: "Human-readable description of what the policy is for. Helps with auditing and tooling.",
|
|
170
|
+
format_example: "Append-only audit log keyed by timestamp",
|
|
171
|
+
validation_rules: [
|
|
172
|
+
`Length ≤ MAX_POLICY_DESCRIPTION_LEN (${MAX_POLICY_DESCRIPTION_LEN})`,
|
|
173
|
+
"Move aborts with E_POLICY_DESCRIPTION_EXCEEDED (1)",
|
|
174
|
+
],
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
field_name: "policies[].id_from",
|
|
178
|
+
move_field: "PolicyRule.id_from",
|
|
179
|
+
value_type: "u8 (number | 'None' | 'Clock' | 'Signer')",
|
|
180
|
+
semantic: "Source of data ID when writing data. None (0): caller provides id; Clock (1): id=timestamp; " +
|
|
181
|
+
"Signer (2): id=signer address. Determines which entry point to use for data operations. " +
|
|
182
|
+
"SDK parseIdFrom normalizes string forms before comparison [P1-2 fix].",
|
|
183
|
+
format_example: "0, 1, 2, 'None', 'Clock', 'Signer'",
|
|
184
|
+
validation_rules: [
|
|
185
|
+
"Must be one of: 0, 1, 2, 'None', 'Clock', 'Signer' (case-insensitive)",
|
|
186
|
+
"Move aborts with E_INVALID_ID_FROM (18) for invalid u8 values",
|
|
187
|
+
"R-D-1 (refined): None requires non-empty write_guard; Clock/Signer allows non-empty write_guard but every PolicyGuard.id_from_submission MUST be None (data_from_submission still allowed)",
|
|
188
|
+
],
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
field_name: "policies[].write_guard",
|
|
192
|
+
move_field: "PolicyRule.write_guard",
|
|
193
|
+
value_type: "PolicyGuard[]",
|
|
194
|
+
semantic: "List of Guard objects that must be verified (via Passport) to write data. Each PolicyGuard maps to a " +
|
|
195
|
+
"Guard object and optionally specifies id_from_submission / data_from_submission for Mode 4/5 routing. " +
|
|
196
|
+
"R-D-1 (refined): must be non-empty when id_from=None; when id_from=Clock/Signer, MAY be non-empty but " +
|
|
197
|
+
"every PolicyGuard.id_from_submission MUST be None (data_from_submission is still allowed, enabling Mode 2b " +
|
|
198
|
+
"where id is auto-generated from clock/signer while data comes from the guard submission).",
|
|
199
|
+
format_example: "[{ guard: '0xaddr...', id_from_submission: 0, data_from_submission: 1 }]",
|
|
200
|
+
validation_rules: [
|
|
201
|
+
`Array length ≤ MAX_POLICY_GUARD_COUNT (${MAX_POLICY_GUARD_COUNT}) per policy`,
|
|
202
|
+
"Move aborts with E_POLICY_GUARD_COUNT_EXCEEDED (2)",
|
|
203
|
+
"R-D-1: E_POLICY_WRITE_GUARD_REQUIRED (22) if empty when id_from=None",
|
|
204
|
+
"R-D-1: E_POLICY_ID_FROM_SUBMISSION_FORBIDDEN (23) if any PolicyGuard.id_from_submission is non-null when id_from=Clock/Signer (data_from_submission still allowed)",
|
|
205
|
+
],
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
field_name: "policies[].write_guard[].id_from_submission",
|
|
209
|
+
move_field: "PolicyGuard.id_from_submission",
|
|
210
|
+
value_type: "Option<u8> (number | null)",
|
|
211
|
+
semantic: "Guard table data index whose value is the ID of the data to be written. When set, the ID comes from " +
|
|
212
|
+
"the Passport submission (Mode 5). When null, the caller must provide the ID (Mode 4). " +
|
|
213
|
+
"R-D-1 (refined): MUST be null when policy id_from=Clock/Signer (id is auto-generated; setting this " +
|
|
214
|
+
"would conflict with id_from routing). data_from_submission is still allowed in that case (Mode 2b).",
|
|
215
|
+
format_example: "0, 1, 2, or null",
|
|
216
|
+
validation_rules: [
|
|
217
|
+
"Optional (null → caller provides id)",
|
|
218
|
+
"Guard must have is_identifier_address_compatible(identifier)",
|
|
219
|
+
"Move aborts with E_INVALID_ID_IN_GUARD_TABLE (16) if incompatible",
|
|
220
|
+
"R-D-1: MUST be null when policy id_from=Clock/Signer (E_POLICY_ID_FROM_SUBMISSION_FORBIDDEN=23)",
|
|
221
|
+
],
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
field_name: "policies[].write_guard[].data_from_submission",
|
|
225
|
+
move_field: "PolicyGuard.data_from_submission",
|
|
226
|
+
value_type: "Option<u8> (number | null)",
|
|
227
|
+
semantic: "Guard table data index whose value is the data to be written. When set, the data comes from the " +
|
|
228
|
+
"Passport submission (Mode 5). When null, the caller provides the data (Mode 4). " +
|
|
229
|
+
"R-D-2: must be null for id_data_remove_with_passport (removal cannot consume submission data).",
|
|
230
|
+
format_example: "0, 1, 2, or null",
|
|
231
|
+
validation_rules: [
|
|
232
|
+
"Optional (null → caller provides data)",
|
|
233
|
+
"Guard must have has_identifier(identifier)",
|
|
234
|
+
"Move aborts with E_INVALID_DATA_IN_GUARD_TABLE (17) if missing",
|
|
235
|
+
"R-D-2: E_GUARD_SPECIFIED_ID_FROM_SUBMISSION (11) if set in id_data_remove_with_passport",
|
|
236
|
+
],
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
field_name: "data_add / data_remove",
|
|
240
|
+
value_type: "SignerOrClock | { name, items }",
|
|
241
|
+
semantic: "Data operations. For Clock/Signer policies, use SignerOrClock form ({name, data} or {name}). " +
|
|
242
|
+
"For None policies, use items form with id + write_guard per item. SDK hasSubmissionSettings helper " +
|
|
243
|
+
"routes to the correct Move entry point based on PolicyGuard settings [P1-1 fix].",
|
|
244
|
+
format_example: "{ name: 'audit_log', data: ... } or { name: 'order_meta', items: [{ id, data, write_guard }] }",
|
|
245
|
+
validation_rules: [
|
|
246
|
+
"Policy name must exist in Repository (E_POLICY_NOT_FOUND=7)",
|
|
247
|
+
"write_guard must be in policy (E_GUARD_SPECIFIED_NOT_IN_POLICY=13)",
|
|
248
|
+
"ID count ≤ MAX_ID_COUNT_ONCE per call",
|
|
249
|
+
"Data size ≤ MAX_DATA_SIZE per value",
|
|
250
|
+
],
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
field_name: "rewards",
|
|
254
|
+
value_type: "{ op: 'add'|'set'|'remove'|'clear', objects: string[] }",
|
|
255
|
+
semantic: "Reward objects referenced by this Repository. Rewards incentivize data contribution. When a writer " +
|
|
256
|
+
"adds data, they may claim a reward (if the guard verifies eligibility).",
|
|
257
|
+
format_example: "{ op: 'add', objects: ['0xreward1...', '0xreward2...'] }",
|
|
258
|
+
validation_rules: [
|
|
259
|
+
`Total reward count ≤ MAX_REWARD_COUNT (${MAX_REWARD_COUNT})`,
|
|
260
|
+
"Move aborts with E_MAX_REWARD_COUNT_EXCEEDED (19)",
|
|
261
|
+
"Reward objects must be properly configured (guard, amounts, recipients)",
|
|
262
|
+
],
|
|
263
|
+
},
|
|
264
|
+
];
|
|
265
|
+
export const REPOSITORY_CONSTRAINT_RULES = [
|
|
266
|
+
{
|
|
267
|
+
id: "REP_C_01",
|
|
268
|
+
name: "policy count within limit",
|
|
269
|
+
description: `Total policies in a Repository must be ≤ MAX_POLICY_COUNT (${MAX_POLICY_COUNT}).`,
|
|
270
|
+
validation_logic: "existing_policies + new_policies <= MAX_POLICY_COUNT",
|
|
271
|
+
failure_message: `Policy count exceeds MAX_POLICY_COUNT (${MAX_POLICY_COUNT}) — E_POLICY_COUNT_EXCEEDED (3)`,
|
|
272
|
+
related_field: "policies",
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
id: "REP_C_02",
|
|
276
|
+
name: "write_guard required when id_from=None (R-D-1)",
|
|
277
|
+
description: "When id_from is None, write_guard MUST be non-empty to prevent unauthorized writes.",
|
|
278
|
+
validation_logic: "id_from == None => write_guard.length > 0",
|
|
279
|
+
failure_message: "id_from=None requires non-empty write_guard — E_POLICY_WRITE_GUARD_REQUIRED (22)",
|
|
280
|
+
related_field: "policies[].write_guard",
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
id: "REP_C_03",
|
|
284
|
+
name: "id_from_submission forbidden when id_from=Clock/Signer (R-D-1 refined)",
|
|
285
|
+
description: "When id_from is Clock or Signer, every PolicyGuard.id_from_submission MUST be None (id is auto-generated; data_from_submission is still allowed).",
|
|
286
|
+
validation_logic: "(id_from == Clock || id_from == Signer) => all write_guard[].id_from_submission == null",
|
|
287
|
+
failure_message: "id_from=Clock/Signer requires id_from_submission=null on all guards — E_POLICY_ID_FROM_SUBMISSION_FORBIDDEN (23)",
|
|
288
|
+
related_field: "policies[].write_guard[].id_from_submission",
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
id: "REP_C_04",
|
|
292
|
+
name: "policy guard count within limit",
|
|
293
|
+
description: `Each policy write_guard list must be ≤ MAX_POLICY_GUARD_COUNT (${MAX_POLICY_GUARD_COUNT}).`,
|
|
294
|
+
validation_logic: "policy.write_guard.length <= MAX_POLICY_GUARD_COUNT",
|
|
295
|
+
failure_message: `Policy guard count exceeds MAX_POLICY_GUARD_COUNT (${MAX_POLICY_GUARD_COUNT}) — E_POLICY_GUARD_COUNT_EXCEEDED (2)`,
|
|
296
|
+
related_field: "policies[].write_guard",
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
id: "REP_C_05",
|
|
300
|
+
name: "data size within limit",
|
|
301
|
+
description: `Each data value must be ≤ MAX_DATA_SIZE (${MAX_DATA_SIZE}) bytes.`,
|
|
302
|
+
validation_logic: "data.length <= MAX_DATA_SIZE",
|
|
303
|
+
failure_message: `Data value exceeds MAX_DATA_SIZE (${MAX_DATA_SIZE} bytes) — E_DATA_EXCEEDED (4)`,
|
|
304
|
+
related_field: "data_add.data",
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
id: "REP_C_06",
|
|
308
|
+
name: "id count per op within limit",
|
|
309
|
+
description: `A single Repository call may operate on at most MAX_ID_COUNT_ONCE (${MAX_ID_COUNT_ONCE}) IDs.`,
|
|
310
|
+
validation_logic: "id_count <= MAX_ID_COUNT_ONCE",
|
|
311
|
+
failure_message: `ID count exceeds MAX_ID_COUNT_ONCE (${MAX_ID_COUNT_ONCE}) — E_ID_COUNT_EXCEEDED (5)`,
|
|
312
|
+
related_field: "data_add.items[].id / data_remove.items[].id",
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
id: "REP_C_07",
|
|
316
|
+
name: "data_from_submission null in id_data_remove_with_passport (R-D-2)",
|
|
317
|
+
description: "id_data_remove_with_passport only removes data by caller id; it cannot consume Passport submissions. " +
|
|
318
|
+
"Both id_from_submission AND data_from_submission must be None.",
|
|
319
|
+
validation_logic: "is_data_remove_with_passport => !has_id_from_submission && !has_data_from_submission",
|
|
320
|
+
failure_message: "id_data_remove_with_passport cannot have id_from_submission or data_from_submission — E_GUARD_SPECIFIED_ID_FROM_SUBMISSION (11)",
|
|
321
|
+
related_field: "policies[].write_guard[].data_from_submission",
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
id: "REP_C_08",
|
|
325
|
+
name: "hasSubmissionSettings checks both submission fields (P1-1)",
|
|
326
|
+
description: "SDK hasSubmissionSettings helper must check BOTH id_from_submission AND data_from_submission to " +
|
|
327
|
+
"correctly route Mode 5 (id_data_mixed_with_passport).",
|
|
328
|
+
validation_logic: "hasSubmissionSettings = (id_from_submission != null) || (data_from_submission != null)",
|
|
329
|
+
failure_message: "Mode 5 routing missed if only id_from_submission is checked (P1-1 fix)",
|
|
330
|
+
related_field: "policies[].write_guard",
|
|
331
|
+
},
|
|
332
|
+
];
|
|
333
|
+
function normalizeIdFrom(v) {
|
|
334
|
+
if (typeof v === "number")
|
|
335
|
+
return v;
|
|
336
|
+
const lower = String(v).toLowerCase();
|
|
337
|
+
if (lower === "none")
|
|
338
|
+
return 0;
|
|
339
|
+
if (lower === "clock")
|
|
340
|
+
return 1;
|
|
341
|
+
if (lower === "signer")
|
|
342
|
+
return 2;
|
|
343
|
+
const parsed = Number(v);
|
|
344
|
+
return Number.isNaN(parsed) ? -1 : parsed;
|
|
345
|
+
}
|
|
346
|
+
export function explainRepository(input) {
|
|
347
|
+
const warnings = [];
|
|
348
|
+
const recommendations = [];
|
|
349
|
+
const routingModes = [];
|
|
350
|
+
let rD1Violations = 0;
|
|
351
|
+
let rD2Violations = 0;
|
|
352
|
+
let p11Correct = true;
|
|
353
|
+
let p12Recognized = true;
|
|
354
|
+
if (input.policies) {
|
|
355
|
+
for (const p of input.policies) {
|
|
356
|
+
const idFrom = normalizeIdFrom(p.id_from);
|
|
357
|
+
if (idFrom < 0 || idFrom > 2) {
|
|
358
|
+
p12Recognized = false;
|
|
359
|
+
warnings.push(`Policy "${p.name}": id_from="${p.id_from}" not recognized (P1-2 parseIdFrom)`);
|
|
360
|
+
}
|
|
361
|
+
if (idFrom === 0 && p.write_guard_count === 0) {
|
|
362
|
+
rD1Violations++;
|
|
363
|
+
warnings.push(`Policy "${p.name}": id_from=None + empty write_guard violates R-D-1 (E_POLICY_WRITE_GUARD_REQUIRED=22)`);
|
|
364
|
+
}
|
|
365
|
+
if ((idFrom === 1 || idFrom === 2) && p.has_id_from_submission) {
|
|
366
|
+
rD1Violations++;
|
|
367
|
+
warnings.push(`Policy "${p.name}": id_from=Clock/Signer + id_from_submission set violates R-D-1 (E_POLICY_ID_FROM_SUBMISSION_FORBIDDEN=23)`);
|
|
368
|
+
}
|
|
369
|
+
if (input.is_data_remove_with_passport && p.has_data_from_submission) {
|
|
370
|
+
rD2Violations++;
|
|
371
|
+
warnings.push(`Policy "${p.name}": data_from_submission set but used in id_data_remove_with_passport violates R-D-2`);
|
|
372
|
+
}
|
|
373
|
+
if (idFrom === 0 && (p.has_id_from_submission || p.has_data_from_submission)) {
|
|
374
|
+
if (p.has_data_from_submission && !p.has_id_from_submission) {
|
|
375
|
+
routingModes.push(`${p.name}: Mode 5 (data_from_submission only) — SDK hasSubmissionSettings correctly detects [P1-1]`);
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
routingModes.push(`${p.name}: Mode 5 (id_data_mixed_with_passport)`);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
else if (idFrom === 0 && p.write_guard_count > 0) {
|
|
382
|
+
routingModes.push(`${p.name}: Mode 4 (Guard + caller id, id_data_with_passport)`);
|
|
383
|
+
}
|
|
384
|
+
else if ((idFrom === 1 || idFrom === 2) && p.write_guard_count > 0) {
|
|
385
|
+
routingModes.push(`${p.name}: Mode 2b (auto-id + guard, data_when_id_from_set_with_passport)`);
|
|
386
|
+
}
|
|
387
|
+
else if (idFrom === 1) {
|
|
388
|
+
routingModes.push(`${p.name}: Mode 1 (Clock-routed, data_when_id_from_set)`);
|
|
389
|
+
}
|
|
390
|
+
else if (idFrom === 2) {
|
|
391
|
+
routingModes.push(`${p.name}: Mode 2 (Signer-routed, data_when_id_from_set)`);
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
routingModes.push(`${p.name}: unknown/invalid routing`);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (rD1Violations > 0)
|
|
399
|
+
recommendations.push("Fix R-D-1 violations: align write_guard presence with id_from");
|
|
400
|
+
if (rD2Violations > 0)
|
|
401
|
+
recommendations.push("Fix R-D-2 violations: remove data_from_submission for id_data_remove_with_passport");
|
|
402
|
+
if (!p12Recognized)
|
|
403
|
+
recommendations.push("Use recognized id_from values: 0/1/2 or 'None'/'Clock'/'Signer'");
|
|
404
|
+
if (routingModes.length === 0)
|
|
405
|
+
recommendations.push("Define at least one policy to enable data operations");
|
|
406
|
+
const rD1Status = rD1Violations === 0 ? "PASS (all policies satisfy R-D-1)" : `FAIL (${rD1Violations} violation(s))`;
|
|
407
|
+
const rD2Status = rD2Violations === 0 ? "PASS (no R-D-2 violations)" : `FAIL (${rD2Violations} violation(s))`;
|
|
408
|
+
const p11Status = p11Correct ? "PASS (hasSubmissionSettings checks both fields)" : "FAIL";
|
|
409
|
+
const p12Status = p12Recognized ? "PASS (all id_from values recognized)" : "FAIL (unrecognized id_from values)";
|
|
410
|
+
const summary = `Repository has ${input.policies?.length ?? 0} policy(ies). ` +
|
|
411
|
+
`R-D-1: ${rD1Status}. R-D-2: ${rD2Status}. P1-1: ${p11Status}. P1-2: ${p12Status}.`;
|
|
412
|
+
return {
|
|
413
|
+
summary,
|
|
414
|
+
routing_modes: routingModes,
|
|
415
|
+
r_d_1_status: rD1Status,
|
|
416
|
+
r_d_2_status: rD2Status,
|
|
417
|
+
p1_1_status: p11Status,
|
|
418
|
+
p1_2_status: p12Status,
|
|
419
|
+
warnings,
|
|
420
|
+
recommendations,
|
|
421
|
+
};
|
|
422
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type ResourceRiskLevel = "CRITICAL" | "HIGH" | "MEDIUM" | "LOW" | "INFO";
|
|
2
|
+
export type ResourceRiskCategory = "structural" | "semantic" | "lifecycle" | "permission" | "knowledge";
|
|
3
|
+
export type ResourceStakeholder = "owner" | "caller" | "system";
|
|
4
|
+
export interface ResourceRisk {
|
|
5
|
+
id: string;
|
|
6
|
+
level: ResourceRiskLevel;
|
|
7
|
+
category: ResourceRiskCategory;
|
|
8
|
+
title: string;
|
|
9
|
+
description: string;
|
|
10
|
+
affected_stakeholders: ResourceStakeholder[];
|
|
11
|
+
scenario: string;
|
|
12
|
+
mitigation: string;
|
|
13
|
+
evidence?: string;
|
|
14
|
+
related_move_error?: string;
|
|
15
|
+
auto_fixable: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface ResourceRiskCheckContext {
|
|
18
|
+
tags_count?: number;
|
|
19
|
+
expects_resource_permission?: boolean;
|
|
20
|
+
tag_set_return_ignored?: boolean;
|
|
21
|
+
is_destroy?: boolean;
|
|
22
|
+
expects_tag_events?: boolean;
|
|
23
|
+
references_dead_switch?: boolean;
|
|
24
|
+
constants_synced?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare const RESOURCE_RISK_RULES: {
|
|
27
|
+
rule: ResourceRisk;
|
|
28
|
+
check: (ctx: ResourceRiskCheckContext) => ResourceRisk | null;
|
|
29
|
+
}[];
|
|
30
|
+
export declare const RESOURCE_RISK_VERSION = "1.0.0";
|
|
31
|
+
export declare function checkResourceRisks(ctx: ResourceRiskCheckContext): ResourceRisk[];
|
|
32
|
+
export declare function getResourceRiskById(id: string): ResourceRisk | undefined;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { MAX_TAGS_COUNT } from "@wowok/wowok";
|
|
2
|
+
const R_R_01 = {
|
|
3
|
+
rule: {
|
|
4
|
+
id: "R-RESOURCE-01",
|
|
5
|
+
level: "LOW",
|
|
6
|
+
category: "permission",
|
|
7
|
+
title: "Resource has no Permission — relies entirely on caller-side gating",
|
|
8
|
+
description: "Resource does not associate with a Permission object. All functions are " +
|
|
9
|
+
"public(package) (new/destroy/transfer/tag_set/tag_unset) or public " +
|
|
10
|
+
"(add_object_tags/remove_object_tags/remove_object) — there is no on-chain permission " +
|
|
11
|
+
"check. Access control is delegated to the calling module (Personal, Entity). A " +
|
|
12
|
+
"caller that forgets to enforce its own permission check would let any address mutate " +
|
|
13
|
+
"tags.",
|
|
14
|
+
affected_stakeholders: ["owner", "caller"],
|
|
15
|
+
scenario: "Personal/Entity forgets to gate add_object_tags behind its own permission check",
|
|
16
|
+
mitigation: "Callers (Personal, Entity) MUST enforce their own permission checks before invoking " +
|
|
17
|
+
"Resource functions. Audit the call sites in Personal/Entity to confirm gating.",
|
|
18
|
+
auto_fixable: false,
|
|
19
|
+
},
|
|
20
|
+
check: (ctx) => {
|
|
21
|
+
if (!ctx.expects_resource_permission)
|
|
22
|
+
return null;
|
|
23
|
+
return { ...R_R_01.rule, evidence: "expects_resource_permission=true (Resource has none)" };
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
const R_R_02 = {
|
|
27
|
+
rule: {
|
|
28
|
+
id: "R-RESOURCE-02",
|
|
29
|
+
level: "MEDIUM",
|
|
30
|
+
category: "semantic",
|
|
31
|
+
title: "Tag mutations emit no events — external indexers must poll",
|
|
32
|
+
description: "add_object_tags / remove_object_tags / remove_object do not emit events " +
|
|
33
|
+
"(resource.move:89-145). External indexers cannot rely on an event stream to track " +
|
|
34
|
+
"tag changes; they must poll the ParentTable field. This complicates real-time " +
|
|
35
|
+
"notification and consistency.",
|
|
36
|
+
affected_stakeholders: ["owner", "caller"],
|
|
37
|
+
scenario: "Indexer expects a TagAddedEvent but none is emitted; UI fails to refresh",
|
|
38
|
+
mitigation: "External indexers should poll Resource.table on a cadence. Do not build critical UX " +
|
|
39
|
+
"on tag event streams until events are added in a future version.",
|
|
40
|
+
auto_fixable: false,
|
|
41
|
+
},
|
|
42
|
+
check: (ctx) => {
|
|
43
|
+
if (!ctx.expects_tag_events)
|
|
44
|
+
return null;
|
|
45
|
+
return { ...R_R_02.rule, evidence: "expects_tag_events=true (no events emitted)" };
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
const R_R_03 = {
|
|
49
|
+
rule: {
|
|
50
|
+
id: "R-RESOURCE-03",
|
|
51
|
+
level: "LOW",
|
|
52
|
+
category: "structural",
|
|
53
|
+
title: `MAX_TAGS_COUNT=${MAX_TAGS_COUNT} permissive — storage cost`,
|
|
54
|
+
description: `A single object's AddressTag.tags vector may hold up to MAX_TAGS_COUNT=${MAX_TAGS_COUNT} ` +
|
|
55
|
+
`entries (resource.move:9). The limit aborts with E_TAGS_COUNT_EXCEEDED (1) only at the ` +
|
|
56
|
+
`boundary. 100 tags per object is generous; loading all tags on every read increases ` +
|
|
57
|
+
`gas and storage cost.`,
|
|
58
|
+
affected_stakeholders: ["owner"],
|
|
59
|
+
scenario: "Caller adds 100 tags to a single object",
|
|
60
|
+
mitigation: "Business layer should self-limit tag count well below 100. For heavy tagging, " +
|
|
61
|
+
"shard across multiple Resource objects or store bulk tags off-chain.",
|
|
62
|
+
related_move_error: "E_TAGS_COUNT_EXCEEDED (1)",
|
|
63
|
+
auto_fixable: false,
|
|
64
|
+
},
|
|
65
|
+
check: (ctx) => {
|
|
66
|
+
if (ctx.tags_count === undefined)
|
|
67
|
+
return null;
|
|
68
|
+
if (ctx.tags_count < MAX_TAGS_COUNT)
|
|
69
|
+
return null;
|
|
70
|
+
return { ...R_R_03.rule, evidence: `tags_count=${ctx.tags_count}, limit=${MAX_TAGS_COUNT}` };
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
const R_R_04 = {
|
|
74
|
+
rule: {
|
|
75
|
+
id: "R-RESOURCE-04",
|
|
76
|
+
level: "LOW",
|
|
77
|
+
category: "lifecycle",
|
|
78
|
+
title: "destroy is irreversible — no recovery mechanism",
|
|
79
|
+
description: "Resource.destroy(resource) (resource.move:38) deletes the object and its ParentTable " +
|
|
80
|
+
"in place. There is no archive, no event, and no rollback. Once destroyed, the object " +
|
|
81
|
+
"ID is permanently invalid and all tags are lost.",
|
|
82
|
+
affected_stakeholders: ["owner"],
|
|
83
|
+
scenario: "Caller destroys a Resource that is still referenced by Personal/Entity",
|
|
84
|
+
mitigation: "Confirm no live references exist before calling destroy. SDK should refuse to destroy " +
|
|
85
|
+
"a Resource whose owner address is still referenced by Personal.mark or Entity.resource.",
|
|
86
|
+
auto_fixable: false,
|
|
87
|
+
},
|
|
88
|
+
check: (ctx) => {
|
|
89
|
+
if (!ctx.is_destroy)
|
|
90
|
+
return null;
|
|
91
|
+
return { ...R_R_04.rule, evidence: "is_destroy=true (irreversible)" };
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
const R_R_05 = {
|
|
95
|
+
rule: {
|
|
96
|
+
id: "R-RESOURCE-05",
|
|
97
|
+
level: "MEDIUM",
|
|
98
|
+
category: "semantic",
|
|
99
|
+
title: "tag_set returns bool — SDK may ignore the 'already exists' signal",
|
|
100
|
+
description: "tag_set(resource, object, name) returns bool: true if a new tag was added, false if " +
|
|
101
|
+
"the tag already existed (resource.move:47-58). If the SDK ignores the return value, " +
|
|
102
|
+
"callers cannot distinguish 'newly added' from 'duplicate silently skipped'. This " +
|
|
103
|
+
"masks intent and complicates idempotency reasoning.",
|
|
104
|
+
affected_stakeholders: ["caller"],
|
|
105
|
+
scenario: "SDK treats tag_set as void; caller assumes tag was added when it was a duplicate",
|
|
106
|
+
mitigation: "SDK should expose tag_set's bool return value to the caller. UI should show 'tag " +
|
|
107
|
+
"already existed' when false is returned.",
|
|
108
|
+
auto_fixable: true,
|
|
109
|
+
},
|
|
110
|
+
check: (ctx) => {
|
|
111
|
+
if (!ctx.tag_set_return_ignored)
|
|
112
|
+
return null;
|
|
113
|
+
return { ...R_R_05.rule, evidence: "tag_set_return_ignored=true (duplicate not surfaced)" };
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
const R_R_06 = {
|
|
117
|
+
rule: {
|
|
118
|
+
id: "R-RESOURCE-06",
|
|
119
|
+
level: "LOW",
|
|
120
|
+
category: "semantic",
|
|
121
|
+
title: "Commented-out switch function (resource.move:71-86) — feature may be intended",
|
|
122
|
+
description: "resource.move:71-86 contains a switch function that is fully commented out. The " +
|
|
123
|
+
"intended behavior is unclear — it may be a planned feature (e.g. bulk tag operations) " +
|
|
124
|
+
"that was disabled. Referencing it as if it were live would silently fail.",
|
|
125
|
+
affected_stakeholders: ["system"],
|
|
126
|
+
scenario: "Developer reads the commented switch and assumes it is callable",
|
|
127
|
+
mitigation: "Confirm with the package maintainers whether the switch should be enabled or removed. " +
|
|
128
|
+
"Do not reference it in SDK or MCP code.",
|
|
129
|
+
auto_fixable: false,
|
|
130
|
+
},
|
|
131
|
+
check: (ctx) => {
|
|
132
|
+
if (!ctx.references_dead_switch)
|
|
133
|
+
return null;
|
|
134
|
+
return { ...R_R_06.rule, evidence: "references_dead_switch=true (commented out in Move)" };
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
export const RESOURCE_RISK_RULES = [
|
|
138
|
+
R_R_01,
|
|
139
|
+
R_R_02,
|
|
140
|
+
R_R_03,
|
|
141
|
+
R_R_04,
|
|
142
|
+
R_R_05,
|
|
143
|
+
R_R_06,
|
|
144
|
+
];
|
|
145
|
+
export const RESOURCE_RISK_VERSION = "1.0.0";
|
|
146
|
+
export function checkResourceRisks(ctx) {
|
|
147
|
+
const risks = [];
|
|
148
|
+
for (const rule of RESOURCE_RISK_RULES) {
|
|
149
|
+
const r = rule.check(ctx);
|
|
150
|
+
if (r)
|
|
151
|
+
risks.push(r);
|
|
152
|
+
}
|
|
153
|
+
return risks;
|
|
154
|
+
}
|
|
155
|
+
export function getResourceRiskById(id) {
|
|
156
|
+
return RESOURCE_RISK_RULES.find(r => r.rule.id === id)?.rule;
|
|
157
|
+
}
|