@wowok/agent-mcp 2.3.18 → 2.4.3

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.
Files changed (121) hide show
  1. package/dist/customer/industry-risks.js +31 -31
  2. package/dist/customer/order-monitor.js +57 -57
  3. package/dist/customer/order-strategy.js +89 -89
  4. package/dist/customer/post-purchase.js +97 -97
  5. package/dist/customer/reminder-system.js +26 -26
  6. package/dist/customer/risk-assessment.js +46 -46
  7. package/dist/customer/types.d.ts +4 -4
  8. package/dist/customer/types.js +4 -4
  9. package/dist/customer/user-preferences.js +50 -50
  10. package/dist/experience/intent-distill.js +6 -6
  11. package/dist/index.d.ts +2 -2
  12. package/dist/index.js +11 -1624
  13. package/dist/knowledge/acquisition-flywheel.js +64 -64
  14. package/dist/knowledge/arbitration-trust.js +10 -10
  15. package/dist/knowledge/demand-matching.js +8 -8
  16. package/dist/knowledge/dynamic-pricing.js +18 -18
  17. package/dist/knowledge/flywheel-loop.js +11 -11
  18. package/dist/knowledge/glossary.js +22 -22
  19. package/dist/knowledge/guard-ledger.d.ts +1 -1
  20. package/dist/knowledge/guard-ledger.js +145 -104
  21. package/dist/knowledge/guard-lint.d.ts +77 -0
  22. package/dist/knowledge/guard-lint.js +670 -0
  23. package/dist/knowledge/guard-migration.d.ts +48 -0
  24. package/dist/knowledge/guard-migration.js +228 -0
  25. package/dist/knowledge/guard-puzzle.d.ts +109 -14
  26. package/dist/knowledge/guard-puzzle.js +627 -101
  27. package/dist/knowledge/guard-risk.d.ts +10 -1
  28. package/dist/knowledge/guard-risk.js +1634 -292
  29. package/dist/knowledge/guard-templates.d.ts +38 -0
  30. package/dist/knowledge/guard-templates.js +605 -0
  31. package/dist/knowledge/guard-translation.d.ts +14 -2
  32. package/dist/knowledge/guard-translation.js +825 -194
  33. package/dist/knowledge/index.d.ts +8 -4
  34. package/dist/knowledge/index.js +9 -5
  35. package/dist/knowledge/industry-evolution.js +29 -29
  36. package/dist/knowledge/industry-generalizer.js +52 -52
  37. package/dist/knowledge/industry-registry.js +20 -33
  38. package/dist/knowledge/intent-metrics.js +67 -67
  39. package/dist/knowledge/process-model.js +80 -80
  40. package/dist/knowledge/reputation-rules.js +9 -9
  41. package/dist/knowledge/reward-templates.js +51 -51
  42. package/dist/knowledge/safety-rules.js +3 -3
  43. package/dist/knowledge/tool-constraints.js +20 -4
  44. package/dist/knowledge/trust-metrics.js +26 -26
  45. package/dist/project/graph.d.ts +1 -0
  46. package/dist/project/graph.js +27 -1
  47. package/dist/project/index.d.ts +1 -0
  48. package/dist/project/index.js +39 -2
  49. package/dist/project/namespace.d.ts +11 -1
  50. package/dist/project/namespace.js +27 -2
  51. package/dist/project/query.d.ts +2 -0
  52. package/dist/project/query.js +56 -15
  53. package/dist/rules.d.ts +12 -0
  54. package/dist/rules.js +9 -0
  55. package/dist/schema/call/allocation.d.ts +10 -10
  56. package/dist/schema/call/base.js +19 -19
  57. package/dist/schema/call/bridge.d.ts +32 -32
  58. package/dist/schema/call/demand.d.ts +84 -84
  59. package/dist/schema/call/guard.d.ts +153 -0
  60. package/dist/schema/call/guard.js +50 -0
  61. package/dist/schema/call/machine.d.ts +38 -38
  62. package/dist/schema/call/permission.d.ts +78 -78
  63. package/dist/schema/call/repository.d.ts +22 -22
  64. package/dist/schema/call/semantic.js +229 -25
  65. package/dist/schema/call/service.d.ts +7 -7
  66. package/dist/schema/local/wip.d.ts +39 -19
  67. package/dist/schema/local/wip.js +5 -5
  68. package/dist/schema/messenger/index.d.ts +26 -26
  69. package/dist/schema/messenger/index.js +2 -2
  70. package/dist/schema/operations.d.ts +270 -192
  71. package/dist/schema/query/index.d.ts +184 -184
  72. package/dist/schema/query/index.js +15 -9
  73. package/dist/schema/trust/index.d.ts +4 -4
  74. package/dist/schema/utils/guard-parser.js +4 -4
  75. package/dist/schema/utils/guard-query-utils.d.ts +7 -0
  76. package/dist/schema/utils/guard-query-utils.js +14 -1
  77. package/dist/schema/utils/node-parser.js +14 -14
  78. package/dist/schemas/bridge_operation.output.json +15 -15
  79. package/dist/schemas/index.json +1 -1
  80. package/dist/schemas/messenger_operation.output.json +18 -16
  81. package/dist/schemas/onchain_events.output.json +15 -15
  82. package/dist/schemas/onchain_operations.output.json +16 -16
  83. package/dist/schemas/onchain_operations.schema.json +11 -20
  84. package/dist/schemas/onchain_operations_allocation.schema.json +7 -10
  85. package/dist/schemas/onchain_operations_machine.schema.json +2 -5
  86. package/dist/schemas/onchain_operations_service.schema.json +2 -5
  87. package/dist/schemas/onchain_table_data.output.json +20 -26
  88. package/dist/schemas/wip_file.output.json +24 -1
  89. package/dist/tools/handlers/bridge.d.ts +1 -0
  90. package/dist/tools/handlers/bridge.js +1 -0
  91. package/dist/tools/handlers/config.d.ts +2 -0
  92. package/dist/tools/handlers/config.js +71 -0
  93. package/dist/tools/handlers/file-export.d.ts +3 -0
  94. package/dist/tools/handlers/file-export.js +90 -0
  95. package/dist/tools/handlers/local.d.ts +30 -0
  96. package/dist/tools/handlers/local.js +27 -0
  97. package/dist/tools/handlers/messenger.d.ts +16 -0
  98. package/dist/tools/handlers/messenger.js +187 -0
  99. package/dist/tools/handlers/onchain.d.ts +2 -0
  100. package/dist/tools/handlers/onchain.js +246 -0
  101. package/dist/tools/handlers/project.d.ts +2 -0
  102. package/dist/tools/handlers/project.js +53 -0
  103. package/dist/tools/handlers/query.d.ts +5 -0
  104. package/dist/tools/handlers/query.js +256 -0
  105. package/dist/tools/handlers/schema-query.d.ts +2 -0
  106. package/dist/tools/handlers/schema-query.js +92 -0
  107. package/dist/tools/handlers/trust.d.ts +2 -0
  108. package/dist/tools/handlers/trust.js +194 -0
  109. package/dist/tools/handlers/wip.d.ts +2 -0
  110. package/dist/tools/handlers/wip.js +44 -0
  111. package/dist/tools/index.d.ts +13 -0
  112. package/dist/tools/index.js +479 -0
  113. package/dist/tools/rules-hook.d.ts +2 -0
  114. package/dist/tools/rules-hook.js +22 -0
  115. package/dist/tools/shared.d.ts +29 -0
  116. package/dist/tools/shared.js +130 -0
  117. package/dist/tools/types.d.ts +35 -0
  118. package/dist/tools/types.js +1 -0
  119. package/dist/tools/wrap.d.ts +6 -0
  120. package/dist/tools/wrap.js +55 -0
  121. package/package.json +19 -5
