@wowok/agent-mcp 2.3.16 → 2.4.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/customer/index.d.ts +9 -0
- package/dist/customer/index.js +9 -0
- package/dist/customer/industry-risks.d.ts +4 -0
- package/dist/customer/industry-risks.js +45 -31
- package/dist/customer/order-monitor.js +57 -57
- package/dist/customer/order-strategy.js +89 -89
- package/dist/customer/post-purchase.js +97 -97
- package/dist/customer/reminder-system.js +26 -26
- package/dist/customer/risk-assessment.js +46 -46
- package/dist/customer/types.d.ts +4 -4
- package/dist/customer/types.js +4 -4
- package/dist/customer/user-preferences.d.ts +3 -0
- package/dist/customer/user-preferences.js +59 -50
- package/dist/experience/intent-distill.js +6 -6
- package/dist/experience/realtime-feedback.js +17 -0
- package/dist/index.js +360 -273
- package/dist/knowledge/acquisition-flywheel.d.ts +3 -0
- package/dist/knowledge/acquisition-flywheel.js +73 -64
- package/dist/knowledge/arbitration-trust.js +10 -10
- package/dist/knowledge/demand-matching.js +8 -8
- package/dist/knowledge/dynamic-pricing.js +18 -18
- package/dist/knowledge/flywheel-loop.js +11 -11
- package/dist/knowledge/glossary.js +22 -22
- package/dist/knowledge/guard-ledger.d.ts +19 -0
- package/dist/knowledge/guard-ledger.js +246 -0
- package/dist/knowledge/guard-lint.d.ts +76 -0
- package/dist/knowledge/guard-lint.js +590 -0
- package/dist/knowledge/guard-puzzle.d.ts +188 -0
- package/dist/knowledge/guard-puzzle.js +804 -0
- package/dist/knowledge/guard-risk.d.ts +67 -0
- package/dist/knowledge/guard-risk.js +1046 -0
- package/dist/knowledge/guard-templates.d.ts +37 -0
- package/dist/knowledge/guard-templates.js +329 -0
- package/dist/knowledge/guard-translation.d.ts +58 -0
- package/dist/knowledge/guard-translation.js +1118 -0
- package/dist/knowledge/index.d.ts +17 -0
- package/dist/knowledge/index.js +17 -0
- package/dist/knowledge/industry-evolution.js +29 -29
- package/dist/knowledge/industry-generalizer.js +52 -52
- package/dist/knowledge/industry-registry.d.ts +1 -2
- package/dist/knowledge/industry-registry.js +43 -36
- package/dist/knowledge/intent-metrics.js +67 -67
- package/dist/knowledge/process-model.js +80 -80
- package/dist/knowledge/reputation-rules.js +9 -9
- package/dist/knowledge/reward-templates.js +51 -51
- package/dist/knowledge/safety-rules.js +63 -2
- package/dist/knowledge/tool-constraints.js +17 -11
- package/dist/knowledge/trust-metrics.js +26 -26
- package/dist/safety/confirm-gate.d.ts +4 -2
- package/dist/safety/confirm-gate.js +48 -4
- package/dist/schema/call/allocation.d.ts +24 -14
- package/dist/schema/call/arbitration.d.ts +142 -132
- package/dist/schema/call/base.d.ts +901 -43
- package/dist/schema/call/base.js +77 -13
- package/dist/schema/call/bridge-handler.js +15 -2
- package/dist/schema/call/bridge.d.ts +795 -27
- package/dist/schema/call/bridge.js +37 -0
- package/dist/schema/call/contact.d.ts +10 -0
- package/dist/schema/call/demand.d.ts +94 -84
- package/dist/schema/call/guard.d.ts +229 -46
- package/dist/schema/call/guard.js +50 -0
- package/dist/schema/call/handler.js +46 -14
- package/dist/schema/call/machine.d.ts +158 -138
- package/dist/schema/call/order.d.ts +10 -0
- package/dist/schema/call/payment.d.ts +10 -0
- package/dist/schema/call/permission.d.ts +314 -304
- package/dist/schema/call/personal.d.ts +10 -0
- package/dist/schema/call/progress.d.ts +10 -0
- package/dist/schema/call/proof.d.ts +20 -0
- package/dist/schema/call/repository.d.ts +32 -22
- package/dist/schema/call/reward.d.ts +10 -0
- package/dist/schema/call/semantic.d.ts +9 -2
- package/dist/schema/call/semantic.js +617 -25
- package/dist/schema/call/service.d.ts +20 -10
- package/dist/schema/call/treasury.d.ts +10 -0
- package/dist/schema/config/index.d.ts +18 -0
- package/dist/schema/config/index.js +17 -0
- package/dist/schema/index.d.ts +6 -0
- package/dist/schema/index.js +5 -0
- package/dist/schema/local/index.d.ts +9 -9
- package/dist/schema/local/index.js +9 -0
- package/dist/schema/local/wip.d.ts +39 -19
- package/dist/schema/local/wip.js +5 -5
- package/dist/schema/messenger/index.d.ts +376 -55
- package/dist/schema/messenger/index.js +19 -19
- package/dist/schema/operations.d.ts +1881 -681
- package/dist/schema/operations.js +91 -96
- package/dist/schema/project/index.d.ts +21 -0
- package/dist/schema/project/index.js +32 -0
- package/dist/schema/query/index.d.ts +1074 -168
- package/dist/schema/query/index.js +8 -8
- package/dist/schema/schema-query/index.d.ts +33 -0
- package/dist/schema/schema-query/index.js +36 -0
- package/dist/schema/schema-version.d.ts +25 -0
- package/dist/schema/schema-version.js +76 -0
- package/dist/schema/trust/index.d.ts +407 -0
- package/dist/schema/trust/index.js +113 -0
- package/dist/schema/utils/guard-parser.js +4 -4
- package/dist/schema/utils/node-parser.js +14 -14
- package/dist/schemas/bridge_operation.output.json +233 -9
- package/dist/schemas/bridge_operation.schema.json +67 -8
- package/dist/schemas/config_operation.output.json +18 -0
- package/dist/schemas/config_operation.schema.json +34 -0
- package/dist/schemas/guard-node-schema.json +82 -0
- package/dist/schemas/guard2file.schema.json +8 -0
- package/dist/schemas/index.json +19 -1
- package/dist/schemas/machineNode2file.schema.json +8 -0
- package/dist/schemas/messenger_operation.output.json +236 -10
- package/dist/schemas/onchain_events.output.json +718 -0
- package/dist/schemas/onchain_operations.output.json +286 -11
- package/dist/schemas/onchain_operations.schema.json +19 -16
- package/dist/schemas/onchain_operations_allocation.schema.json +8 -0
- package/dist/schemas/onchain_operations_arbitration.schema.json +8 -0
- package/dist/schemas/onchain_operations_contact.schema.json +8 -0
- package/dist/schemas/onchain_operations_demand.schema.json +8 -0
- package/dist/schemas/onchain_operations_gen_passport.schema.json +16 -0
- package/dist/schemas/onchain_operations_guard.schema.json +11 -16
- package/dist/schemas/onchain_operations_machine.schema.json +8 -0
- package/dist/schemas/onchain_operations_order.schema.json +8 -0
- package/dist/schemas/onchain_operations_payment.schema.json +8 -0
- package/dist/schemas/onchain_operations_permission.schema.json +8 -0
- package/dist/schemas/onchain_operations_personal.schema.json +8 -0
- package/dist/schemas/onchain_operations_progress.schema.json +8 -0
- package/dist/schemas/onchain_operations_repository.schema.json +8 -0
- package/dist/schemas/onchain_operations_reward.schema.json +8 -0
- package/dist/schemas/onchain_operations_service.schema.json +8 -0
- package/dist/schemas/onchain_operations_treasury.schema.json +8 -0
- package/dist/schemas/onchain_table_data.output.json +718 -0
- package/dist/schemas/project_operation.output.json +18 -0
- package/dist/schemas/project_operation.schema.json +42 -0
- package/dist/schemas/query_toolkit.schema.json +360 -368
- package/dist/schemas/schema_query.schema.json +6 -3
- package/dist/schemas/trust_score.output.json +327 -0
- package/dist/schemas/trust_score.schema.json +46 -0
- package/dist/schemas/wip_file.output.json +24 -1
- package/package.json +2 -2
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
}
|
|
24
|
+
export declare const GUARD_TEMPLATES: GuardTemplate[];
|
|
25
|
+
export declare function getTemplatesByScene(sceneId: string): GuardTemplate[];
|
|
26
|
+
export declare function getTemplateById(templateId: string): GuardTemplate | undefined;
|
|
27
|
+
export declare function getTemplatesByIndustry(industry: string): GuardTemplate[];
|
|
28
|
+
export declare function getTemplatesByPattern(patternId: string): GuardTemplate[];
|
|
29
|
+
export declare function listGuardTemplates(): GuardTemplate[];
|
|
30
|
+
export declare function suggestTemplateForScene(sceneId: string): GuardTemplate | undefined;
|
|
31
|
+
export declare function getTemplateParameters(templateId: string): GuardTemplateParam[];
|
|
32
|
+
export declare function validateTemplateParams(templateId: string, params: Record<string, unknown>): {
|
|
33
|
+
valid: boolean;
|
|
34
|
+
missing: string[];
|
|
35
|
+
};
|
|
36
|
+
export declare const GUARD_TEMPLATES_VERSION = "1.0.0";
|
|
37
|
+
export declare const GUARD_TEMPLATES_COUNT: number;
|
|
@@ -0,0 +1,329 @@
|
|
|
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
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: "tpl_allocator_threshold",
|
|
32
|
+
scene_id: "service_order_allocators_guard",
|
|
33
|
+
name: "Allocation amount threshold validation",
|
|
34
|
+
description: "Selects different allocation strategies based on the order amount. When the amount exceeds the threshold, advanced allocation is used; otherwise, default allocation applies.",
|
|
35
|
+
recommended_patterns: ["P02", "P10"],
|
|
36
|
+
parameters: [
|
|
37
|
+
{ name: "threshold", type: "number", description: "Allocation threshold (unit: smallest precision)", required: true,
|
|
38
|
+
constraint: "Must be > 0; a reasonable range is recommended to avoid boundary gaming" },
|
|
39
|
+
{ name: "service_name", type: "string", description: "Service object name", required: true },
|
|
40
|
+
],
|
|
41
|
+
example_table: [
|
|
42
|
+
{ identifier: 0, b_submission: false, value_type: "Address", value: "${service_name}", name: "Service object" },
|
|
43
|
+
{ identifier: 1, b_submission: false, value_type: "U64", value: "${threshold}", name: "Allocation threshold" },
|
|
44
|
+
],
|
|
45
|
+
example_root: {
|
|
46
|
+
type: "logic_as_u256_greater",
|
|
47
|
+
left: { type: "query", query: "order.amount", object: { identifier: 0 }, parameters: [] },
|
|
48
|
+
right: { type: "identifier", identifier: 1 },
|
|
49
|
+
},
|
|
50
|
+
applicable_industries: ["ecommerce", "rental", "education", "travel"],
|
|
51
|
+
relevant_risks: ["R-X1-01", "R-X1-05", "R-X1-08"],
|
|
52
|
+
creation_notes: [
|
|
53
|
+
"order_allocators cannot be modified after binding (immutable after publish)",
|
|
54
|
+
"First-match-wins mechanism: multiple allocators are matched in order; the first one that passes executes",
|
|
55
|
+
"Threshold boundary must be tested: behavior when exactly equal to the threshold (> vs >=)",
|
|
56
|
+
],
|
|
57
|
+
example_use_case: "E-commerce platform: order amount > 1000 WOW triggers 3-way allocation (platform + merchant + logistics); otherwise 2-way allocation (platform + merchant).",
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: "tpl_forward_node_check",
|
|
61
|
+
scene_id: "machine_forward_guard",
|
|
62
|
+
name: "Workflow node state validation",
|
|
63
|
+
description: "Verifies that the order is currently at the correct Machine node before advancing to the next step. Prevents skipping nodes or reverse operations.",
|
|
64
|
+
recommended_patterns: ["P06", "P09"],
|
|
65
|
+
parameters: [
|
|
66
|
+
{ name: "expected_node", type: "string", description: "Expected current node name", required: true,
|
|
67
|
+
constraint: "Must exactly match the name defined in Machine nodes (case-sensitive)" },
|
|
68
|
+
],
|
|
69
|
+
example_table: [
|
|
70
|
+
{ identifier: 0, b_submission: true, value_type: "Address", name: "Order object address",
|
|
71
|
+
object_type: "Order" },
|
|
72
|
+
{ identifier: 1, b_submission: false, value_type: "String", value: "${expected_node}",
|
|
73
|
+
name: "Expected current node name" },
|
|
74
|
+
],
|
|
75
|
+
example_root: {
|
|
76
|
+
type: "logic_equal",
|
|
77
|
+
left: {
|
|
78
|
+
type: "query", query: "progress.current_node_name",
|
|
79
|
+
object: { identifier: 0, convert_witness: 100 },
|
|
80
|
+
parameters: [],
|
|
81
|
+
},
|
|
82
|
+
right: { type: "identifier", identifier: 1 },
|
|
83
|
+
},
|
|
84
|
+
applicable_industries: ["rental", "ecommerce", "education", "travel", "subscription"],
|
|
85
|
+
relevant_risks: ["R-C2-01", "R-C2-03", "R-X1-08"],
|
|
86
|
+
creation_notes: [
|
|
87
|
+
"Forward.guard cannot be modified after binding (immutable after Machine publish)",
|
|
88
|
+
"witness 100 (Order→Progress) is a single hop; no risk of chained-derivation breakage",
|
|
89
|
+
"Node names are case-sensitive; query returns a String type",
|
|
90
|
+
],
|
|
91
|
+
example_use_case: "Camera equipment rental flow: the user must be at the 'pending return' node to perform the return operation.",
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: "tpl_submission_signer_binding",
|
|
95
|
+
scene_id: "progress_submission_guard",
|
|
96
|
+
name: "Submission data signer binding validation",
|
|
97
|
+
description: "Verifies that the user submitting the data is a legitimate Progress participant and that the submitted value matches expectations.",
|
|
98
|
+
recommended_patterns: ["P08", "P15"],
|
|
99
|
+
parameters: [
|
|
100
|
+
{ name: "expected_value", type: "string", description: "Expected submitted value (e.g. node name, status code)", required: true },
|
|
101
|
+
{ name: "provider_address", type: "address", description: "Service provider address (used for identity verification)", required: true },
|
|
102
|
+
],
|
|
103
|
+
example_table: [
|
|
104
|
+
{ identifier: 0, b_submission: true, value_type: "String",
|
|
105
|
+
name: "User-submitted operation type (e.g. 'return' / 'damage')",
|
|
106
|
+
binding_constraint: "Must be one of the predefined operation types" },
|
|
107
|
+
{ identifier: 1, b_submission: false, value_type: "Address",
|
|
108
|
+
value: "${provider_address}", name: "Service provider address" },
|
|
109
|
+
{ identifier: 2, b_submission: false, value_type: "String",
|
|
110
|
+
value: "${expected_value}", name: "Expected submitted value" },
|
|
111
|
+
],
|
|
112
|
+
example_root: {
|
|
113
|
+
type: "logic_and",
|
|
114
|
+
nodes: [
|
|
115
|
+
{ type: "logic_equal",
|
|
116
|
+
nodes: [{ type: "identifier", identifier: 0 }, { type: "identifier", identifier: 2 }] },
|
|
117
|
+
{ type: "logic_equal",
|
|
118
|
+
nodes: [{ type: "context", context: "Signer" }, { type: "identifier", identifier: 1 }] },
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
applicable_industries: ["rental", "ecommerce", "education", "travel"],
|
|
122
|
+
relevant_risks: ["R-C3-01", "R-C3-03", "R-X1-12"],
|
|
123
|
+
creation_notes: [
|
|
124
|
+
"submission guard cannot be modified after binding",
|
|
125
|
+
"The name of b_submission=true entries must be a complete natural-language description (≥10 characters)",
|
|
126
|
+
"Providing a binding_constraint field describing value rules is recommended (R-X1-12)",
|
|
127
|
+
],
|
|
128
|
+
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.",
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
id: "tpl_reward_one_time_claim",
|
|
132
|
+
scene_id: "reward_guard",
|
|
133
|
+
name: "One-time reward claim validation",
|
|
134
|
+
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.",
|
|
135
|
+
recommended_patterns: ["P07", "P13"],
|
|
136
|
+
parameters: [
|
|
137
|
+
{ name: "repository_address", type: "address", description: "Repository object address (stores claim records)", required: true },
|
|
138
|
+
],
|
|
139
|
+
example_table: [
|
|
140
|
+
{ identifier: 0, b_submission: false, value_type: "Address",
|
|
141
|
+
value: "${repository_address}", name: "Reward claim record Repository",
|
|
142
|
+
object_type: "Repository" },
|
|
143
|
+
{ identifier: 1, b_submission: false, value_type: "U64",
|
|
144
|
+
value: "0", name: "First-claim threshold (record_count == 0)" },
|
|
145
|
+
],
|
|
146
|
+
example_root: {
|
|
147
|
+
type: "logic_equal",
|
|
148
|
+
left: {
|
|
149
|
+
type: "query", query: "repository.data",
|
|
150
|
+
object: { identifier: 0 },
|
|
151
|
+
parameters: [{ type: "context", context: "Signer" }],
|
|
152
|
+
},
|
|
153
|
+
right: { type: "identifier", identifier: 1 },
|
|
154
|
+
},
|
|
155
|
+
applicable_industries: ["ecommerce", "education", "travel", "subscription"],
|
|
156
|
+
relevant_risks: ["R-C1-03", "R-X1-01", "R-X1-10"],
|
|
157
|
+
creation_notes: [
|
|
158
|
+
"Repository queries require quote_guard==None (otherwise impack_list is empty, causing IMPACK_GUARD_NOT_FOUND)",
|
|
159
|
+
"repository.data query returns U64 (record count), compared with identifier[1] (value 0)",
|
|
160
|
+
"Reward guard is iterable; duplicate-claim protection requires rebuilding the Guard to update the Repository address",
|
|
161
|
+
],
|
|
162
|
+
example_use_case: "New-user first-order reward: query the user's historical order count via Repository; allow claim only when record_count==0.",
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
id: "tpl_write_guard_type_check",
|
|
166
|
+
scene_id: "repository_write_guard",
|
|
167
|
+
name: "Storage write type validation",
|
|
168
|
+
description: "Verifies that the data type written to the Repository matches the declaration and that the writer's identity is legitimate.",
|
|
169
|
+
recommended_patterns: ["P08", "P11"],
|
|
170
|
+
parameters: [
|
|
171
|
+
{ name: "repository_address", type: "address", description: "Repository object address", required: true,
|
|
172
|
+
constraint: "Must be the address of an already-published Repository" },
|
|
173
|
+
{ name: "entity_registrar", type: "address", description: "EntityRegistrar address (fixed 0xaab)", required: false,
|
|
174
|
+
default: "0xaab" },
|
|
175
|
+
],
|
|
176
|
+
example_table: [
|
|
177
|
+
{ identifier: 0, b_submission: true, value_type: "Address",
|
|
178
|
+
name: "Writer address (submitted by caller)",
|
|
179
|
+
binding_constraint: "Must be a valid Entity address" },
|
|
180
|
+
{ identifier: 1, b_submission: true, value_type: "String",
|
|
181
|
+
name: "Write data key name (submitted by caller)",
|
|
182
|
+
binding_constraint: "Key name format must be 'category:key'" },
|
|
183
|
+
{ identifier: 2, b_submission: false, value_type: "Address",
|
|
184
|
+
value: "${entity_registrar}", name: "EntityRegistrar system address",
|
|
185
|
+
is_system_address: true },
|
|
186
|
+
],
|
|
187
|
+
example_root: {
|
|
188
|
+
type: "logic_and",
|
|
189
|
+
nodes: [
|
|
190
|
+
{ type: "logic_equal",
|
|
191
|
+
nodes: [{ type: "context", context: "Signer" }, { type: "identifier", identifier: 0 }] },
|
|
192
|
+
{ type: "logic_not_equal",
|
|
193
|
+
nodes: [{ type: "identifier", identifier: 0 }, { type: "identifier", identifier: 2 }] },
|
|
194
|
+
],
|
|
195
|
+
},
|
|
196
|
+
applicable_industries: ["ecommerce", "education", "travel", "subscription", "rental"],
|
|
197
|
+
relevant_risks: ["R-C1-02", "R-C3-03", "R-C3-04"],
|
|
198
|
+
creation_notes: [
|
|
199
|
+
"id_from_submission in write_guard must be of Address type",
|
|
200
|
+
"data_from_submission must match the Repository value_type",
|
|
201
|
+
"EntityRegistrar (0xaab) and EntityLinker (0xaaa) are fixed system addresses",
|
|
202
|
+
],
|
|
203
|
+
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.",
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
id: "tpl_usage_guard_threshold",
|
|
207
|
+
scene_id: "arbitration_usage_guard",
|
|
208
|
+
name: "Dispute initiation threshold validation",
|
|
209
|
+
description: "Verifies that the dispute initiator meets minimum conditions (e.g. order amount, time window), filtering out meaningless disputes.",
|
|
210
|
+
recommended_patterns: ["P02", "P10"],
|
|
211
|
+
parameters: [
|
|
212
|
+
{ name: "min_amount", type: "number", description: "Minimum dispute amount threshold", required: true,
|
|
213
|
+
constraint: "A reasonable threshold is recommended; too high hinders user rights protection, too low produces many invalid disputes" },
|
|
214
|
+
],
|
|
215
|
+
example_table: [
|
|
216
|
+
{ identifier: 0, b_submission: true, value_type: "Address",
|
|
217
|
+
name: "Dispute-related Order object address", object_type: "Order" },
|
|
218
|
+
{ identifier: 1, b_submission: false, value_type: "U64",
|
|
219
|
+
value: "${min_amount}", name: "Minimum dispute amount threshold" },
|
|
220
|
+
],
|
|
221
|
+
example_root: {
|
|
222
|
+
type: "logic_as_u256_greater_or_equal",
|
|
223
|
+
left: { type: "query", query: "order.amount", object: { identifier: 0 }, parameters: [] },
|
|
224
|
+
right: { type: "identifier", identifier: 1 },
|
|
225
|
+
},
|
|
226
|
+
applicable_industries: ["ecommerce", "rental", "education", "travel"],
|
|
227
|
+
relevant_risks: ["R-X1-01", "R-X1-07", "R-C3-03"],
|
|
228
|
+
creation_notes: [
|
|
229
|
+
"usage_guard is iterable (Arbitration can be updated)",
|
|
230
|
+
"AND conditions should not be too many (R-X1-07); ≤3 conditions recommended",
|
|
231
|
+
"When Arbitration bPaused=true, blocking takes priority (checked before Guard)",
|
|
232
|
+
],
|
|
233
|
+
example_use_case: "Rental service dispute: only disputes with order amount ≥ 10 WOW are accepted, filtering out small-amount conflicts.",
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
id: "tpl_voting_guard_numeric_weight",
|
|
237
|
+
scene_id: "arbitration_voting_guard",
|
|
238
|
+
name: "Numeric voting weight validation",
|
|
239
|
+
description: "Assigns numeric voting weights based on arbitrator rank; higher-rank arbitrators have greater weight.",
|
|
240
|
+
recommended_patterns: ["P12"],
|
|
241
|
+
parameters: [
|
|
242
|
+
{ name: "arbiter_weights", type: "vec_address", description: "Arbitrator address to weight mapping (address:weight pairs)", required: true,
|
|
243
|
+
constraint: "Weights must be numeric types U8-U256" },
|
|
244
|
+
],
|
|
245
|
+
example_table: [
|
|
246
|
+
{ identifier: 0, b_submission: true, value_type: "Address",
|
|
247
|
+
name: "Arbitrator address (submitted by caller)", object_type: "Arb" },
|
|
248
|
+
{ identifier: 1, b_submission: false, value_type: "Vec<Address>",
|
|
249
|
+
value: "${arbiter_weights}", name: "Authorized arbitrator address list" },
|
|
250
|
+
],
|
|
251
|
+
example_root: {
|
|
252
|
+
type: "vec_contains_address",
|
|
253
|
+
vec: { type: "identifier", identifier: 1 },
|
|
254
|
+
target: { type: "identifier", identifier: 0 },
|
|
255
|
+
},
|
|
256
|
+
applicable_industries: ["ecommerce", "rental", "education", "travel"],
|
|
257
|
+
relevant_risks: ["R-C3-02", "R-C2-01", "R-C2-02"],
|
|
258
|
+
creation_notes: [
|
|
259
|
+
"The GuardIdentifier for voting_guard must be numeric (U8-U256), otherwise E_GUARD_IDENTIFIER_NOT_NUMBER",
|
|
260
|
+
"Weights from submitted data (b_submission=true) carry forgery risk (R-C3-02 critical)",
|
|
261
|
+
"Deriving weights from the Arb object via witness is recommended, rather than submitting them directly",
|
|
262
|
+
],
|
|
263
|
+
example_use_case: "3-person arbitration panel: chief arbitrator weight 3, regular arbitrators weight 1, majority vote decision.",
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
id: "tpl_gen_passport_identity",
|
|
267
|
+
scene_id: "gen_passport_guard",
|
|
268
|
+
name: "Passport identity credential generation validation",
|
|
269
|
+
description: "Standalone Guard; after verifying the user's identity, generates a Passport with a credential, used as submission data for subsequent operations.",
|
|
270
|
+
recommended_patterns: ["P03", "P14"],
|
|
271
|
+
parameters: [
|
|
272
|
+
{ name: "authorized_address", type: "address", description: "Authorized address (or use Vec<Address> whitelist)", required: true },
|
|
273
|
+
],
|
|
274
|
+
example_table: [
|
|
275
|
+
{ identifier: 0, b_submission: false, value_type: "Address",
|
|
276
|
+
value: "${authorized_address}", name: "Authorized address" },
|
|
277
|
+
],
|
|
278
|
+
example_root: {
|
|
279
|
+
type: "logic_equal",
|
|
280
|
+
nodes: [
|
|
281
|
+
{ type: "context", context: "Signer" },
|
|
282
|
+
{ type: "identifier", identifier: 0 },
|
|
283
|
+
],
|
|
284
|
+
},
|
|
285
|
+
applicable_industries: ["ecommerce", "education", "travel", "subscription", "rental"],
|
|
286
|
+
relevant_risks: ["R-C1-01", "R-X1-10", "R-X1-13"],
|
|
287
|
+
creation_notes: [
|
|
288
|
+
"gen_passport is a standalone Guard; it does not bind a Host Object (host_object: Standalone)",
|
|
289
|
+
"impack_list is always empty during the verify phase; quote_guard queries will always fail",
|
|
290
|
+
"The Guard can be depended on by other Guards via rely (requires rep=true)",
|
|
291
|
+
"The generated Passport can be used as submission data for subsequent operations",
|
|
292
|
+
],
|
|
293
|
+
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.",
|
|
294
|
+
},
|
|
295
|
+
];
|
|
296
|
+
export function getTemplatesByScene(sceneId) {
|
|
297
|
+
return GUARD_TEMPLATES.filter((t) => t.scene_id === sceneId);
|
|
298
|
+
}
|
|
299
|
+
export function getTemplateById(templateId) {
|
|
300
|
+
return GUARD_TEMPLATES.find((t) => t.id === templateId);
|
|
301
|
+
}
|
|
302
|
+
export function getTemplatesByIndustry(industry) {
|
|
303
|
+
return GUARD_TEMPLATES.filter((t) => t.applicable_industries.includes(industry));
|
|
304
|
+
}
|
|
305
|
+
export function getTemplatesByPattern(patternId) {
|
|
306
|
+
return GUARD_TEMPLATES.filter((t) => t.recommended_patterns.includes(patternId));
|
|
307
|
+
}
|
|
308
|
+
export function listGuardTemplates() {
|
|
309
|
+
return GUARD_TEMPLATES;
|
|
310
|
+
}
|
|
311
|
+
export function suggestTemplateForScene(sceneId) {
|
|
312
|
+
return GUARD_TEMPLATES.find((t) => t.scene_id === sceneId);
|
|
313
|
+
}
|
|
314
|
+
export function getTemplateParameters(templateId) {
|
|
315
|
+
const template = getTemplateById(templateId);
|
|
316
|
+
return template?.parameters ?? [];
|
|
317
|
+
}
|
|
318
|
+
export function validateTemplateParams(templateId, params) {
|
|
319
|
+
const template = getTemplateById(templateId);
|
|
320
|
+
if (!template) {
|
|
321
|
+
return { valid: false, missing: ["template_not_found"] };
|
|
322
|
+
}
|
|
323
|
+
const missing = template.parameters
|
|
324
|
+
.filter((p) => p.required && !(p.name in params))
|
|
325
|
+
.map((p) => p.name);
|
|
326
|
+
return { valid: missing.length === 0, missing };
|
|
327
|
+
}
|
|
328
|
+
export const GUARD_TEMPLATES_VERSION = "1.0.0";
|
|
329
|
+
export const GUARD_TEMPLATES_COUNT = GUARD_TEMPLATES.length;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export interface SemanticToSchemaRule {
|
|
2
|
+
id: string;
|
|
3
|
+
pattern_name: string;
|
|
4
|
+
data_source_combination: string;
|
|
5
|
+
semantic_intent: string;
|
|
6
|
+
match_keywords: string[];
|
|
7
|
+
schema_elements: {
|
|
8
|
+
root_type: string;
|
|
9
|
+
table_entries: Array<{
|
|
10
|
+
value_type: string;
|
|
11
|
+
b_submission: boolean;
|
|
12
|
+
purpose: string;
|
|
13
|
+
}>;
|
|
14
|
+
query_nodes?: Array<{
|
|
15
|
+
query_name: string;
|
|
16
|
+
object_type: string;
|
|
17
|
+
convert_witness?: number;
|
|
18
|
+
}>;
|
|
19
|
+
context_nodes?: Array<{
|
|
20
|
+
context_type: "Signer" | "Clock" | "Guard";
|
|
21
|
+
purpose: string;
|
|
22
|
+
}>;
|
|
23
|
+
tree_structure: string;
|
|
24
|
+
};
|
|
25
|
+
constraints: string[];
|
|
26
|
+
example: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
export declare const SEMANTIC_TO_SCHEMA_RULES: SemanticToSchemaRule[];
|
|
29
|
+
export interface SchemaToSemanticRule {
|
|
30
|
+
element_type: "node" | "table_entry" | "query" | "witness" | "rely" | "context";
|
|
31
|
+
type_name: string;
|
|
32
|
+
semantic: string;
|
|
33
|
+
return_type?: string;
|
|
34
|
+
child_constraints?: string;
|
|
35
|
+
data_source_class?: "Type1_OnChainConstant" | "Type2_WitnessDerived" | "Type3_SubmittedObject" | "Type4_SystemContext";
|
|
36
|
+
discovery_tool?: string;
|
|
37
|
+
}
|
|
38
|
+
export declare const SCHEMA_TO_SEMANTIC_RULES: SchemaToSemanticRule[];
|
|
39
|
+
export interface GuardConstraintRule {
|
|
40
|
+
id: string;
|
|
41
|
+
name: string;
|
|
42
|
+
description: string;
|
|
43
|
+
category: "root" | "table" | "query" | "witness" | "rely" | "binding" | "input" | "immutable" | "runtime";
|
|
44
|
+
phase: "creation" | "runtime";
|
|
45
|
+
validation_logic: string;
|
|
46
|
+
failure_message: string;
|
|
47
|
+
verification_location: string;
|
|
48
|
+
pitfall_number?: number;
|
|
49
|
+
}
|
|
50
|
+
export declare const GUARD_CONSTRAINT_RULES: GuardConstraintRule[];
|
|
51
|
+
export declare function matchSemanticPattern(userIntent: string): SemanticToSchemaRule[];
|
|
52
|
+
export declare function explainNode(nodeType: string): SchemaToSemanticRule | undefined;
|
|
53
|
+
export declare function explainWitness(witnessType: number): SchemaToSemanticRule | undefined;
|
|
54
|
+
export declare function explainContext(contextType: string): SchemaToSemanticRule | undefined;
|
|
55
|
+
export declare function getConstraintsByCategory(category: GuardConstraintRule["category"]): GuardConstraintRule[];
|
|
56
|
+
export declare function getConstraintsByPhase(phase: GuardConstraintRule["phase"]): GuardConstraintRule[];
|
|
57
|
+
export declare function getPatternById(id: string): SemanticToSchemaRule | undefined;
|
|
58
|
+
export declare function getDataSourceCombinations(): string[];
|