@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.
Files changed (317) hide show
  1. package/dist/config/runtime.d.ts +4 -0
  2. package/dist/config/runtime.js +29 -5
  3. package/dist/harness/auto-escalation.d.ts +27 -0
  4. package/dist/harness/auto-escalation.js +68 -0
  5. package/dist/index.js +21 -0
  6. package/dist/knowledge/allocation-confirm.d.ts +115 -0
  7. package/dist/knowledge/allocation-confirm.js +534 -0
  8. package/dist/knowledge/allocation-context.d.ts +58 -0
  9. package/dist/knowledge/allocation-context.js +249 -0
  10. package/dist/knowledge/allocation-ledger.d.ts +67 -0
  11. package/dist/knowledge/allocation-ledger.js +463 -0
  12. package/dist/knowledge/allocation-puzzle.d.ts +135 -0
  13. package/dist/knowledge/allocation-puzzle.js +298 -0
  14. package/dist/knowledge/allocation-risk.d.ts +78 -0
  15. package/dist/knowledge/allocation-risk.js +568 -0
  16. package/dist/knowledge/allocation-templates.d.ts +38 -0
  17. package/dist/knowledge/allocation-templates.js +970 -0
  18. package/dist/knowledge/allocation-translation.d.ts +72 -0
  19. package/dist/knowledge/allocation-translation.js +585 -0
  20. package/dist/knowledge/arb-risk.d.ts +37 -0
  21. package/dist/knowledge/arb-risk.js +210 -0
  22. package/dist/knowledge/arbitration-confirm.d.ts +135 -0
  23. package/dist/knowledge/arbitration-confirm.js +559 -0
  24. package/dist/knowledge/arbitration-context.d.ts +81 -0
  25. package/dist/knowledge/arbitration-context.js +505 -0
  26. package/dist/knowledge/arbitration-ledger.d.ts +62 -0
  27. package/dist/knowledge/arbitration-ledger.js +521 -0
  28. package/dist/knowledge/arbitration-puzzle.d.ts +84 -0
  29. package/dist/knowledge/arbitration-puzzle.js +304 -0
  30. package/dist/knowledge/arbitration-risk.d.ts +112 -0
  31. package/dist/knowledge/arbitration-risk.js +433 -0
  32. package/dist/knowledge/arbitration-templates.d.ts +38 -0
  33. package/dist/knowledge/arbitration-templates.js +276 -0
  34. package/dist/knowledge/arbitration-translation.d.ts +91 -0
  35. package/dist/knowledge/arbitration-translation.js +487 -0
  36. package/dist/knowledge/bridge-risk.d.ts +36 -0
  37. package/dist/knowledge/bridge-risk.js +263 -0
  38. package/dist/knowledge/contact-risk.d.ts +32 -0
  39. package/dist/knowledge/contact-risk.js +200 -0
  40. package/dist/knowledge/demand-confirm.d.ts +32 -0
  41. package/dist/knowledge/demand-confirm.js +206 -0
  42. package/dist/knowledge/demand-risk.d.ts +30 -0
  43. package/dist/knowledge/demand-risk.js +240 -0
  44. package/dist/knowledge/demand-translation.d.ts +55 -0
  45. package/dist/knowledge/demand-translation.js +354 -0
  46. package/dist/knowledge/deployment-scanner.d.ts +63 -0
  47. package/dist/knowledge/deployment-scanner.js +762 -0
  48. package/dist/knowledge/examples-scanner-cli.d.ts +1 -0
  49. package/dist/knowledge/examples-scanner-cli.js +26 -0
  50. package/dist/knowledge/examples-scanner.d.ts +121 -0
  51. package/dist/knowledge/examples-scanner.js +825 -0
  52. package/dist/knowledge/flywheel-loop.d.ts +3 -0
  53. package/dist/knowledge/flywheel-loop.js +32 -3
  54. package/dist/knowledge/glossary.js +3 -1
  55. package/dist/knowledge/guard-confirm.d.ts +86 -0
  56. package/dist/knowledge/guard-confirm.js +406 -0
  57. package/dist/knowledge/guard-context.d.ts +56 -0
  58. package/dist/knowledge/guard-context.js +287 -0
  59. package/dist/knowledge/guard-design-patterns.d.ts +37 -0
  60. package/dist/knowledge/guard-design-patterns.js +257 -0
  61. package/dist/knowledge/guard-puzzle.js +3 -2
  62. package/dist/knowledge/guard-risk.d.ts +1 -1
  63. package/dist/knowledge/guard-risk.js +12 -14
  64. package/dist/knowledge/guard-templates.js +1 -1
  65. package/dist/knowledge/guard-translation.js +6 -5
  66. package/dist/knowledge/index.d.ts +342 -0
  67. package/dist/knowledge/index.js +344 -0
  68. package/dist/knowledge/machine-confirm.d.ts +102 -0
  69. package/dist/knowledge/machine-confirm.js +559 -0
  70. package/dist/knowledge/machine-context.d.ts +160 -0
  71. package/dist/knowledge/machine-context.js +812 -0
  72. package/dist/knowledge/machine-ledger.d.ts +41 -0
  73. package/dist/knowledge/machine-ledger.js +315 -0
  74. package/dist/knowledge/machine-puzzle.d.ts +206 -0
  75. package/dist/knowledge/machine-puzzle.js +494 -0
  76. package/dist/knowledge/machine-risk.d.ts +75 -0
  77. package/dist/knowledge/machine-risk.js +644 -0
  78. package/dist/knowledge/machine-templates.d.ts +92 -0
  79. package/dist/knowledge/machine-templates.js +1592 -0
  80. package/dist/knowledge/machine-topology.d.ts +57 -0
  81. package/dist/knowledge/machine-topology.js +234 -0
  82. package/dist/knowledge/machine-translation.d.ts +96 -0
  83. package/dist/knowledge/machine-translation.js +513 -0
  84. package/dist/knowledge/mcp-schema-audit-cli.d.ts +1 -0
  85. package/dist/knowledge/mcp-schema-audit-cli.js +45 -0
  86. package/dist/knowledge/mcp-schema-audit.d.ts +90 -0
  87. package/dist/knowledge/mcp-schema-audit.js +772 -0
  88. package/dist/knowledge/onchain-constants.d.ts +4 -0
  89. package/dist/knowledge/onchain-constants.js +35 -0
  90. package/dist/knowledge/order-confirm.d.ts +115 -0
  91. package/dist/knowledge/order-confirm.js +573 -0
  92. package/dist/knowledge/order-context.d.ts +66 -0
  93. package/dist/knowledge/order-context.js +390 -0
  94. package/dist/knowledge/order-ledger.d.ts +69 -0
  95. package/dist/knowledge/order-ledger.js +341 -0
  96. package/dist/knowledge/order-puzzle.d.ts +159 -0
  97. package/dist/knowledge/order-puzzle.js +255 -0
  98. package/dist/knowledge/order-risk.d.ts +66 -0
  99. package/dist/knowledge/order-risk.js +653 -0
  100. package/dist/knowledge/order-templates.d.ts +50 -0
  101. package/dist/knowledge/order-templates.js +368 -0
  102. package/dist/knowledge/order-translation.d.ts +78 -0
  103. package/dist/knowledge/order-translation.js +550 -0
  104. package/dist/knowledge/passport-confirm.d.ts +130 -0
  105. package/dist/knowledge/passport-confirm.js +531 -0
  106. package/dist/knowledge/passport-context.d.ts +59 -0
  107. package/dist/knowledge/passport-context.js +306 -0
  108. package/dist/knowledge/passport-ledger.d.ts +48 -0
  109. package/dist/knowledge/passport-ledger.js +282 -0
  110. package/dist/knowledge/passport-puzzle.d.ts +108 -0
  111. package/dist/knowledge/passport-puzzle.js +333 -0
  112. package/dist/knowledge/passport-risk.d.ts +70 -0
  113. package/dist/knowledge/passport-risk.js +450 -0
  114. package/dist/knowledge/passport-templates.d.ts +40 -0
  115. package/dist/knowledge/passport-templates.js +568 -0
  116. package/dist/knowledge/passport-translation.d.ts +68 -0
  117. package/dist/knowledge/passport-translation.js +516 -0
  118. package/dist/knowledge/payment-risk.d.ts +33 -0
  119. package/dist/knowledge/payment-risk.js +182 -0
  120. package/dist/knowledge/permission-confirm.d.ts +110 -0
  121. package/dist/knowledge/permission-confirm.js +426 -0
  122. package/dist/knowledge/permission-context.d.ts +58 -0
  123. package/dist/knowledge/permission-context.js +224 -0
  124. package/dist/knowledge/permission-ledger.d.ts +38 -0
  125. package/dist/knowledge/permission-ledger.js +403 -0
  126. package/dist/knowledge/permission-puzzle.d.ts +122 -0
  127. package/dist/knowledge/permission-puzzle.js +173 -0
  128. package/dist/knowledge/permission-risk.d.ts +76 -0
  129. package/dist/knowledge/permission-risk.js +411 -0
  130. package/dist/knowledge/permission-templates.d.ts +38 -0
  131. package/dist/knowledge/permission-templates.js +234 -0
  132. package/dist/knowledge/permission-translation.d.ts +57 -0
  133. package/dist/knowledge/permission-translation.js +350 -0
  134. package/dist/knowledge/personal-risk.d.ts +36 -0
  135. package/dist/knowledge/personal-risk.js +212 -0
  136. package/dist/knowledge/progress-confirm.d.ts +108 -0
  137. package/dist/knowledge/progress-confirm.js +456 -0
  138. package/dist/knowledge/progress-context.d.ts +123 -0
  139. package/dist/knowledge/progress-context.js +452 -0
  140. package/dist/knowledge/progress-ledger.d.ts +63 -0
  141. package/dist/knowledge/progress-ledger.js +327 -0
  142. package/dist/knowledge/progress-puzzle.d.ts +82 -0
  143. package/dist/knowledge/progress-puzzle.js +219 -0
  144. package/dist/knowledge/progress-risk.d.ts +74 -0
  145. package/dist/knowledge/progress-risk.js +461 -0
  146. package/dist/knowledge/progress-templates.d.ts +38 -0
  147. package/dist/knowledge/progress-templates.js +228 -0
  148. package/dist/knowledge/progress-translation.d.ts +52 -0
  149. package/dist/knowledge/progress-translation.js +401 -0
  150. package/dist/knowledge/proof-confirm.d.ts +31 -0
  151. package/dist/knowledge/proof-confirm.js +187 -0
  152. package/dist/knowledge/proof-risk.d.ts +33 -0
  153. package/dist/knowledge/proof-risk.js +207 -0
  154. package/dist/knowledge/proof-translation.d.ts +52 -0
  155. package/dist/knowledge/proof-translation.js +283 -0
  156. package/dist/knowledge/registrar-risk.d.ts +34 -0
  157. package/dist/knowledge/registrar-risk.js +217 -0
  158. package/dist/knowledge/repository-confirm.d.ts +36 -0
  159. package/dist/knowledge/repository-confirm.js +242 -0
  160. package/dist/knowledge/repository-risk.d.ts +40 -0
  161. package/dist/knowledge/repository-risk.js +312 -0
  162. package/dist/knowledge/repository-translation.d.ts +58 -0
  163. package/dist/knowledge/repository-translation.js +422 -0
  164. package/dist/knowledge/resource-risk.d.ts +32 -0
  165. package/dist/knowledge/resource-risk.js +157 -0
  166. package/dist/knowledge/reward-confirm.d.ts +113 -0
  167. package/dist/knowledge/reward-confirm.js +496 -0
  168. package/dist/knowledge/reward-context.d.ts +127 -0
  169. package/dist/knowledge/reward-context.js +504 -0
  170. package/dist/knowledge/reward-ledger.d.ts +96 -0
  171. package/dist/knowledge/reward-ledger.js +502 -0
  172. package/dist/knowledge/reward-puzzle.d.ts +97 -0
  173. package/dist/knowledge/reward-puzzle.js +288 -0
  174. package/dist/knowledge/reward-risk.d.ts +84 -0
  175. package/dist/knowledge/reward-risk.js +545 -0
  176. package/dist/knowledge/reward-translation.d.ts +58 -0
  177. package/dist/knowledge/reward-translation.js +501 -0
  178. package/dist/knowledge/safety-rules.js +11 -3
  179. package/dist/knowledge/scenario-modes.d.ts +53 -0
  180. package/dist/knowledge/scenario-modes.js +302 -0
  181. package/dist/knowledge/service-confirm.d.ts +152 -0
  182. package/dist/knowledge/service-confirm.js +699 -0
  183. package/dist/knowledge/service-context.d.ts +66 -0
  184. package/dist/knowledge/service-context.js +403 -0
  185. package/dist/knowledge/service-ledger.d.ts +71 -0
  186. package/dist/knowledge/service-ledger.js +609 -0
  187. package/dist/knowledge/service-puzzle.d.ts +158 -0
  188. package/dist/knowledge/service-puzzle.js +236 -0
  189. package/dist/knowledge/service-risk.d.ts +108 -0
  190. package/dist/knowledge/service-risk.js +615 -0
  191. package/dist/knowledge/service-templates.d.ts +39 -0
  192. package/dist/knowledge/service-templates.js +418 -0
  193. package/dist/knowledge/service-translation.d.ts +103 -0
  194. package/dist/knowledge/service-translation.js +622 -0
  195. package/dist/knowledge/tools-reference.d.ts +17 -0
  196. package/dist/knowledge/tools-reference.js +151 -0
  197. package/dist/knowledge/treasury-confirm.d.ts +133 -0
  198. package/dist/knowledge/treasury-confirm.js +512 -0
  199. package/dist/knowledge/treasury-context.d.ts +64 -0
  200. package/dist/knowledge/treasury-context.js +363 -0
  201. package/dist/knowledge/treasury-ledger.d.ts +42 -0
  202. package/dist/knowledge/treasury-ledger.js +300 -0
  203. package/dist/knowledge/treasury-puzzle.d.ts +163 -0
  204. package/dist/knowledge/treasury-puzzle.js +216 -0
  205. package/dist/knowledge/treasury-risk.d.ts +86 -0
  206. package/dist/knowledge/treasury-risk.js +440 -0
  207. package/dist/knowledge/treasury-templates.d.ts +38 -0
  208. package/dist/knowledge/treasury-templates.js +316 -0
  209. package/dist/knowledge/treasury-translation.d.ts +78 -0
  210. package/dist/knowledge/treasury-translation.js +498 -0
  211. package/dist/knowledge/util-risk.d.ts +30 -0
  212. package/dist/knowledge/util-risk.js +135 -0
  213. package/dist/project/business-puzzle.d.ts +47 -0
  214. package/dist/project/business-puzzle.js +372 -0
  215. package/dist/project/deployment-doc.d.ts +61 -0
  216. package/dist/project/deployment-doc.js +432 -0
  217. package/dist/project/risk-aggregator.d.ts +50 -0
  218. package/dist/project/risk-aggregator.js +280 -0
  219. package/dist/project/substep-trace.d.ts +130 -0
  220. package/dist/project/substep-trace.js +332 -0
  221. package/dist/schema/call/allocation.d.ts +34 -34
  222. package/dist/schema/call/arbitration.d.ts +141 -141
  223. package/dist/schema/call/base.d.ts +386 -386
  224. package/dist/schema/call/base.js +3 -3
  225. package/dist/schema/call/bridge-handler.d.ts +5 -2
  226. package/dist/schema/call/bridge.d.ts +159 -159
  227. package/dist/schema/call/contact.d.ts +110 -110
  228. package/dist/schema/call/demand.d.ts +76 -76
  229. package/dist/schema/call/handler.d.ts +2 -3
  230. package/dist/schema/call/handler.js +1 -1
  231. package/dist/schema/call/machine.d.ts +58 -58
  232. package/dist/schema/call/order.d.ts +98 -110
  233. package/dist/schema/call/permission-handler.d.ts +5 -0
  234. package/dist/schema/call/permission-handler.js +54 -0
  235. package/dist/schema/call/permission.d.ts +108 -108
  236. package/dist/schema/call/personal.d.ts +14 -14
  237. package/dist/schema/call/progress.d.ts +57 -72
  238. package/dist/schema/call/progress.js +7 -4
  239. package/dist/schema/call/proof.d.ts +18 -18
  240. package/dist/schema/call/proof.js +12 -7
  241. package/dist/schema/call/repository.d.ts +154 -154
  242. package/dist/schema/call/reward.d.ts +55 -55
  243. package/dist/schema/call/service.d.ts +231 -231
  244. package/dist/schema/call/treasury.d.ts +93 -93
  245. package/dist/schema/config/index.d.ts +178 -5
  246. package/dist/schema/config/index.js +52 -1
  247. package/dist/schema/local/index.d.ts +3554 -836
  248. package/dist/schema/local/index.js +2 -1
  249. package/dist/schema/messenger/index.d.ts +162 -162
  250. package/dist/schema/operations.d.ts +1058 -1074
  251. package/dist/schema/operations.js +7 -1
  252. package/dist/schema/project/index.d.ts +1412 -6
  253. package/dist/schema/project/index.js +441 -3
  254. package/dist/schema/query/index.d.ts +672 -672
  255. package/dist/schema/schema-query/index.d.ts +23 -3
  256. package/dist/schema/schema-query/index.js +13 -2
  257. package/dist/schema/sync-layer4.d.ts +21 -0
  258. package/dist/schema/sync-layer4.js +261 -0
  259. package/dist/schema/trust/index.d.ts +26 -26
  260. package/dist/schemas/account_operation.output.json +718 -0
  261. package/dist/schemas/config_operation.output.json +173 -0
  262. package/dist/schemas/index.json +9 -1
  263. package/dist/schemas/local_info_operation.output.json +718 -0
  264. package/dist/schemas/local_mark_operation.output.json +718 -0
  265. package/dist/schemas/onchain_operations.output.json +3 -2
  266. package/dist/schemas/onchain_operations.schema.json +1809 -336
  267. package/dist/schemas/onchain_operations_allocation.schema.json +2 -1
  268. package/dist/schemas/onchain_operations_arbitration.schema.json +2 -1
  269. package/dist/schemas/onchain_operations_contact.schema.json +2 -1
  270. package/dist/schemas/onchain_operations_demand.schema.json +2 -1
  271. package/dist/schemas/onchain_operations_gen_passport.schema.json +878 -872
  272. package/dist/schemas/onchain_operations_gen_proof.schema.json +273 -0
  273. package/dist/schemas/onchain_operations_guard.schema.json +578 -579
  274. package/dist/schemas/onchain_operations_machine.schema.json +2 -1
  275. package/dist/schemas/onchain_operations_order.schema.json +13 -9
  276. package/dist/schemas/onchain_operations_payment.schema.json +0 -514
  277. package/dist/schemas/onchain_operations_permission.schema.json +0 -514
  278. package/dist/schemas/onchain_operations_personal.schema.json +0 -514
  279. package/dist/schemas/onchain_operations_progress.schema.json +14 -10
  280. package/dist/schemas/onchain_operations_proof.schema.json +699 -0
  281. package/dist/schemas/onchain_operations_repository.schema.json +2 -1
  282. package/dist/schemas/onchain_operations_reward.schema.json +2 -1
  283. package/dist/schemas/onchain_operations_service.schema.json +2 -1
  284. package/dist/schemas/onchain_operations_treasury.schema.json +2 -1
  285. package/dist/schemas/onchain_table_data.schema.json +32 -1
  286. package/dist/schemas/project_operation.output.json +918 -0
  287. package/dist/schemas/project_operation.schema.json +474 -3
  288. package/dist/schemas/query_toolkit.output.json +14906 -6
  289. package/dist/schemas/schema_query.output.json +38 -1
  290. package/dist/telemetry/index.d.ts +1 -1
  291. package/dist/tools/handlers/config.d.ts +1 -1
  292. package/dist/tools/handlers/config.js +21 -18
  293. package/dist/tools/handlers/file-export.d.ts +2 -2
  294. package/dist/tools/handlers/local.d.ts +3 -30
  295. package/dist/tools/handlers/local.js +14 -3
  296. package/dist/tools/handlers/messenger.d.ts +1 -1
  297. package/dist/tools/handlers/messenger.js +2 -1
  298. package/dist/tools/handlers/onchain.d.ts +1 -1
  299. package/dist/tools/handlers/onchain.js +24 -22
  300. package/dist/tools/handlers/project.d.ts +1 -1
  301. package/dist/tools/handlers/project.js +262 -18
  302. package/dist/tools/handlers/query.d.ts +4 -4
  303. package/dist/tools/handlers/schema-query.d.ts +1 -1
  304. package/dist/tools/handlers/schema-query.js +21 -20
  305. package/dist/tools/handlers/trust.d.ts +1 -1
  306. package/dist/tools/handlers/trust.js +2 -2
  307. package/dist/tools/handlers/wip.d.ts +1 -1
  308. package/dist/tools/handlers/wip.js +1 -1
  309. package/dist/tools/index.d.ts +1 -1
  310. package/dist/tools/index.js +96 -25
  311. package/dist/tools/rules-hook.d.ts +1 -1
  312. package/dist/tools/rules-hook.js +3 -2
  313. package/dist/tools/shared.d.ts +13 -22
  314. package/dist/tools/types.d.ts +5 -5
  315. package/dist/tools/wrap.d.ts +10 -2
  316. package/dist/tools/wrap.js +212 -0
  317. package/package.json +3 -3