@@ -0,0 +1,38 @@
1
+ export type TemplateParamType = "address" | "string" | "number" | "boolean" | "vec_address";
2
+ export interface GuardTemplateParam {
3
+ name: string;
4
+ type: TemplateParamType;
5
+ description: string;
6
+ required: boolean;
7
+ default?: string;
8
+ constraint?: string;
9
+ }
10
+ export interface GuardTemplate {
11
+ id: string;
12
+ scene_id: string;
13
+ name: string;
14
+ description: string;
15
+ recommended_patterns: string[];
16
+ parameters: GuardTemplateParam[];
17
+ example_table: object;
18
+ example_root: object;
19
+ applicable_industries: string[];
20
+ relevant_risks: string[];
21
+ creation_notes: string[];
22
+ example_use_case: string;
23
+ verifier_constraint_level?: "level1_strict" | "level2_identity_set" | "level3_scene_combined";
24
+ }
25
+ export declare const GUARD_TEMPLATES: GuardTemplate[];
26
+ export declare function getTemplatesByScene(sceneId: string): GuardTemplate[];
27
+ export declare function getTemplateById(templateId: string): GuardTemplate | undefined;
28
+ export declare function getTemplatesByIndustry(industry: string): GuardTemplate[];
29
+ export declare function getTemplatesByPattern(patternId: string): GuardTemplate[];
30
+ export declare function listGuardTemplates(): GuardTemplate[];
31
+ export declare function suggestTemplateForScene(sceneId: string): GuardTemplate | undefined;
32
+ export declare function getTemplateParameters(templateId: string): GuardTemplateParam[];
33
+ export declare function validateTemplateParams(templateId: string, params: Record<string, unknown>): {
34
+ valid: boolean;
35
+ missing: string[];
36
+ };
37
+ export declare const GUARD_TEMPLATES_VERSION = "1.0.0";
38
+ export declare const GUARD_TEMPLATES_COUNT: number;
@@ -0,0 +1,605 @@
1
+ export const GUARD_TEMPLATES = [
2
+ {
3
+ id: "tpl_buy_guard_whitelist",
4
+ scene_id: "service_buy_guard",
5
+ name: "Whitelist purchase validation",
6
+ description: "Only addresses in the whitelist can purchase the service. Suitable for limited-time sales, VIP exclusives, internal testing eligibility, etc.",
7
+ recommended_patterns: ["P04", "P03"],
8
+ parameters: [
9
+ { name: "whitelist", type: "vec_address", description: "List of authorized addresses", required: true,
10
+ constraint: "Each address must be valid and unique" },
11
+ { name: "service_name", type: "string", description: "Service object name (used for circular references)", required: false,
12
+ constraint: "If P16 circular reference is used, a name must be provided rather than an address" },
13
+ ],
14
+ example_table: [
15
+ { identifier: 0, b_submission: false, value_type: "Vec<Address>", value: "${whitelist}", name: "Authorized purchase whitelist" },
16
+ ],
17
+ example_root: {
18
+ type: "vec_contains_address",
19
+ vec: { type: "identifier", identifier: 0 },
20
+ target: { type: "context", context: "Signer" },
21
+ },
22
+ applicable_industries: ["rental", "ecommerce", "education", "travel", "subscription"],
23
+ relevant_risks: ["R-C1-01", "R-C3-01", "R-C4-01"],
24
+ creation_notes: [
25
+ "Updating the whitelist requires rebuilding the Guard (buy_guard is iterable)",
26
+ "If the Service is already published, the table can use the address directly; otherwise use the name (P16 circular reference)",
27
+ ],
28
+ example_use_case: "Internal testing phase for camera equipment rental, allowing only the first 50 seed users to place rental orders.",
29
+ verifier_constraint_level: "level2_identity_set",
30
+ },
31
+ {
32
+ id: "tpl_allocator_threshold",
33
+ scene_id: "service_order_allocators_guard",
34
+ name: "Allocation amount threshold validation",
35
+ description: "Selects different allocation strategies based on the order amount. When the amount exceeds the threshold, advanced allocation is used; otherwise, default allocation applies.",
36
+ recommended_patterns: ["P02", "P10"],
37
+ parameters: [
38
+ { name: "threshold", type: "number", description: "Allocation threshold (unit: smallest precision)", required: true,
39
+ constraint: "Must be > 0; a reasonable range is recommended to avoid boundary gaming" },
40
+ { name: "service_name", type: "string", description: "Service object name", required: true },
41
+ ],
42
+ example_table: [
43
+ { identifier: 0, b_submission: false, value_type: "Address", value: "${service_name}", name: "Service object" },
44
+ { identifier: 1, b_submission: false, value_type: "U64", value: "${threshold}", name: "Allocation threshold" },
45
+ ],
46
+ example_root: {
47
+ type: "logic_as_u256_greater",
48
+ left: { type: "query", query: "order.amount", object: { identifier: 0 }, parameters: [] },
49
+ right: { type: "identifier", identifier: 1 },
50
+ },
51
+ applicable_industries: ["ecommerce", "rental", "education", "travel"],
52
+ relevant_risks: ["R-X1-01", "R-X1-05", "R-X1-08"],
53
+ creation_notes: [
54
+ "order_allocators cannot be modified after binding (immutable after publish)",
55
+ "First-match-wins mechanism: multiple allocators are matched in order; the first one that passes executes",
56
+ "Threshold boundary must be tested: behavior when exactly equal to the threshold (> vs >=)",
57
+ ],
58
+ example_use_case: "E-commerce platform: order amount > 1000 WOW triggers 3-way allocation (platform + merchant + logistics); otherwise 2-way allocation (platform + merchant).",
59
+ verifier_constraint_level: "level3_scene_combined",
60
+ },
61
+ {
62
+ id: "tpl_allocator_treasury_personal",
63
+ scene_id: "service_order_allocators_guard",
64
+ name: "Treasury + personal address allocation (Entity sharing)",
65
+ description: "2 allocators representing 2 merchant collection approaches: (1) named Treasury address for public fund aggregation, (2) fixed personal address. " +
66
+ "Uses sharing.who=Entity so funds always flow to the legitimate recipient regardless of caller — no Signer binding needed in Guard. " +
67
+ "Guards verify the order is at the Complete node + belongs to the service (project binding).",
68
+ recommended_patterns: ["P02", "P10", "P16"],
69
+ parameters: [
70
+ { name: "service_name", type: "string", description: "Service object name (circular ref via P16 — resolved after Service publish)", required: true,
71
+ constraint: "Must be a name, not an address (the Service is not yet published when the Guard is created)" },
72
+ { name: "complete_node_name", type: "string", description: "Expected node name that triggers allocation (e.g. 'Complete')", required: true,
73
+ default: "Complete", constraint: "Must exactly match the Machine node name (case-sensitive)" },
74
+ { name: "treasury_name", type: "string", description: "Named Treasury object (created with the Service's permission)", required: true,
75
+ constraint: "Treasury must be created before the Service; use the SAME permission as the Service for consistency" },
76
+ { name: "personal_address", type: "address", description: "Fixed personal collection address (e.g. the permission creator's address)", required: true },
77
+ ],
78
+ example_table: [
79
+ { identifier: 0, b_submission: true, value_type: "Address", object_type: "Order",
80
+ name: "order_id (Order object submitted at runtime)" },
81
+ { identifier: 1, b_submission: false, value_type: "String", value: "${complete_node_name}",
82
+ name: "Expected Complete node name (case-sensitive)" },
83
+ { identifier: 2, b_submission: false, value_type: "Address", value: "${service_name}",
84
+ name: "Service object (project binding, circular ref via name)" },
85
+ ],
86
+ example_root: {
87
+ type: "logic_and",
88
+ nodes: [
89
+ {
90
+ type: "logic_equal",
91
+ nodes: [
92
+ { type: "query", query: "progress.current", object: { identifier: 0, convert_witness: "OrderProgress" }, parameters: [] },
93
+ { type: "identifier", identifier: 1 },
94
+ ],
95
+ },
96
+ {
97
+ type: "logic_equal",
98
+ nodes: [
99
+ { type: "query", query: "order.service", object: { identifier: 0 }, parameters: [] },
100
+ { type: "identifier", identifier: 2 },
101
+ ],
102
+ },
103
+ ],
104
+ },
105
+ applicable_industries: ["insurance", "ecommerce", "travel", "rental", "subscription"],
106
+ relevant_risks: ["R-C3-05", "R-C3-06", "R-X1-05", "R-X1-01"],
107
+ creation_notes: [
108
+ "2 Guard objects with IDENTICAL root/table but DIFFERENT descriptions (allocators require unique guard addresses — no two allocators may reference the same Guard).",
109
+ "sharing.who=Entity (Treasury/personal) — no Signer binding needed in the Guard (R-C3-06 safe).",
110
+ "First-match-wins: only the first allocator (Treasury) executes; the personal allocator is an alternative (swap the allocators order to activate personal collection).",
111
+ "Treasury should be created with the SAME permission as the Service (permission consistency — different permissions = minor risk).",
112
+ "order.service binding (query 1563) suppresses R-C3-05 (cross-project bypass prevents premature allocation on foreign orders).",
113
+ "order_allocators is immutable after Service publish — verify the Guard logic and sharing config before publishing.",
114
+ ],
115
+ example_use_case: "Insurance service: after a claim reaches the Complete node, order funds are allocated to the insurance Treasury " +
116
+ "(approach 1, for operational fund aggregation) or to the provider's personal address (approach 2, for direct income).",
117
+ verifier_constraint_level: "level3_scene_combined",
118
+ },
119
+ {
120
+ id: "tpl_allocator_identity_set_order_holder",
121
+ scene_id: "service_order_allocators_guard",
122
+ name: "Order-holder identity-set allocation (Level 2)",
123
+ description: "Level 2 identity-set binding: Signer is order.owner (1562, Address) OR order.agent (1567, Bool with [Signer] param). " +
124
+ "Demonstrates the mixed return-type construction pattern — Address-returning queries are wrapped in logic_equal, " +
125
+ "while Bool-returning queries (suffix 'has') are used directly as logic_or children. " +
126
+ "Combined with order.service binding (R-C3-05) for cross-service theft prevention. " +
127
+ "Use when either the order owner or an authorized agent should be able to trigger allocation (e.g. refund to caller).",
128
+ recommended_patterns: ["P02", "P10", "P16"],
129
+ parameters: [
130
+ { name: "service_name", type: "string", description: "Service object name (circular ref via P16)", required: true,
131
+ constraint: "Must be a name, not an address (the Service is not yet published when the Guard is created)" },
132
+ ],
133
+ example_table: [
134
+ { identifier: 0, b_submission: true, value_type: "Address", object_type: "Order",
135
+ name: "order_id (Order object submitted at runtime)" },
136
+ { identifier: 1, b_submission: false, value_type: "Address", value: "${service_name}",
137
+ name: "Service object (project binding, circular ref via name)" },
138
+ ],
139
+ example_root: {
140
+ type: "logic_and",
141
+ nodes: [
142
+ {
143
+ type: "logic_or",
144
+ nodes: [
145
+ {
146
+ type: "logic_equal",
147
+ nodes: [
148
+ { type: "query", query: "order.owner", object: { identifier: 0 }, parameters: [] },
149
+ { type: "context", context: "Signer" },
150
+ ],
151
+ },
152
+ {
153
+ type: "query",
154
+ query: "order.agent has",
155
+ object: { identifier: 0 },
156
+ parameters: [{ type: "context", context: "Signer" }],
157
+ },
158
+ ],
159
+ },
160
+ {
161
+ type: "logic_equal",
162
+ nodes: [
163
+ { type: "query", query: "order.service", object: { identifier: 0 }, parameters: [] },
164
+ { type: "identifier", identifier: 1 },
165
+ ],
166
+ },
167
+ ],
168
+ },
169
+ applicable_industries: ["ecommerce", "rental", "travel", "subscription"],
170
+ relevant_risks: ["R-C3-01", "R-C3-05", "R-C3-06", "R-C4-04"],
171
+ creation_notes: [
172
+ "MIXED RETURN-TYPE CONSTRUCTION (key Level 2 pattern): query 1562 (order.owner) returns Address → wrap in logic_equal with context(Signer); query 1567 (order.agent has) returns Bool → use directly as logic_or child with parameters: [context(Signer)].",
173
+ "logic_or wrapping of the Signer check suppresses R-C4-04 (Level 1 strict binding convenience warning) — this is the recommended Level 2 alternative.",
174
+ "Use this pattern when sharing.who=Signer (funds flow to caller) AND either the owner or an agent should be authorized to trigger allocation.",
175
+ "order.service binding (query 1563) suppresses R-C3-05 (cross-project bypass).",
176
+ "If agents are not needed, use the simpler Level 2 dynamic pattern: logic_equal[query(1562), context(Signer)] without logic_or.",
177
+ ],
178
+ example_use_case: "Refund allocation: when an order is cancelled, either the order owner or an authorized agent can trigger the refund. " +
179
+ "The Guard verifies Signer is order.owner OR order.agent, and that the order belongs to this service.",
180
+ verifier_constraint_level: "level2_identity_set",
181
+ },
182
+ {
183
+ id: "tpl_allocator_identity_set_service_provider_dynamic",
184
+ scene_id: "service_order_allocators_guard",
185
+ name: "Service-provider identity-set allocation with dynamic permission (Level 2)",
186
+ description: "Level 2 identity-set binding with DYNAMIC permission address: Signer is permission.owner (1002, Address) OR " +
187
+ "has admin (1004, Bool with [Signer] param). The permission address is submitted by the caller and verified " +
188
+ "against service.permission (1488) — this survives permission rotation without rebuilding the Guard. " +
189
+ "Use when the Service may rotate its permission (like a company changing its board) and a static permission " +
190
+ "address would break the Guard.",
191
+ recommended_patterns: ["P02", "P10", "P16"],
192
+ parameters: [
193
+ { name: "service_name", type: "string", description: "Service object name (circular ref via P16)", required: true,
194
+ constraint: "Must be a name, not an address (the Service is not yet published when the Guard is created)" },
195
+ ],
196
+ example_table: [
197
+ { identifier: 0, b_submission: true, value_type: "Address", object_type: "Order",
198
+ name: "order_id (Order object submitted at runtime)" },
199
+ { identifier: 1, b_submission: false, value_type: "Address", value: "${service_name}",
200
+ name: "Service object (project binding, circular ref via name)" },
201
+ { identifier: 2, b_submission: true, value_type: "Address", object_type: "Permission",
202
+ name: "permission_id (Permission object submitted by caller — must equal service.permission)" },
203
+ ],
204
+ example_root: {
205
+ type: "logic_and",
206
+ nodes: [
207
+ {
208
+ type: "logic_equal",
209
+ nodes: [
210
+ { type: "query", query: "order.service", object: { identifier: 0 }, parameters: [] },
211
+ { type: "identifier", identifier: 1 },
212
+ ],
213
+ },
214
+ {
215
+ type: "logic_equal",
216
+ nodes: [
217
+ { type: "query", query: "service.permission", object: { identifier: 1 }, parameters: [] },
218
+ { type: "identifier", identifier: 2 },
219
+ ],
220
+ },
221
+ {
222
+ type: "logic_or",
223
+ nodes: [
224
+ {
225
+ type: "logic_equal",
226
+ nodes: [
227
+ { type: "query", query: "permission.owner", object: { identifier: 2 }, parameters: [] },
228
+ { type: "context", context: "Signer" },
229
+ ],
230
+ },
231
+ {
232
+ type: "query",
233
+ query: "permission.admin has",
234
+ object: { identifier: 2 },
235
+ parameters: [{ type: "context", context: "Signer" }],
236
+ },
237
+ ],
238
+ },
239
+ ],
240
+ },
241
+ applicable_industries: ["ecommerce", "rental", "insurance", "travel", "subscription"],
242
+ relevant_risks: ["R-C3-01", "R-C3-05", "R-C3-06", "R-C4-04"],
243
+ creation_notes: [
244
+ "DYNAMIC PERMISSION VERIFICATION (key pattern): caller submits a Permission address (identifier 2); Guard verifies query(1488: service.permission) == submitted permission, then checks 1002/1004 against the submitted permission. This survives permission rotation — if the Service changes its permission, the Guard still works without rebuilding.",
245
+ "MIXED RETURN-TYPE CONSTRUCTION: query 1002 (permission.owner) returns Address → wrap in logic_equal; query 1004 (permission.admin has) returns Bool → use directly as logic_or child with parameters: [context(Signer)].",
246
+ "logic_or wrapping of the Signer check suppresses R-C4-04 (Level 1 strict binding convenience warning).",
247
+ "THREE conditions in logic_and: (1) order.service binding (R-C3-05), (2) dynamic permission verification, (3) identity set (owner OR admin).",
248
+ "Static permission alternative (simpler but breaks on rotation): use a table constant for the permission address instead of b_submission=true + 1488 verification.",
249
+ "Repository-based address set (most flexible, most complex): store the permission address set in a Repository and query dynamically — only for extreme flexibility needs.",
250
+ ],
251
+ example_use_case: "Merchant allocation: the Service may rotate its permission (like a company changing its board). " +
252
+ "The caller submits the current permission address; the Guard verifies it matches service.permission (1488), " +
253
+ "then checks that Signer is the permission owner or has admin rights.",
254
+ verifier_constraint_level: "level2_identity_set",
255
+ },
256
+ {
257
+ id: "tpl_forward_node_check",
258
+ scene_id: "machine_forward_guard",
259
+ name: "Workflow node state validation",
260
+ description: "Verifies that the order is currently at the correct Machine node before advancing to the next step. Prevents skipping nodes or reverse operations.",
261
+ recommended_patterns: ["P06", "P09"],
262
+ parameters: [
263
+ { name: "expected_node", type: "string", description: "Expected current node name", required: true,
264
+ constraint: "Must exactly match the name defined in Machine nodes (case-sensitive)" },
265
+ ],
266
+ example_table: [
267
+ { identifier: 0, b_submission: true, value_type: "Address", name: "Order object address",
268
+ object_type: "Order" },
269
+ { identifier: 1, b_submission: false, value_type: "String", value: "${expected_node}",
270
+ name: "Expected current node name" },
271
+ ],
272
+ example_root: {
273
+ type: "logic_equal",
274
+ left: {
275
+ type: "query", query: "progress.current",
276
+ object: { identifier: 0, convert_witness: "OrderProgress" },
277
+ parameters: [],
278
+ },
279
+ right: { type: "identifier", identifier: 1 },
280
+ },
281
+ applicable_industries: ["rental", "ecommerce", "education", "travel", "subscription"],
282
+ relevant_risks: ["R-C2-01", "R-C2-03", "R-X1-08"],
283
+ creation_notes: [
284
+ "Forward.guard cannot be modified after binding (immutable after Machine publish)",
285
+ "witness 100 (Order→Progress) is a single hop; no risk of chained-derivation breakage",
286
+ "Node names are case-sensitive; query returns a String type",
287
+ ],
288
+ example_use_case: "Camera equipment rental flow: the user must be at the 'pending return' node to perform the return operation.",
289
+ verifier_constraint_level: "level3_scene_combined",
290
+ },
291
+ {
292
+ id: "tpl_forward_privacy_delivery_proof",
293
+ scene_id: "machine_forward_guard",
294
+ name: "Privacy-delivery Proof verification (strict mode, Messenger → on-chain Proof)",
295
+ description: "Strict-mode guard for 'privacy information delivered via Messenger but not suitable for on-chain publication' " +
296
+ "(e.g. shipping details, return addresses, private credentials). The verifier submits BOTH a Proof object address " +
297
+ "(generated by messenger.submitChainProof) AND the Order object address. Three conditions verify: " +
298
+ "(1) Signer == proof.signer (submitter accountability — 'whoever benefits bears the burden of proof'), " +
299
+ "(2) proof.time > order.time (proof created after the order — freshness, prevents stale-proof replay), " +
300
+ "(3) order.service == service (project binding, suppresses R-C3-05 cross-project bypass). " +
301
+ "No content verification — only submission responsibility. The counterparty can dispute by checking their own " +
302
+ "Messenger conversation. Broad-mode alternative (verify Merkle Root string length == 66 via P15) is documented " +
303
+ "in creation_notes — broad mode trusts the submitter's honesty and is suitable when the Guard is mainly an " +
304
+ "arbitration basis rather than a fund-flow gate.",
305
+ recommended_patterns: ["P10", "P15"],
306
+ parameters: [
307
+ { name: "service_name", type: "string", description: "Service object name (circular ref via P16 — resolved after Service publish)", required: true,
308
+ constraint: "Must be a name, not an address (the Service is not yet published when the Guard is created)" },
309
+ ],
310
+ example_table: [
311
+ { identifier: 0, b_submission: true, value_type: "Address", object_type: "Proof",
312
+ name: "proof_object (Proof address generated by messenger.submitChainProof, submitted by verifier at runtime)",
313
+ binding_constraint: "Must be a Proof object created AFTER the order; signer must equal the transaction Signer" },
314
+ { identifier: 1, b_submission: true, value_type: "Address", object_type: "Order",
315
+ name: "order_object (Order address submitted by verifier at runtime)",
316
+ binding_constraint: "Must belong to the service declared in identifier 2 (order.service == service)" },
317
+ { identifier: 2, b_submission: false, value_type: "Address", value: "${service_name}",
318
+ name: "Service object (project binding, circular ref via name)" },
319
+ ],
320
+ example_root: {
321
+ type: "logic_and",
322
+ nodes: [
323
+ {
324
+ type: "logic_equal",
325
+ nodes: [
326
+ { type: "context", context: "Signer" },
327
+ { type: "query", query: "proof.signer", object: { identifier: 0 }, parameters: [] },
328
+ ],
329
+ },
330
+ {
331
+ type: "logic_as_u256_greater",
332
+ nodes: [
333
+ { type: "query", query: "proof.time", object: { identifier: 0 }, parameters: [] },
334
+ { type: "query", query: "order.time", object: { identifier: 1 }, parameters: [] },
335
+ ],
336
+ },
337
+ {
338
+ type: "logic_equal",
339
+ nodes: [
340
+ { type: "query", query: "order.service", object: { identifier: 1 }, parameters: [] },
341
+ { type: "identifier", identifier: 2 },
342
+ ],
343
+ },
344
+ ],
345
+ },
346
+ applicable_industries: ["ecommerce", "logistics", "service", "privacy delivery"],
347
+ relevant_risks: ["R-C3-01", "R-C3-05", "R-X1-12"],
348
+ creation_notes: [
349
+ "STRICT MODE (this template): verifier submits Proof + Order addresses. Three conditions: Signer==proof.signer (submitter accountability), proof.time>order.time (freshness), order.service==service (project binding). No content verification — only submission responsibility ('谁得利谁举证' principle).",
350
+ "BROAD MODE ALTERNATIVE: use P15 retained_submission with a String submission (the Merkle Root) and verify calc_string_length == 66 (0x prefix + 64 hex chars). Broad mode trusts the submitter's honesty; the counterparty can dispute by checking their own Messenger conversation. Broad mode is suitable when the Guard is mainly an arbitration basis, not a fund-flow gate.",
351
+ "Guard table supports MULTIPLE b_submission=true Address identifiers (no submission count limit) — this template uses two: Proof (identifier 0) and Order (identifier 1).",
352
+ "submitChainProof(env, peerAddress, description?) sets Proof.about = peerAddress (the counterparty's address). Pass the order_id as a string in the description parameter to associate the Proof with an order (e.g. description: 'order:0x123...').",
353
+ "Query IDs (all zero-parameter): proof.signer=1958, proof.time=1960 (invariant clock_derived, always >0), order.time=1574, order.service=1563.",
354
+ "Forward.guard is immutable after Machine publish — choose broad vs strict before publishing.",
355
+ "The same strict Guard can be reused across ALL Machine forwards that need merkle-root verification (shipping, lost, returns, etc.) — the verifier just submits the relevant Proof + Order each time.",
356
+ "Condition (1) Signer==proof.signer suppresses R-C3-01 (submission not bound to Signer). Condition (3) order.service==service suppresses R-C3-05 (cross-project submission bypass).",
357
+ ],
358
+ example_use_case: "MyShop e-commerce: after delivering shipping details / return addresses via Messenger (privacy info not suitable for on-chain publication), " +
359
+ "the provider generates a Proof via submitChainProof and submits it with the Order address to advance the Machine forward. " +
360
+ "The Guard verifies the submitter is the Proof's signer, the Proof was created after the order, and the order belongs to this service.",
361
+ verifier_constraint_level: "level3_scene_combined",
362
+ },
363
+ {
364
+ id: "tpl_submission_signer_binding",
365
+ scene_id: "progress_submission_guard",
366
+ name: "Submission data signer binding validation",
367
+ description: "Verifies that the user submitting the data is a legitimate Progress participant and that the submitted value matches expectations.",
368
+ recommended_patterns: ["P08", "P15"],
369
+ parameters: [
370
+ { name: "expected_value", type: "string", description: "Expected submitted value (e.g. node name, status code)", required: true },
371
+ { name: "provider_address", type: "address", description: "Service provider address (used for identity verification)", required: true },
372
+ ],
373
+ example_table: [
374
+ { identifier: 0, b_submission: true, value_type: "String",
375
+ name: "User-submitted operation type (e.g. 'return' / 'damage')",
376
+ binding_constraint: "Must be one of the predefined operation types" },
377
+ { identifier: 1, b_submission: false, value_type: "Address",
378
+ value: "${provider_address}", name: "Service provider address" },
379
+ { identifier: 2, b_submission: false, value_type: "String",
380
+ value: "${expected_value}", name: "Expected submitted value" },
381
+ ],
382
+ example_root: {
383
+ type: "logic_and",
384
+ nodes: [
385
+ { type: "logic_equal",
386
+ nodes: [{ type: "identifier", identifier: 0 }, { type: "identifier", identifier: 2 }] },
387
+ { type: "logic_equal",
388
+ nodes: [{ type: "context", context: "Signer" }, { type: "identifier", identifier: 1 }] },
389
+ ],
390
+ },
391
+ applicable_industries: ["rental", "ecommerce", "education", "travel"],
392
+ relevant_risks: ["R-C3-01", "R-C3-03", "R-X1-12"],
393
+ creation_notes: [
394
+ "submission guard cannot be modified after binding",
395
+ "The name of b_submission=true entries must be a complete natural-language description (≥10 characters)",
396
+ "Providing a binding_constraint field describing value rules is recommended (R-X1-12)",
397
+ ],
398
+ example_use_case: "On equipment return, the user submits the 'return' operation; the Guard verifies that the submitter is the service provider and that the operation type is correct.",
399
+ verifier_constraint_level: "level1_strict",
400
+ },
401
+ {
402
+ id: "tpl_reward_one_time_claim",
403
+ scene_id: "reward_guard",
404
+ name: "One-time reward claim validation",
405
+ description: "Verifies that the user is claiming the reward for the first time, preventing duplicate claims. Implemented by querying the historical record count via Repository.",
406
+ recommended_patterns: ["P07", "P13"],
407
+ parameters: [
408
+ { name: "repository_address", type: "address", description: "Repository object address (stores claim records)", required: true },
409
+ ],
410
+ example_table: [
411
+ { identifier: 0, b_submission: false, value_type: "Address",
412
+ value: "${repository_address}", name: "Reward claim record Repository",
413
+ object_type: "Repository" },
414
+ { identifier: 1, b_submission: false, value_type: "U64",
415
+ value: "0", name: "First-claim threshold (record_count == 0)" },
416
+ ],
417
+ example_root: {
418
+ type: "logic_equal",
419
+ left: {
420
+ type: "query", query: "repository.data",
421
+ object: { identifier: 0 },
422
+ parameters: [{ type: "context", context: "Signer" }],
423
+ },
424
+ right: { type: "identifier", identifier: 1 },
425
+ },
426
+ applicable_industries: ["ecommerce", "education", "travel", "subscription"],
427
+ relevant_risks: ["R-C1-03", "R-X1-01", "R-X1-10"],
428
+ creation_notes: [
429
+ "Repository queries require quote_guard==None (otherwise impack_list is empty, causing IMPACK_GUARD_NOT_FOUND)",
430
+ "repository.data query returns U64 (record count), compared with identifier[1] (value 0)",
431
+ "Reward guard is iterable; duplicate-claim protection requires rebuilding the Guard to update the Repository address",
432
+ ],
433
+ example_use_case: "New-user first-order reward: query the user's historical order count via Repository; allow claim only when record_count==0.",
434
+ verifier_constraint_level: "level3_scene_combined",
435
+ },
436
+ {
437
+ id: "tpl_write_guard_type_check",
438
+ scene_id: "repository_write_guard",
439
+ name: "Storage write type validation",
440
+ description: "Verifies that the data type written to the Repository matches the declaration and that the writer's identity is legitimate.",
441
+ recommended_patterns: ["P08", "P11"],
442
+ parameters: [
443
+ { name: "repository_address", type: "address", description: "Repository object address", required: true,
444
+ constraint: "Must be the address of an already-published Repository" },
445
+ { name: "entity_registrar", type: "address", description: "EntityRegistrar address (fixed 0xaab)", required: false,
446
+ default: "0xaab" },
447
+ ],
448
+ example_table: [
449
+ { identifier: 0, b_submission: true, value_type: "Address",
450
+ name: "Writer address (submitted by caller)",
451
+ binding_constraint: "Must be a valid Entity address" },
452
+ { identifier: 1, b_submission: true, value_type: "String",
453
+ name: "Write data key name (submitted by caller)",
454
+ binding_constraint: "Key name format must be 'category:key'" },
455
+ { identifier: 2, b_submission: false, value_type: "Address",
456
+ value: "${entity_registrar}", name: "EntityRegistrar system address",
457
+ is_system_address: true },
458
+ ],
459
+ example_root: {
460
+ type: "logic_and",
461
+ nodes: [
462
+ { type: "logic_equal",
463
+ nodes: [{ type: "context", context: "Signer" }, { type: "identifier", identifier: 0 }] },
464
+ { type: "logic_not_equal",
465
+ nodes: [{ type: "identifier", identifier: 0 }, { type: "identifier", identifier: 2 }] },
466
+ ],
467
+ },
468
+ applicable_industries: ["ecommerce", "education", "travel", "subscription", "rental"],
469
+ relevant_risks: ["R-C1-02", "R-C3-03", "R-C3-04"],
470
+ creation_notes: [
471
+ "id_from_submission in write_guard must be of Address type",
472
+ "data_from_submission must match the Repository value_type",
473
+ "EntityRegistrar (0xaab) and EntityLinker (0xaaa) are fixed system addresses",
474
+ ],
475
+ example_use_case: "E-commerce platform merchant writes product review data; the Guard verifies that the writer is a registered Entity and not a system address.",
476
+ verifier_constraint_level: "level1_strict",
477
+ },
478
+ {
479
+ id: "tpl_usage_guard_threshold",
480
+ scene_id: "arbitration_usage_guard",
481
+ name: "Dispute initiation threshold validation",
482
+ description: "Verifies that the dispute initiator meets minimum conditions (e.g. order amount, time window), filtering out meaningless disputes.",
483
+ recommended_patterns: ["P02", "P10"],
484
+ parameters: [
485
+ { name: "min_amount", type: "number", description: "Minimum dispute amount threshold", required: true,
486
+ constraint: "A reasonable threshold is recommended; too high hinders user rights protection, too low produces many invalid disputes" },
487
+ ],
488
+ example_table: [
489
+ { identifier: 0, b_submission: true, value_type: "Address",
490
+ name: "Dispute-related Order object address", object_type: "Order" },
491
+ { identifier: 1, b_submission: false, value_type: "U64",
492
+ value: "${min_amount}", name: "Minimum dispute amount threshold" },
493
+ ],
494
+ example_root: {
495
+ type: "logic_as_u256_greater_or_equal",
496
+ left: { type: "query", query: "order.amount", object: { identifier: 0 }, parameters: [] },
497
+ right: { type: "identifier", identifier: 1 },
498
+ },
499
+ applicable_industries: ["ecommerce", "rental", "education", "travel"],
500
+ relevant_risks: ["R-X1-01", "R-X1-07", "R-C3-03"],
501
+ creation_notes: [
502
+ "usage_guard is iterable (Arbitration can be updated)",
503
+ "AND conditions should not be too many (R-X1-07); ≤3 conditions recommended",
504
+ "When Arbitration bPaused=true, blocking takes priority (checked before Guard)",
505
+ ],
506
+ example_use_case: "Rental service dispute: only disputes with order amount ≥ 10 WOW are accepted, filtering out small-amount conflicts.",
507
+ verifier_constraint_level: "level3_scene_combined",
508
+ },
509
+ {
510
+ id: "tpl_voting_guard_numeric_weight",
511
+ scene_id: "arbitration_voting_guard",
512
+ name: "Numeric voting weight validation",
513
+ description: "Assigns numeric voting weights based on arbitrator rank; higher-rank arbitrators have greater weight.",
514
+ recommended_patterns: ["P12"],
515
+ parameters: [
516
+ { name: "arbiter_weights", type: "vec_address", description: "Arbitrator address to weight mapping (address:weight pairs)", required: true,
517
+ constraint: "Weights must be numeric types U8-U256" },
518
+ ],
519
+ example_table: [
520
+ { identifier: 0, b_submission: true, value_type: "Address",
521
+ name: "Arbitrator address (submitted by caller)", object_type: "Arb" },
522
+ { identifier: 1, b_submission: false, value_type: "Vec<Address>",
523
+ value: "${arbiter_weights}", name: "Authorized arbitrator address list" },
524
+ ],
525
+ example_root: {
526
+ type: "vec_contains_address",
527
+ vec: { type: "identifier", identifier: 1 },
528
+ target: { type: "identifier", identifier: 0 },
529
+ },
530
+ applicable_industries: ["ecommerce", "rental", "education", "travel"],
531
+ relevant_risks: ["R-C3-02", "R-C2-01", "R-C2-02"],
532
+ creation_notes: [
533
+ "The GuardIdentifier for voting_guard must be numeric (U8-U256), otherwise E_GUARD_IDENTIFIER_NOT_NUMBER",
534
+ "Weights from submitted data (b_submission=true) carry forgery risk (R-C3-02 critical)",
535
+ "Deriving weights from the Arb object via witness is recommended, rather than submitting them directly",
536
+ ],
537
+ example_use_case: "3-person arbitration panel: chief arbitrator weight 3, regular arbitrators weight 1, majority vote decision.",
538
+ verifier_constraint_level: "level2_identity_set",
539
+ },
540
+ {
541
+ id: "tpl_gen_passport_identity",
542
+ scene_id: "gen_passport_guard",
543
+ name: "Passport identity credential generation validation",
544
+ description: "Standalone Guard; after verifying the user's identity, generates a Passport with a credential, used as submission data for subsequent operations.",
545
+ recommended_patterns: ["P03", "P14"],
546
+ parameters: [
547
+ { name: "authorized_address", type: "address", description: "Authorized address (or use Vec<Address> whitelist)", required: true },
548
+ ],
549
+ example_table: [
550
+ { identifier: 0, b_submission: false, value_type: "Address",
551
+ value: "${authorized_address}", name: "Authorized address" },
552
+ ],
553
+ example_root: {
554
+ type: "logic_equal",
555
+ nodes: [
556
+ { type: "context", context: "Signer" },
557
+ { type: "identifier", identifier: 0 },
558
+ ],
559
+ },
560
+ applicable_industries: ["ecommerce", "education", "travel", "subscription", "rental"],
561
+ relevant_risks: ["R-C1-01", "R-X1-10", "R-X1-13"],
562
+ creation_notes: [
563
+ "gen_passport is a standalone Guard; it does not bind a Host Object (host_object: Standalone)",
564
+ "impack_list is always empty during the verify phase; quote_guard queries will always fail",
565
+ "The Guard can be depended on by other Guards via rely (requires rep=true)",
566
+ "The generated Passport can be used as submission data for subsequent operations",
567
+ ],
568
+ example_use_case: "After the user passes identity verification, a Passport is generated; this Passport is then submitted as an identity credential in subsequent service purchases.",
569
+ verifier_constraint_level: "level1_strict",
570
+ },
571
+ ];
572
+ export function getTemplatesByScene(sceneId) {
573
+ return GUARD_TEMPLATES.filter((t) => t.scene_id === sceneId);
574
+ }
575
+ export function getTemplateById(templateId) {
576
+ return GUARD_TEMPLATES.find((t) => t.id === templateId);
577
+ }
578
+ export function getTemplatesByIndustry(industry) {
579
+ return GUARD_TEMPLATES.filter((t) => t.applicable_industries.includes(industry));
580
+ }
581
+ export function getTemplatesByPattern(patternId) {
582
+ return GUARD_TEMPLATES.filter((t) => t.recommended_patterns.includes(patternId));
583
+ }
584
+ export function listGuardTemplates() {
585
+ return GUARD_TEMPLATES;
586
+ }
587
+ export function suggestTemplateForScene(sceneId) {
588
+ return GUARD_TEMPLATES.find((t) => t.scene_id === sceneId);
589
+ }
590
+ export function getTemplateParameters(templateId) {
591
+ const template = getTemplateById(templateId);
592
+ return template?.parameters ?? [];
593
+ }
594
+ export function validateTemplateParams(templateId, params) {
595
+ const template = getTemplateById(templateId);
596
+ if (!template) {
597
+ return { valid: false, missing: ["template_not_found"] };
598
+ }
599
+ const missing = template.parameters
600
+ .filter((p) => p.required && !(p.name in params))
601
+ .map((p) => p.name);
602
+ return { valid: missing.length === 0, missing };
603
+ }
604
+ export const GUARD_TEMPLATES_VERSION = "1.0.0";
605
+ export const GUARD_TEMPLATES_COUNT = GUARD_TEMPLATES.length;