@@ -0,0 +1,516 @@
1
+ import { PASSPORT_ERROR_CODES, MAX_GUARD_COUNT_PASSPORT, MAX_SUBMISSION_SIZE_PASSPORT, } from "./passport-ledger.js";
2
+ export const SEMANTIC_TO_SCHEMA_RULES = [
3
+ {
4
+ id: "P-PASS-01",
5
+ pattern_name: "Create Passport",
6
+ semantic_intent: "Create a new verification carrier object bound to the current transaction",
7
+ match_keywords: ["create", "new", "passport", "instantiate"],
8
+ schema_fields: ["(SubmissionCall)"],
9
+ example_json: {
10
+ type: "submission",
11
+ guard: [],
12
+ submission: [],
13
+ },
14
+ reverse_explanation: "Passport created via passport::new(clock, ctx). tx_hash bound to tx_context::digest(ctx). No Guard added yet.",
15
+ },
16
+ {
17
+ id: "P-PASS-02",
18
+ pattern_name: "Add impack Guard",
19
+ semantic_intent: "Add a Guard that affects the final verification result (impack=true)",
20
+ match_keywords: ["impack", "affect", "decisive", "critical guard"],
21
+ schema_fields: ["guard[].object", "guard[].impack=true"],
22
+ example_json: {
23
+ guard: [
24
+ { object: "kyc_guard", impack: true },
25
+ ],
26
+ submission: [
27
+ {
28
+ guard: "kyc_guard",
29
+ submission: [
30
+ { identifier: 0, value: "0x1234...", value_type: "address" },
31
+ ],
32
+ },
33
+ ],
34
+ },
35
+ reverse_explanation: "guard[].impack=true marks this Guard as affecting final result. At least 1 impack Guard required (else E_IMPACK_GUARD_NOT_FOUND). Failure aborts overall result to false.",
36
+ },
37
+ {
38
+ id: "P-PASS-03",
39
+ pattern_name: "Add non-impack Guard",
40
+ semantic_intent: "Add a Guard that only records per-Guard result (impack=false)",
41
+ match_keywords: ["non-impack", "record", "audit", "log"],
42
+ schema_fields: ["guard[].object", "guard[].impack=false"],
43
+ example_json: {
44
+ guard: [
45
+ { object: "audit_log_guard", impack: false },
46
+ ],
47
+ submission: [],
48
+ },
49
+ reverse_explanation: "guard[].impack=false marks this Guard as audit-only. Its result is recorded but does NOT affect final result. Useful for logging / secondary checks.",
50
+ },
51
+ {
52
+ id: "P-PASS-04",
53
+ pattern_name: "Add Guard with relies dependency",
54
+ semantic_intent: "Add a Guard that depends on other Guards (AND/OR logic)",
55
+ match_keywords: ["relies", "depend", "dependency", "and", "or"],
56
+ schema_fields: ["guard[].object", "guard[].impack", "(relies read from Guard object)"],
57
+ example_json: {
58
+ guard: [
59
+ { object: "guard_a", impack: true },
60
+ { object: "guard_b", impack: true },
61
+ ],
62
+ submission: [],
63
+ },
64
+ reverse_explanation: "relies is read from guard::relies(guard) — NOT set in Passport JSON. Must add relied Guards first (E_RELIES_GUARD_NOT_ADDED). relies_logic_and=true=AND, false=OR. No transitive dependencies allowed.",
65
+ },
66
+ {
67
+ id: "P-PASS-05",
68
+ pattern_name: "Verify Passport (one-time)",
69
+ semantic_intent: "Trigger one-time verification of all Guards; result is immutable after this call",
70
+ match_keywords: ["verify", "validation", "submit"],
71
+ schema_fields: ["(verify operation)"],
72
+ example_json: {
73
+ operation: "verify",
74
+ },
75
+ reverse_explanation: "passport::verify(self, ctx). One-time — has_verified set to true. Computes per-Guard result via relies logic, then impack Guards decide final result. Aborts E_HAS_VERIFIED if called twice.",
76
+ },
77
+ {
78
+ id: "P-PASS-06",
79
+ pattern_name: "Freeze Passport (permanent)",
80
+ semantic_intent: "Permanently freeze the Passport as immutable (cannot be destroyed after)",
81
+ match_keywords: ["freeze", "freezen", "permanent"],
82
+ schema_fields: ["(freezen operation)"],
83
+ example_json: {
84
+ operation: "freezen",
85
+ },
86
+ reverse_explanation: "passport::freezen(self) calls transfer::freeze_object(self). Passport becomes immutable and publicly readable. Cannot be destroyed after freezing. SDK exports as `freeze` (correct spelling).",
87
+ },
88
+ {
89
+ id: "P-PASS-07",
90
+ pattern_name: "Query result",
91
+ semantic_intent: "Get the final verification result (requires has_verified=true + tx_hash match)",
92
+ match_keywords: ["result", "query", "outcome"],
93
+ schema_fields: ["(result query)"],
94
+ example_json: {
95
+ operation: "result_query",
96
+ },
97
+ reverse_explanation: "passport::result(self, ctx) : bool. Aborts E_NOT_VERIFIED (5) if not yet verified; E_TX_NOT_MATCH (8) if called from a different transaction. Must be called in the same tx as verify().",
98
+ },
99
+ {
100
+ id: "P-PASS-08",
101
+ pattern_name: "Query specific Guard result (result_for_guard)",
102
+ semantic_intent: "Hard-verify that a specific impack Guard passed (aborts E_VERIFY_FAILED if not)",
103
+ match_keywords: ["result_for_guard", "hard-verify", "specific guard"],
104
+ schema_fields: ["(result_for_guard query)"],
105
+ example_json: {
106
+ operation: "result_for_guard",
107
+ guard: "kyc_guard",
108
+ },
109
+ reverse_explanation: "passport::result_for_guard(self, guard, ctx). Aborts E_NOT_IMPACK_GUARD (6) if guard is not impack; E_VERIFY_FAILED (7) if overall result=false. Used by consumers to enforce specific Guard checks.",
110
+ },
111
+ {
112
+ id: "P-PASS-09",
113
+ pattern_name: "Query impack Guard list (result_for_permission)",
114
+ semantic_intent: "Get the list of impack Guard addresses (lazy-filled on first call)",
115
+ match_keywords: ["result_for_permission", "impack list", "impack addresses"],
116
+ schema_fields: ["(result_for_permission query)"],
117
+ example_json: {
118
+ operation: "result_for_permission",
119
+ },
120
+ reverse_explanation: "passport::result_for_permission(self, ctx) : vector<address>. Lazy-fills self.impack on first call. Aborts E_VERIFY_FAILED (7) if overall result=false. Used by Permission/Allocation to get authorized Guard list.",
121
+ },
122
+ {
123
+ id: "P-PASS-10",
124
+ pattern_name: "Get submission value",
125
+ semantic_intent: "Read the submitted value for a (guard, identifier) pair",
126
+ match_keywords: ["submission_get", "read", "fetch submission"],
127
+ schema_fields: ["(submission_get query)"],
128
+ example_json: {
129
+ operation: "submission_get",
130
+ guard: "voting_guard",
131
+ identifier: 0,
132
+ },
133
+ reverse_explanation: "passport::submission_get(self, guard, identifier) : vector<u8>. Read-only — no tx_hash check. Returns the BCS-encoded value. Aborts E_SUBMISSION_NOT_FOUND (10) if no entry exists.",
134
+ },
135
+ {
136
+ id: "P-PASS-11",
137
+ pattern_name: "Destroy Passport",
138
+ semantic_intent: "Permanently delete the Passport to release storage (must be before freeze)",
139
+ match_keywords: ["destroy", "delete", "remove"],
140
+ schema_fields: ["(destroy operation)"],
141
+ example_json: {
142
+ operation: "destroy",
143
+ },
144
+ reverse_explanation: "passport::destroy(self) calls object::delete(id). Must be called BEFORE freeze (frozen objects are immutable, cannot be destroyed). Move ownership protects: only signer holding the object can call.",
145
+ },
146
+ {
147
+ id: "P-PASS-12",
148
+ pattern_name: "Clear all Guards (pre-verify only)",
149
+ semantic_intent: "Remove all Guards from Passport (only allowed before verify)",
150
+ match_keywords: ["guard_clear", "clear", "reset"],
151
+ schema_fields: ["(guard_clear operation)"],
152
+ example_json: {
153
+ operation: "guard_clear",
154
+ },
155
+ reverse_explanation: "passport::guard_clear(self, ctx). Aborts E_HAS_VERIFIED (4) if already verified; E_DIGEST_NOT_MATCH (11) if tx_hash mismatch. Useful for resetting configuration before verify.",
156
+ },
157
+ ];
158
+ export const SCHEMA_TO_SEMANTIC_RULES = [
159
+ {
160
+ element_type: "field",
161
+ type_name: "object",
162
+ semantic_explanation: "Passport object reference (address). For create, no object yet; for operate, the existing Passport address.",
163
+ },
164
+ {
165
+ element_type: "field",
166
+ type_name: "guard",
167
+ semantic_explanation: "Array of {object, impack}. Each entry references a Guard object and marks whether it affects final result. Count ≤ MAX_GUARD_COUNT_PASSPORT=20.",
168
+ },
169
+ {
170
+ element_type: "field",
171
+ type_name: "guard[].object",
172
+ semantic_explanation: "Guard object address. Must be unique within the Passport (duplicate addresses overwrite existing config). Resolved via LocalMark before on-chain call.",
173
+ },
174
+ {
175
+ element_type: "field",
176
+ type_name: "guard[].impack",
177
+ semantic_explanation: "Boolean. true=affects final result (at least 1 required); false=audit-only. impack Guards failing → overall result=false immediately.",
178
+ },
179
+ {
180
+ element_type: "field",
181
+ type_name: "submission",
182
+ semantic_explanation: "Array of {guard, submission[]}. Each submission is {identifier, value, value_type}. identifier is u8 (0-255) matching Guard.table[].identifier.",
183
+ },
184
+ {
185
+ element_type: "field",
186
+ type_name: "submission[].identifier",
187
+ semantic_explanation: "u8 (0-255). References Guard.table[identifier]. Must be marked b_submission=true in the Guard.",
188
+ },
189
+ {
190
+ element_type: "field",
191
+ type_name: "submission[].value",
192
+ semantic_explanation: "Value matching submission[].value_type. BCS-serialized on-chain; total serialized size per submission ≤ MAX_SUBMISSION_SIZE_PASSPORT=256 bytes.",
193
+ },
194
+ {
195
+ element_type: "field",
196
+ type_name: "submission[].value_type",
197
+ semantic_explanation: "Type string: 'address' | 'u64' | 'bool' | 'string' | 'vector<u8>' etc. Must match Guard.table[identifier].value_type.",
198
+ },
199
+ {
200
+ element_type: "op",
201
+ type_name: "create (new)",
202
+ semantic_explanation: "passport::new(clock, ctx) → Passport. Binds tx_hash = tx_context::digest(ctx). signer = tx_context::sender(ctx). time = clock::timestamp_ms(clock).",
203
+ },
204
+ {
205
+ element_type: "op",
206
+ type_name: "guard_add",
207
+ semantic_explanation: "passport::guard_add(self, guard, identifiers, values, impack, ctx). Pre-verify only. Reads guard::relies(guard) for dependency info. Aborts E_RELIES_GUARD_NOT_ADDED if relies missing.",
208
+ },
209
+ {
210
+ element_type: "op",
211
+ type_name: "verify",
212
+ semantic_explanation: "passport::verify(self, ctx) : bool. One-time. Computes per-Guard result via relies, then impack Guards decide final result. Sets has_verified=true.",
213
+ },
214
+ {
215
+ element_type: "op",
216
+ type_name: "freezen",
217
+ semantic_explanation: "passport::freezen(self). Permanent freeze (transfer::freeze_object). Cannot destroy after. Historical typo: Move function name is 'freezen' (not 'freeze'), retained for compatibility. SDK exports as `freeze`.",
218
+ },
219
+ {
220
+ element_type: "op",
221
+ type_name: "destroy",
222
+ semantic_explanation: "passport::destroy(self). Releases storage (object::delete). Must be before freeze. Move ownership protects: only object holder can call.",
223
+ },
224
+ {
225
+ element_type: "impack",
226
+ type_name: "impack=true",
227
+ semantic_explanation: "Guard affects final result. At least 1 required (E_IMPACK_GUARD_NOT_FOUND). Failure → overall result=false, immediate return.",
228
+ },
229
+ {
230
+ element_type: "impack",
231
+ type_name: "impack=false",
232
+ semantic_explanation: "Guard is audit-only. Per-Guard result is recorded but does NOT affect final result. Useful for logging / secondary checks.",
233
+ },
234
+ {
235
+ element_type: "relies_logic",
236
+ type_name: "AND (relies_logic_and=true)",
237
+ semantic_explanation: "All relied Guards must pass. Short-circuits on first false. Initial value = true; result = true AND rely1.result AND rely2.result ...",
238
+ },
239
+ {
240
+ element_type: "relies_logic",
241
+ type_name: "OR (relies_logic_and=false)",
242
+ semantic_explanation: "Any relied Guard may pass. Short-circuits on first true. Initial value = false; result = false OR rely1.result OR rely2.result ...",
243
+ },
244
+ {
245
+ element_type: "lifecycle",
246
+ type_name: "new → guard_add → verify → use → freeze/destroy",
247
+ semantic_explanation: "5-stage lifecycle. verify is one-time. freeze and destroy are mutually exclusive terminal states. All write ops (guard_add/verify) require tx_hash match.",
248
+ },
249
+ ];
250
+ export const PASSPORT_CONSTRAINT_RULES = [
251
+ {
252
+ id: "T-PASS-01",
253
+ category: "structural",
254
+ rule: "Passport is created via the SubmissionCall mechanism, not the standard Call pattern (schema/call/base.ts SubmissionCallSchema)",
255
+ applies_to: ["SubmissionCall", "passport::new"],
256
+ },
257
+ {
258
+ id: "T-PASS-02",
259
+ category: "logic",
260
+ rule: "Guards with guard[].impack=true decide the final result; at least 1 impack Guard is required (E_IMPACK_GUARD_NOT_FOUND=9)",
261
+ applies_to: ["guard[].impack", "verify operation"],
262
+ },
263
+ {
264
+ id: "T-PASS-03",
265
+ category: "logic",
266
+ rule: "Depended-on Guards must be added first (topological order); guard_add checks relies, missing relies aborts E_RELIES_GUARD_NOT_ADDED=2",
267
+ applies_to: ["guard_add operation", "guard::relies(guard)"],
268
+ },
269
+ {
270
+ id: "T-PASS-04",
271
+ category: "lifecycle",
272
+ rule: "After verify, config cannot be modified (has_verified is one-time); second calls to guard_add/guard_clear/verify abort E_HAS_VERIFIED=4",
273
+ applies_to: ["verify operation", "has_verified field"],
274
+ },
275
+ {
276
+ id: "T-PASS-05",
277
+ category: "lifecycle",
278
+ rule: "tx_hash binding ensures Passport cannot be reused across transactions; write functions and result queries check tx_hash match",
279
+ applies_to: ["tx_hash field", "guard_add", "verify", "result"],
280
+ },
281
+ {
282
+ id: "T-PASS-06",
283
+ category: "structural",
284
+ rule: "submission data must match Guard identifier type; BCS serialization ≤ MAX_SUBMISSION_SIZE_PASSPORT=256 bytes",
285
+ applies_to: ["submission[].value_type", "submission[].identifier"],
286
+ },
287
+ {
288
+ id: "T-PASS-07",
289
+ category: "lifecycle",
290
+ rule: "result query must be in the same transaction (tx_hash matches current transaction); otherwise E_TX_NOT_MATCH=8",
291
+ applies_to: ["result operation", "result_for_guard", "result_for_permission"],
292
+ },
293
+ {
294
+ id: "T-PASS-08",
295
+ category: "lifecycle",
296
+ rule: "After freeze, Passport is permanently retained (cannot be destroyed); freezen calls transfer::freeze_object",
297
+ applies_to: ["freezen operation", "destroy operation"],
298
+ },
299
+ {
300
+ id: "T-PASS-09",
301
+ category: "lifecycle",
302
+ rule: "destroy must happen before freeze (destroyable when not frozen); after freezing the object becomes immutable and cannot be received by value",
303
+ applies_to: ["destroy operation", "freezen operation"],
304
+ },
305
+ {
306
+ id: "T-PASS-10",
307
+ category: "operational",
308
+ rule: "explainPassport must translate impack and result status; use passport.object (not passport.id) as the object identifier",
309
+ applies_to: ["explainPassport function", "ObjectPassportSchema"],
310
+ },
311
+ {
312
+ id: "T-PASS-11",
313
+ category: "logic",
314
+ rule: "relies logic (AND/OR) must be reflected in explainPassport; relies_logic_and=true=AND, false=OR",
315
+ applies_to: ["explainPassport function", "guard::relies(guard)"],
316
+ },
317
+ {
318
+ id: "T-PASS-12",
319
+ category: "structural",
320
+ rule: "Guard count ≤ MAX_GUARD_COUNT_PASSPORT=20; submission serialized size ≤ MAX_SUBMISSION_SIZE_PASSPORT=256 bytes",
321
+ applies_to: ["guard array", "submission array"],
322
+ },
323
+ ];
324
+ export const PASSPORT_TRANSLATION_VERSION = "1.0.0";
325
+ export function matchSemanticPattern(userIntent) {
326
+ const lower = userIntent.toLowerCase();
327
+ return SEMANTIC_TO_SCHEMA_RULES.filter(rule => rule.match_keywords.some(kw => lower.includes(kw.toLowerCase())));
328
+ }
329
+ export function explainPassport(passport) {
330
+ const lines = [];
331
+ lines.push(`Passport ${passport.object}`);
332
+ lines.push(` Signer: ${passport.signer}`);
333
+ lines.push(` Time: ${new Date(passport.time).toISOString()}`);
334
+ lines.push(` Verified: ${passport.has_verified}`);
335
+ if (passport.has_verified) {
336
+ lines.push(` Result: ${passport.result ? "PASS ✅" : "FAIL ❌"}`);
337
+ }
338
+ lines.push(` Guards: ${passport.info.length}/${MAX_GUARD_COUNT_PASSPORT}`);
339
+ if (passport.info.length > 0) {
340
+ lines.push(` Guard details:`);
341
+ for (const g of passport.info) {
342
+ const impackDesc = g.impack ? "IMPACK" : "non-impack";
343
+ const resultDesc = g.result ? "PASS" : "FAIL";
344
+ lines.push(` - Guard ${g.guard}: ${resultDesc} (${impackDesc})`);
345
+ }
346
+ }
347
+ if (passport.impack_guard && passport.impack_guard.length > 0) {
348
+ lines.push(` impack_guard list (lazy-filled): ${passport.impack_guard.join(", ")}`);
349
+ }
350
+ if (passport.tx_hash) {
351
+ lines.push(` tx_hash: ${passport.tx_hash}`);
352
+ }
353
+ return lines.join("\n");
354
+ }
355
+ export function passportJsonToSemantic(data) {
356
+ const lines = [];
357
+ if (data.type === "submission" || (data.guard && data.guard.length > 0)) {
358
+ lines.push("Operation: CREATE Passport via SubmissionCall");
359
+ if (data.guard && data.guard.length > 0) {
360
+ const impackCount = data.guard.filter(g => g.impack).length;
361
+ const nonImpackCount = data.guard.length - impackCount;
362
+ lines.push(`- Guards: ${data.guard.length}/${MAX_GUARD_COUNT_PASSPORT} (${impackCount} impack, ${nonImpackCount} non-impack)`);
363
+ if (impackCount === 0) {
364
+ lines.push(" ⚠️ No impack Guard — verify will abort E_IMPACK_GUARD_NOT_FOUND (9)");
365
+ }
366
+ data.guard.forEach((g, i) => {
367
+ const impackDesc = g.impack ? "IMPACK (affects result)" : "non-impack (audit-only)";
368
+ lines.push(` [${i}] ${g.object} — ${impackDesc}`);
369
+ });
370
+ }
371
+ if (data.submission && data.submission.length > 0) {
372
+ lines.push(`- Submissions: ${data.submission.length} guard(s) with submission data`);
373
+ for (const s of data.submission) {
374
+ const totalSize = s.submission.reduce((sum, item) => sum + estimateSubmissionSize(item.value_type), 0);
375
+ const sizeWarn = totalSize > MAX_SUBMISSION_SIZE_PASSPORT
376
+ ? ` ⚠️ ${totalSize} > ${MAX_SUBMISSION_SIZE_PASSPORT} bytes (E_SUBMISSION_SIZE_EXCEEDED)`
377
+ : "";
378
+ lines.push(` - guard=${s.guard}: ${s.submission.length} item(s), estimated size=${totalSize} bytes${sizeWarn}`);
379
+ }
380
+ }
381
+ }
382
+ else if (data.operation) {
383
+ lines.push(`Operation: ${data.operation.toUpperCase()}`);
384
+ switch (data.operation) {
385
+ case "verify":
386
+ lines.push("- One-time verification; sets has_verified=true, computes final result");
387
+ lines.push("- Aborts E_HAS_VERIFIED (4) if already verified");
388
+ break;
389
+ case "freezen":
390
+ lines.push("- Permanent freeze (transfer::freeze_object)");
391
+ lines.push("- Cannot be destroyed after freezing");
392
+ break;
393
+ case "destroy":
394
+ lines.push("- Permanent deletion (object::delete)");
395
+ lines.push("- Must be called BEFORE freeze");
396
+ break;
397
+ case "guard_clear":
398
+ lines.push("- Removes all Guards from Passport");
399
+ lines.push("- Only allowed before verify (E_HAS_VERIFIED if verified)");
400
+ break;
401
+ case "result_query":
402
+ lines.push("- Returns final verification result (bool)");
403
+ lines.push("- Requires has_verified=true (E_NOT_VERIFIED) and tx_hash match (E_TX_NOT_MATCH)");
404
+ break;
405
+ case "result_for_guard":
406
+ lines.push(`- Hard-verifies Guard ${data.guard_target} is impack and passed`);
407
+ lines.push("- Aborts E_NOT_IMPACK_GUARD (6) if not impack; E_VERIFY_FAILED (7) if result=false");
408
+ break;
409
+ case "result_for_permission":
410
+ lines.push("- Returns impack Guard address list (lazy-filled)");
411
+ lines.push("- Aborts E_VERIFY_FAILED (7) if overall result=false");
412
+ break;
413
+ case "submission_get":
414
+ lines.push(`- Reads submission value for (guard=${data.guard_target}, identifier=${data.identifier})`);
415
+ lines.push("- Read-only, no tx_hash check");
416
+ lines.push("- Aborts E_SUBMISSION_NOT_FOUND (10) if no entry");
417
+ break;
418
+ }
419
+ }
420
+ else {
421
+ lines.push("⚠️ Cannot determine operation: provide 'type: submission' with guard[], or 'operation' field");
422
+ }
423
+ return lines.join("\n");
424
+ }
425
+ export function semanticToPassportJson(intent) {
426
+ switch (intent.action) {
427
+ case "create": {
428
+ if (!intent.guards || intent.guards.length === 0) {
429
+ throw new Error("Create action requires at least 1 Guard in intent.guards");
430
+ }
431
+ if (intent.guards.length > MAX_GUARD_COUNT_PASSPORT) {
432
+ throw new Error(`Guard count ${intent.guards.length} exceeds MAX_GUARD_COUNT_PASSPORT=${MAX_GUARD_COUNT_PASSPORT}`);
433
+ }
434
+ const hasImpack = intent.guards.some(g => g.impack);
435
+ if (!hasImpack) {
436
+ throw new Error("At least 1 Guard must have impack=true (else verify aborts E_IMPACK_GUARD_NOT_FOUND=9)");
437
+ }
438
+ return {
439
+ type: "submission",
440
+ guard: intent.guards.map(g => ({ object: g.object, impack: g.impack })),
441
+ submission: intent.guards
442
+ .filter(g => g.submission && g.submission.length > 0)
443
+ .map(g => ({ guard: g.object, submission: g.submission })),
444
+ };
445
+ }
446
+ case "verify":
447
+ return { operation: "verify" };
448
+ case "freeze":
449
+ return { operation: "freezen" };
450
+ case "destroy":
451
+ return { operation: "destroy" };
452
+ case "guard_clear":
453
+ return { operation: "guard_clear" };
454
+ case "query_result":
455
+ return { operation: "result_query" };
456
+ case "query_guard_result":
457
+ if (!intent.targetGuard)
458
+ throw new Error("query_guard_result requires intent.targetGuard");
459
+ return { operation: "result_for_guard", guard_target: intent.targetGuard };
460
+ case "query_impack_list":
461
+ return { operation: "result_for_permission" };
462
+ case "get_submission":
463
+ if (!intent.targetGuard)
464
+ throw new Error("get_submission requires intent.targetGuard");
465
+ if (intent.targetIdentifier === undefined)
466
+ throw new Error("get_submission requires intent.targetIdentifier");
467
+ return {
468
+ operation: "submission_get",
469
+ guard_target: intent.targetGuard,
470
+ identifier: intent.targetIdentifier,
471
+ };
472
+ }
473
+ }
474
+ export function explainField(fieldName) {
475
+ return SCHEMA_TO_SEMANTIC_RULES.find(r => r.element_type === "field" && r.type_name === fieldName);
476
+ }
477
+ export function explainOp(opName) {
478
+ return SCHEMA_TO_SEMANTIC_RULES.find(r => r.element_type === "op" && r.type_name === opName);
479
+ }
480
+ export function explainImpack(impackValue) {
481
+ return SCHEMA_TO_SEMANTIC_RULES.find(r => r.element_type === "impack" && r.type_name === `impack=${impackValue}`);
482
+ }
483
+ export function explainReliesLogic(logicAnd) {
484
+ const name = logicAnd ? "AND (relies_logic_and=true)" : "OR (relies_logic_and=false)";
485
+ return SCHEMA_TO_SEMANTIC_RULES.find(r => r.element_type === "relies_logic" && r.type_name === name);
486
+ }
487
+ export function getConstraintsByCategory(category) {
488
+ return PASSPORT_CONSTRAINT_RULES.filter(r => r.category === category);
489
+ }
490
+ export function explainError(code) {
491
+ const descriptions = {
492
+ [PASSPORT_ERROR_CODES.E_GUARD_COUNT_EXCEEDED]: "Guard count exceeds MAX_GUARD_COUNT_PASSPORT (20) — remove non-essential Guards or merge similar ones",
493
+ [PASSPORT_ERROR_CODES.E_RELIES_GUARD_NOT_ADDED]: "Relied Guard not yet added — add relied Guards in topological order before adding the dependent Guard",
494
+ [PASSPORT_ERROR_CODES.E_SUBMISSION_SIZE_EXCEEDED]: "Submission serialized size exceeds MAX_SUBMISSION_SIZE_PASSPORT (256 bytes) — use Repository reference for large data",
495
+ [PASSPORT_ERROR_CODES.E_HAS_VERIFIED]: "Passport already verified — verify is one-time; create a new Passport to re-verify",
496
+ [PASSPORT_ERROR_CODES.E_NOT_VERIFIED]: "result() called before verify() — call verify() first in the same transaction",
497
+ [PASSPORT_ERROR_CODES.E_NOT_IMPACK_GUARD]: "result_for_guard called on non-impack Guard — only impack Guards can be hard-verified",
498
+ [PASSPORT_ERROR_CODES.E_VERIFY_FAILED]: "result_for_guard / result_for_permission called when overall result=false — fix Guard configuration or submission data",
499
+ [PASSPORT_ERROR_CODES.E_TX_NOT_MATCH]: "result() called from a different transaction — Passport is tx_hash-bound, must query in the same tx as verify()",
500
+ [PASSPORT_ERROR_CODES.E_IMPACK_GUARD_NOT_FOUND]: "verify() found no impack Guard — at least 1 Guard must have impack=true",
501
+ [PASSPORT_ERROR_CODES.E_SUBMISSION_NOT_FOUND]: "submission_get found no entry for (guard, identifier) — check Guard.table[identifier].b_submission=true",
502
+ [PASSPORT_ERROR_CODES.E_DIGEST_NOT_MATCH]: "guard_add / verify / guard_clear called from a different transaction — Passport is tx_hash-bound",
503
+ };
504
+ return descriptions[code] ?? `Unknown Passport error code: ${code}`;
505
+ }
506
+ function estimateSubmissionSize(valueType) {
507
+ switch (valueType) {
508
+ case "bool": return 1;
509
+ case "u8": return 1;
510
+ case "u64": return 8;
511
+ case "address": return 32;
512
+ case "string": return 32;
513
+ case "vector<u8>": return 32;
514
+ default: return 64;
515
+ }
516
+ }
@@ -0,0 +1,33 @@
1
+ export type PaymentRiskLevel = "CRITICAL" | "HIGH" | "MEDIUM" | "LOW" | "INFO";
2
+ export type PaymentRiskCategory = "structural" | "semantic" | "lifecycle" | "permission" | "cross_object" | "knowledge";
3
+ export type PaymentStakeholder = "signer" | "recipient" | "consumer" | "system";
4
+ export interface PaymentRisk {
5
+ id: string;
6
+ level: PaymentRiskLevel;
7
+ category: PaymentRiskCategory;
8
+ title: string;
9
+ description: string;
10
+ affected_stakeholders: PaymentStakeholder[];
11
+ scenario: string;
12
+ mitigation: string;
13
+ evidence?: string;
14
+ related_move_error?: string;
15
+ auto_fixable: boolean;
16
+ }
17
+ export interface PaymentRiskCheckContext {
18
+ recipient_count?: number;
19
+ uses_unsafe_unwrap?: boolean;
20
+ expects_mutation?: boolean;
21
+ payment_info_variant?: "payment_info" | "payment_info2" | "payment_info_with_guard" | "payment_info2_with_guard";
22
+ expects_user_recipient_registered?: boolean;
23
+ uses_signer_for_provenance?: boolean;
24
+ coin_field_lint_reviewed?: boolean;
25
+ constants_synced?: boolean;
26
+ }
27
+ export declare const PAYMENT_RISK_RULES: {
28
+ rule: PaymentRisk;
29
+ check: (ctx: PaymentRiskCheckContext) => PaymentRisk | null;
30
+ }[];
31
+ export declare const PAYMENT_RISK_VERSION = "1.0.0";
32
+ export declare function checkPaymentRisks(ctx: PaymentRiskCheckContext): PaymentRisk[];
33
+ export declare function getPaymentRiskById(id: string): PaymentRisk | undefined;