wowok 2.1.9 → 2.1.12

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 (887) hide show
  1. package/NOTICE +46 -0
  2. package/dist/cjs/bcs/bcs.d.ts +199 -199
  3. package/dist/cjs/bcs/bcs.js +273 -318
  4. package/dist/cjs/bcs/bcs.js.map +1 -0
  5. package/dist/cjs/bcs/effects.d.ts +109 -109
  6. package/dist/cjs/bcs/effects.js +205 -230
  7. package/dist/cjs/bcs/effects.js.map +1 -0
  8. package/dist/cjs/bcs/index.d.ts +1 -2584
  9. package/dist/cjs/bcs/index.js +61 -76
  10. package/dist/cjs/bcs/index.js.map +1 -0
  11. package/dist/cjs/bcs/pure.js +38 -58
  12. package/dist/cjs/bcs/pure.js.map +1 -0
  13. package/dist/cjs/bcs/type-tag-serializer.js +102 -114
  14. package/dist/cjs/bcs/type-tag-serializer.js.map +1 -0
  15. package/dist/cjs/bcs/types.js +6 -23
  16. package/dist/cjs/bcs/types.js.map +1 -0
  17. package/dist/cjs/client/index.js +17 -33
  18. package/dist/cjs/client/index.js.map +1 -0
  19. package/dist/cjs/client/network.js +25 -40
  20. package/dist/cjs/client/network.js.map +1 -0
  21. package/dist/cjs/cryptography/index.js +29 -45
  22. package/dist/cjs/cryptography/index.js.map +1 -0
  23. package/dist/cjs/cryptography/intent.d.ts +1 -1
  24. package/dist/cjs/cryptography/intent.js +20 -31
  25. package/dist/cjs/cryptography/intent.js.map +1 -0
  26. package/dist/cjs/cryptography/keypair.js +102 -116
  27. package/dist/cjs/cryptography/keypair.js.map +1 -0
  28. package/dist/cjs/cryptography/mnemonics.js +43 -41
  29. package/dist/cjs/cryptography/mnemonics.js.map +1 -0
  30. package/dist/cjs/cryptography/publickey.js +112 -134
  31. package/dist/cjs/cryptography/publickey.js.map +1 -0
  32. package/dist/cjs/cryptography/signature-scheme.js +24 -43
  33. package/dist/cjs/cryptography/signature-scheme.js.map +1 -0
  34. package/dist/cjs/cryptography/signature.d.ts +2 -24
  35. package/dist/cjs/cryptography/signature.js +50 -67
  36. package/dist/cjs/cryptography/signature.js.map +1 -0
  37. package/dist/cjs/experimental/cache.js +65 -0
  38. package/dist/cjs/experimental/cache.js.map +1 -0
  39. package/dist/cjs/experimental/client.js +27 -0
  40. package/dist/cjs/experimental/client.js.map +1 -0
  41. package/dist/cjs/experimental/core.js +89 -0
  42. package/dist/cjs/experimental/core.js.map +1 -0
  43. package/dist/cjs/experimental/errors.js +32 -0
  44. package/dist/cjs/experimental/errors.js.map +1 -0
  45. package/dist/cjs/experimental/index.js +15 -0
  46. package/dist/cjs/experimental/index.js.map +1 -0
  47. package/dist/cjs/experimental/persistent-storage.js +343 -0
  48. package/dist/cjs/experimental/persistent-storage.js.map +1 -0
  49. package/dist/cjs/experimental/persistent-storage.test.js +200 -0
  50. package/dist/cjs/experimental/persistent-storage.test.js.map +1 -0
  51. package/dist/cjs/experimental/transports/utils.js +104 -0
  52. package/dist/cjs/experimental/transports/utils.js.map +1 -0
  53. package/dist/cjs/experimental/types.js +6 -0
  54. package/dist/cjs/experimental/types.js.map +1 -0
  55. package/dist/cjs/faucet/faucet.js +106 -124
  56. package/dist/cjs/faucet/faucet.js.map +1 -0
  57. package/dist/cjs/faucet/index.js +12 -28
  58. package/dist/cjs/faucet/index.js.map +1 -0
  59. package/dist/cjs/grpc/client.js +47 -62
  60. package/dist/cjs/grpc/client.js.map +1 -0
  61. package/dist/cjs/grpc/core.js +580 -617
  62. package/dist/cjs/grpc/core.js.map +1 -0
  63. package/dist/cjs/grpc/index.js +9 -25
  64. package/dist/cjs/grpc/index.js.map +1 -0
  65. package/dist/cjs/grpc/proto/google/protobuf/any.js +168 -135
  66. package/dist/cjs/grpc/proto/google/protobuf/any.js.map +1 -0
  67. package/dist/cjs/grpc/proto/google/protobuf/duration.js +105 -90
  68. package/dist/cjs/grpc/proto/google/protobuf/duration.js.map +1 -0
  69. package/dist/cjs/grpc/proto/google/protobuf/empty.js +50 -28
  70. package/dist/cjs/grpc/proto/google/protobuf/empty.js.map +1 -0
  71. package/dist/cjs/grpc/proto/google/protobuf/field_mask.js +96 -75
  72. package/dist/cjs/grpc/proto/google/protobuf/field_mask.js.map +1 -0
  73. package/dist/cjs/grpc/proto/google/protobuf/struct.js +266 -215
  74. package/dist/cjs/grpc/proto/google/protobuf/struct.js.map +1 -0
  75. package/dist/cjs/grpc/proto/google/protobuf/timestamp.js +150 -131
  76. package/dist/cjs/grpc/proto/google/protobuf/timestamp.js.map +1 -0
  77. package/dist/cjs/grpc/proto/google/rpc/error_details.js +331 -302
  78. package/dist/cjs/grpc/proto/google/rpc/error_details.js.map +1 -0
  79. package/dist/cjs/grpc/proto/google/rpc/status.js +50 -50
  80. package/dist/cjs/grpc/proto/google/rpc/status.js.map +1 -0
  81. package/dist/cjs/grpc/proto/sui/rpc/v2/argument.js +84 -68
  82. package/dist/cjs/grpc/proto/sui/rpc/v2/argument.js.map +1 -0
  83. package/dist/cjs/grpc/proto/sui/rpc/v2/balance_change.js +45 -50
  84. package/dist/cjs/grpc/proto/sui/rpc/v2/balance_change.js.map +1 -0
  85. package/dist/cjs/grpc/proto/sui/rpc/v2/bcs.js +38 -43
  86. package/dist/cjs/grpc/proto/sui/rpc/v2/bcs.js.map +1 -0
  87. package/dist/cjs/grpc/proto/sui/rpc/v2/checkpoint.js +70 -75
  88. package/dist/cjs/grpc/proto/sui/rpc/v2/checkpoint.js.map +1 -0
  89. package/dist/cjs/grpc/proto/sui/rpc/v2/checkpoint_contents.js +79 -81
  90. package/dist/cjs/grpc/proto/sui/rpc/v2/checkpoint_contents.js.map +1 -0
  91. package/dist/cjs/grpc/proto/sui/rpc/v2/checkpoint_summary.js +183 -166
  92. package/dist/cjs/grpc/proto/sui/rpc/v2/checkpoint_summary.js.map +1 -0
  93. package/dist/cjs/grpc/proto/sui/rpc/v2/effects.js +369 -296
  94. package/dist/cjs/grpc/proto/sui/rpc/v2/effects.js.map +1 -0
  95. package/dist/cjs/grpc/proto/sui/rpc/v2/epoch.js +80 -85
  96. package/dist/cjs/grpc/proto/sui/rpc/v2/epoch.js.map +1 -0
  97. package/dist/cjs/grpc/proto/sui/rpc/v2/error_reason.js +31 -28
  98. package/dist/cjs/grpc/proto/sui/rpc/v2/error_reason.js.map +1 -0
  99. package/dist/cjs/grpc/proto/sui/rpc/v2/event.js +81 -83
  100. package/dist/cjs/grpc/proto/sui/rpc/v2/event.js.map +1 -0
  101. package/dist/cjs/grpc/proto/sui/rpc/v2/executed_transaction.js +80 -85
  102. package/dist/cjs/grpc/proto/sui/rpc/v2/executed_transaction.js.map +1 -0
  103. package/dist/cjs/grpc/proto/sui/rpc/v2/execution_status.js +876 -506
  104. package/dist/cjs/grpc/proto/sui/rpc/v2/execution_status.js.map +1 -0
  105. package/dist/cjs/grpc/proto/sui/rpc/v2/gas_cost_summary.js +56 -61
  106. package/dist/cjs/grpc/proto/sui/rpc/v2/gas_cost_summary.js.map +1 -0
  107. package/dist/cjs/grpc/proto/sui/rpc/v2/input.js +103 -83
  108. package/dist/cjs/grpc/proto/sui/rpc/v2/input.js.map +1 -0
  109. package/dist/cjs/grpc/proto/sui/rpc/v2/jwk.js +76 -78
  110. package/dist/cjs/grpc/proto/sui/rpc/v2/jwk.js.map +1 -0
  111. package/dist/cjs/grpc/proto/sui/rpc/v2/ledger_service.client.js +69 -119
  112. package/dist/cjs/grpc/proto/sui/rpc/v2/ledger_service.client.js.map +1 -0
  113. package/dist/cjs/grpc/proto/sui/rpc/v2/ledger_service.js +392 -350
  114. package/dist/cjs/grpc/proto/sui/rpc/v2/ledger_service.js.map +1 -0
  115. package/dist/cjs/grpc/proto/sui/rpc/v2/move_package.js +599 -473
  116. package/dist/cjs/grpc/proto/sui/rpc/v2/move_package.js.map +1 -0
  117. package/dist/cjs/grpc/proto/sui/rpc/v2/move_package_service.client.js +46 -78
  118. package/dist/cjs/grpc/proto/sui/rpc/v2/move_package_service.client.js.map +1 -0
  119. package/dist/cjs/grpc/proto/sui/rpc/v2/move_package_service.js +242 -224
  120. package/dist/cjs/grpc/proto/sui/rpc/v2/move_package_service.js.map +1 -0
  121. package/dist/cjs/grpc/proto/sui/rpc/v2/name_service.client.js +32 -52
  122. package/dist/cjs/grpc/proto/sui/rpc/v2/name_service.client.js.map +1 -0
  123. package/dist/cjs/grpc/proto/sui/rpc/v2/name_service.js +139 -134
  124. package/dist/cjs/grpc/proto/sui/rpc/v2/name_service.js.map +1 -0
  125. package/dist/cjs/grpc/proto/sui/rpc/v2/object.js +109 -111
  126. package/dist/cjs/grpc/proto/sui/rpc/v2/object.js.map +1 -0
  127. package/dist/cjs/grpc/proto/sui/rpc/v2/object_reference.js +46 -51
  128. package/dist/cjs/grpc/proto/sui/rpc/v2/object_reference.js.map +1 -0
  129. package/dist/cjs/grpc/proto/sui/rpc/v2/owner.js +76 -61
  130. package/dist/cjs/grpc/proto/sui/rpc/v2/owner.js.map +1 -0
  131. package/dist/cjs/grpc/proto/sui/rpc/v2/protocol_config.js +46 -59
  132. package/dist/cjs/grpc/proto/sui/rpc/v2/protocol_config.js.map +1 -0
  133. package/dist/cjs/grpc/proto/sui/rpc/v2/signature.js +568 -522
  134. package/dist/cjs/grpc/proto/sui/rpc/v2/signature.js.map +1 -0
  135. package/dist/cjs/grpc/proto/sui/rpc/v2/signature_scheme.js +54 -32
  136. package/dist/cjs/grpc/proto/sui/rpc/v2/signature_scheme.js.map +1 -0
  137. package/dist/cjs/grpc/proto/sui/rpc/v2/signature_verification_service.client.js +27 -47
  138. package/dist/cjs/grpc/proto/sui/rpc/v2/signature_verification_service.client.js.map +1 -0
  139. package/dist/cjs/grpc/proto/sui/rpc/v2/signature_verification_service.js +83 -86
  140. package/dist/cjs/grpc/proto/sui/rpc/v2/signature_verification_service.js.map +1 -0
  141. package/dist/cjs/grpc/proto/sui/rpc/v2/state_service.client.js +53 -85
  142. package/dist/cjs/grpc/proto/sui/rpc/v2/state_service.client.js.map +1 -0
  143. package/dist/cjs/grpc/proto/sui/rpc/v2/state_service.js +645 -529
  144. package/dist/cjs/grpc/proto/sui/rpc/v2/state_service.js.map +1 -0
  145. package/dist/cjs/grpc/proto/sui/rpc/v2/subscription_service.client.js +37 -51
  146. package/dist/cjs/grpc/proto/sui/rpc/v2/subscription_service.client.js.map +1 -0
  147. package/dist/cjs/grpc/proto/sui/rpc/v2/subscription_service.js +58 -61
  148. package/dist/cjs/grpc/proto/sui/rpc/v2/subscription_service.js.map +1 -0
  149. package/dist/cjs/grpc/proto/sui/rpc/v2/system_state.js +749 -730
  150. package/dist/cjs/grpc/proto/sui/rpc/v2/system_state.js.map +1 -0
  151. package/dist/cjs/grpc/proto/sui/rpc/v2/transaction.js +1218 -975
  152. package/dist/cjs/grpc/proto/sui/rpc/v2/transaction.js.map +1 -0
  153. package/dist/cjs/grpc/proto/sui/rpc/v2/transaction_execution_service.client.js +32 -46
  154. package/dist/cjs/grpc/proto/sui/rpc/v2/transaction_execution_service.client.js.map +1 -0
  155. package/dist/cjs/grpc/proto/sui/rpc/v2/transaction_execution_service.js +186 -167
  156. package/dist/cjs/grpc/proto/sui/rpc/v2/transaction_execution_service.js.map +1 -0
  157. package/dist/cjs/index.js +96 -91
  158. package/dist/cjs/index.js.map +1 -0
  159. package/dist/cjs/jsonRpc/client.js +654 -743
  160. package/dist/cjs/jsonRpc/client.js.map +1 -0
  161. package/dist/cjs/jsonRpc/core.d.ts +7 -7
  162. package/dist/cjs/jsonRpc/core.js +562 -606
  163. package/dist/cjs/jsonRpc/core.js.map +1 -0
  164. package/dist/cjs/jsonRpc/errors.js +38 -56
  165. package/dist/cjs/jsonRpc/errors.js.map +1 -0
  166. package/dist/cjs/jsonRpc/http-transport.js +70 -114
  167. package/dist/cjs/jsonRpc/http-transport.js.map +1 -0
  168. package/dist/cjs/jsonRpc/index.js +14 -30
  169. package/dist/cjs/jsonRpc/index.js.map +1 -0
  170. package/dist/cjs/jsonRpc/json-rpc-resolver.js +286 -290
  171. package/dist/cjs/jsonRpc/json-rpc-resolver.js.map +1 -0
  172. package/dist/cjs/jsonRpc/rpc-websocket-client.js +150 -207
  173. package/dist/cjs/jsonRpc/rpc-websocket-client.js.map +1 -0
  174. package/dist/cjs/jsonRpc/types/chain.js +4 -15
  175. package/dist/cjs/jsonRpc/types/chain.js.map +1 -0
  176. package/dist/cjs/jsonRpc/types/changes.js +4 -15
  177. package/dist/cjs/jsonRpc/types/changes.js.map +1 -0
  178. package/dist/cjs/jsonRpc/types/coins.js +4 -15
  179. package/dist/cjs/jsonRpc/types/coins.js.map +1 -0
  180. package/dist/cjs/jsonRpc/types/common.js +4 -15
  181. package/dist/cjs/jsonRpc/types/common.js.map +1 -0
  182. package/dist/cjs/jsonRpc/types/generated.d.ts +1 -1
  183. package/dist/cjs/jsonRpc/types/generated.js +4 -15
  184. package/dist/cjs/jsonRpc/types/generated.js.map +1 -0
  185. package/dist/cjs/jsonRpc/types/index.js +4 -15
  186. package/dist/cjs/jsonRpc/types/index.js.map +1 -0
  187. package/dist/cjs/jsonRpc/types/params.js +4 -15
  188. package/dist/cjs/jsonRpc/types/params.js.map +1 -0
  189. package/dist/cjs/keypairs/ed25519/ed25519-hd-key.js +54 -69
  190. package/dist/cjs/keypairs/ed25519/ed25519-hd-key.js.map +1 -0
  191. package/dist/cjs/keypairs/ed25519/index.js +10 -26
  192. package/dist/cjs/keypairs/ed25519/index.js.map +1 -0
  193. package/dist/cjs/keypairs/ed25519/keypair.js +134 -159
  194. package/dist/cjs/keypairs/ed25519/keypair.js.map +1 -0
  195. package/dist/cjs/keypairs/ed25519/publickey.js +70 -84
  196. package/dist/cjs/keypairs/ed25519/publickey.js.map +1 -0
  197. package/dist/cjs/keypairs/index.js +21 -19
  198. package/dist/cjs/keypairs/index.js.map +1 -0
  199. package/dist/cjs/keypairs/passkey/index.js +11 -27
  200. package/dist/cjs/keypairs/passkey/index.js.map +1 -0
  201. package/dist/cjs/keypairs/passkey/keypair.js +245 -256
  202. package/dist/cjs/keypairs/passkey/keypair.js.map +1 -0
  203. package/dist/cjs/keypairs/passkey/publickey.js +163 -162
  204. package/dist/cjs/keypairs/passkey/publickey.js.map +1 -0
  205. package/dist/cjs/keypairs/passkey/types.js +4 -15
  206. package/dist/cjs/keypairs/passkey/types.js.map +1 -0
  207. package/dist/cjs/keypairs/secp256k1/index.js +10 -26
  208. package/dist/cjs/keypairs/secp256k1/index.js.map +1 -0
  209. package/dist/cjs/keypairs/secp256k1/keypair.js +129 -151
  210. package/dist/cjs/keypairs/secp256k1/keypair.js.map +1 -0
  211. package/dist/cjs/keypairs/secp256k1/publickey.js +71 -89
  212. package/dist/cjs/keypairs/secp256k1/publickey.js.map +1 -0
  213. package/dist/cjs/keypairs/secp256r1/index.js +10 -26
  214. package/dist/cjs/keypairs/secp256r1/index.js.map +1 -0
  215. package/dist/cjs/keypairs/secp256r1/keypair.js +127 -148
  216. package/dist/cjs/keypairs/secp256r1/keypair.js.map +1 -0
  217. package/dist/cjs/keypairs/secp256r1/publickey.js +72 -90
  218. package/dist/cjs/keypairs/secp256r1/publickey.js.map +1 -0
  219. package/dist/cjs/multisig/index.js +10 -26
  220. package/dist/cjs/multisig/index.js.map +1 -0
  221. package/dist/cjs/multisig/publickey.d.ts +1 -1
  222. package/dist/cjs/multisig/publickey.js +228 -276
  223. package/dist/cjs/multisig/publickey.js.map +1 -0
  224. package/dist/cjs/multisig/signer.js +62 -110
  225. package/dist/cjs/multisig/signer.js.map +1 -0
  226. package/dist/cjs/transactions/Arguments.d.ts +4 -4
  227. package/dist/cjs/transactions/Arguments.js +13 -34
  228. package/dist/cjs/transactions/Arguments.js.map +1 -0
  229. package/dist/cjs/transactions/Commands.js +111 -141
  230. package/dist/cjs/transactions/Commands.js.map +1 -0
  231. package/dist/cjs/transactions/Inputs.js +53 -82
  232. package/dist/cjs/transactions/Inputs.js.map +1 -0
  233. package/dist/cjs/transactions/ObjectCache.d.ts +8 -8
  234. package/dist/cjs/transactions/ObjectCache.js +204 -241
  235. package/dist/cjs/transactions/ObjectCache.js.map +1 -0
  236. package/dist/cjs/transactions/Transaction.d.ts +31 -31
  237. package/dist/cjs/transactions/Transaction.js +628 -719
  238. package/dist/cjs/transactions/Transaction.js.map +1 -0
  239. package/dist/cjs/transactions/TransactionData.d.ts +9 -9
  240. package/dist/cjs/transactions/TransactionData.js +396 -440
  241. package/dist/cjs/transactions/TransactionData.js.map +1 -0
  242. package/dist/cjs/transactions/__tests__/Transaction.test.js +169 -0
  243. package/dist/cjs/transactions/__tests__/Transaction.test.js.map +1 -0
  244. package/dist/cjs/transactions/__tests__/bcs.test.js +202 -0
  245. package/dist/cjs/transactions/__tests__/bcs.test.js.map +1 -0
  246. package/dist/cjs/transactions/data/internal.js +166 -207
  247. package/dist/cjs/transactions/data/internal.js.map +1 -0
  248. package/dist/cjs/transactions/data/v1.js +436 -495
  249. package/dist/cjs/transactions/data/v1.js.map +1 -0
  250. package/dist/cjs/transactions/data/v2.d.ts +5 -5
  251. package/dist/cjs/transactions/data/v2.js +94 -107
  252. package/dist/cjs/transactions/data/v2.js.map +1 -0
  253. package/dist/cjs/transactions/executor/caching.js +71 -113
  254. package/dist/cjs/transactions/executor/caching.js.map +1 -0
  255. package/dist/cjs/transactions/executor/parallel.js +339 -378
  256. package/dist/cjs/transactions/executor/parallel.js.map +1 -0
  257. package/dist/cjs/transactions/executor/queue.js +60 -80
  258. package/dist/cjs/transactions/executor/queue.js.map +1 -0
  259. package/dist/cjs/transactions/executor/serial.d.ts +4 -4
  260. package/dist/cjs/transactions/executor/serial.js +102 -131
  261. package/dist/cjs/transactions/executor/serial.js.map +1 -0
  262. package/dist/cjs/transactions/hash.js +17 -28
  263. package/dist/cjs/transactions/hash.js.map +1 -0
  264. package/dist/cjs/transactions/index.js +33 -49
  265. package/dist/cjs/transactions/index.js.map +1 -0
  266. package/dist/cjs/transactions/intents/CoinWithBalance.js +137 -191
  267. package/dist/cjs/transactions/intents/CoinWithBalance.js.map +1 -0
  268. package/dist/cjs/transactions/object.js +88 -111
  269. package/dist/cjs/transactions/object.js.map +1 -0
  270. package/dist/cjs/transactions/plugins/NamedPackagesPlugin.js +20 -32
  271. package/dist/cjs/transactions/plugins/NamedPackagesPlugin.js.map +1 -0
  272. package/dist/cjs/transactions/pure.js +38 -60
  273. package/dist/cjs/transactions/pure.js.map +1 -0
  274. package/dist/cjs/transactions/resolve.js +62 -88
  275. package/dist/cjs/transactions/resolve.js.map +1 -0
  276. package/dist/cjs/transactions/serializer.js +150 -163
  277. package/dist/cjs/transactions/serializer.js.map +1 -0
  278. package/dist/cjs/transactions/utils.d.ts +1 -1
  279. package/dist/cjs/transactions/utils.js +114 -125
  280. package/dist/cjs/transactions/utils.js.map +1 -0
  281. package/dist/cjs/utils/constants.js +29 -56
  282. package/dist/cjs/utils/constants.js.map +1 -0
  283. package/dist/cjs/utils/derived-objects.js +14 -30
  284. package/dist/cjs/utils/derived-objects.js.map +1 -0
  285. package/dist/cjs/utils/dynamic-fields.js +20 -37
  286. package/dist/cjs/utils/dynamic-fields.js.map +1 -0
  287. package/dist/cjs/utils/format.js +14 -30
  288. package/dist/cjs/utils/format.js.map +1 -0
  289. package/dist/cjs/utils/index.js +50 -64
  290. package/dist/cjs/utils/index.js.map +1 -0
  291. package/dist/cjs/utils/move-registry.js +37 -35
  292. package/dist/cjs/utils/move-registry.js.map +1 -0
  293. package/dist/cjs/utils/sui-types.js +74 -68
  294. package/dist/cjs/utils/sui-types.js.map +1 -0
  295. package/dist/cjs/utils/suins.js +30 -46
  296. package/dist/cjs/utils/suins.js.map +1 -0
  297. package/dist/cjs/verify/index.js +12 -27
  298. package/dist/cjs/verify/index.js.map +1 -0
  299. package/dist/cjs/verify/verify.js +83 -110
  300. package/dist/cjs/verify/verify.js.map +1 -0
  301. package/dist/cjs/version.js +8 -25
  302. package/dist/cjs/version.js.map +1 -0
  303. package/dist/cjs/w/call/allocation.js +323 -413
  304. package/dist/cjs/w/call/allocation.js.map +1 -0
  305. package/dist/cjs/w/call/arb.js +105 -136
  306. package/dist/cjs/w/call/arb.js.map +1 -0
  307. package/dist/cjs/w/call/arbitration.js +1206 -1581
  308. package/dist/cjs/w/call/arbitration.js.map +1 -0
  309. package/dist/cjs/w/call/base.js +303 -333
  310. package/dist/cjs/w/call/base.js.map +1 -0
  311. package/dist/cjs/w/call/contact.js +335 -452
  312. package/dist/cjs/w/call/contact.js.map +1 -0
  313. package/dist/cjs/w/call/demand.js +690 -844
  314. package/dist/cjs/w/call/demand.js.map +1 -0
  315. package/dist/cjs/w/call/entity.js +167 -201
  316. package/dist/cjs/w/call/entity.js.map +1 -0
  317. package/dist/cjs/w/call/guard-ins.d.ts +1 -0
  318. package/dist/cjs/w/call/guard-ins.js +4376 -4384
  319. package/dist/cjs/w/call/guard-ins.js.map +1 -0
  320. package/dist/cjs/w/call/guard.d.ts +10 -0
  321. package/dist/cjs/w/call/guard.js +1078 -1119
  322. package/dist/cjs/w/call/guard.js.map +1 -0
  323. package/dist/cjs/w/call/index.d.ts +1 -1
  324. package/dist/cjs/w/call/index.js +69 -69
  325. package/dist/cjs/w/call/index.js.map +1 -0
  326. package/dist/cjs/w/call/machine.js +1105 -1419
  327. package/dist/cjs/w/call/machine.js.map +1 -0
  328. package/dist/cjs/w/call/order.js +314 -454
  329. package/dist/cjs/w/call/order.js.map +1 -0
  330. package/dist/cjs/w/call/passport.js +214 -253
  331. package/dist/cjs/w/call/passport.js.map +1 -0
  332. package/dist/cjs/w/call/payment.js +187 -224
  333. package/dist/cjs/w/call/payment.js.map +1 -0
  334. package/dist/cjs/w/call/permission.js +1183 -1294
  335. package/dist/cjs/w/call/permission.js.map +1 -0
  336. package/dist/cjs/w/call/personal.js +132 -170
  337. package/dist/cjs/w/call/personal.js.map +1 -0
  338. package/dist/cjs/w/call/progress.js +634 -794
  339. package/dist/cjs/w/call/progress.js.map +1 -0
  340. package/dist/cjs/w/call/proof.js +67 -116
  341. package/dist/cjs/w/call/proof.js.map +1 -0
  342. package/dist/cjs/w/call/repository.js +1037 -1251
  343. package/dist/cjs/w/call/repository.js.map +1 -0
  344. package/dist/cjs/w/call/resource.js +111 -131
  345. package/dist/cjs/w/call/resource.js.map +1 -0
  346. package/dist/cjs/w/call/reward.js +675 -853
  347. package/dist/cjs/w/call/reward.js.map +1 -0
  348. package/dist/cjs/w/call/service.js +1879 -2385
  349. package/dist/cjs/w/call/service.js.map +1 -0
  350. package/dist/cjs/w/call/treasury.js +841 -1138
  351. package/dist/cjs/w/call/treasury.js.map +1 -0
  352. package/dist/cjs/w/call/util.js +593 -624
  353. package/dist/cjs/w/call/util.js.map +1 -0
  354. package/dist/cjs/w/common.d.ts +1 -1
  355. package/dist/cjs/w/common.js +548 -518
  356. package/dist/cjs/w/common.js.map +1 -0
  357. package/dist/cjs/w/exception.js +574 -584
  358. package/dist/cjs/w/exception.js.map +1 -0
  359. package/dist/cjs/w/index.js +26 -23
  360. package/dist/cjs/w/index.js.map +1 -0
  361. package/dist/cjs/w/local/account.js +664 -741
  362. package/dist/cjs/w/local/account.js.map +1 -0
  363. package/dist/cjs/w/local/cache.js +180 -166
  364. package/dist/cjs/w/local/cache.js.map +1 -0
  365. package/dist/cjs/w/local/config.js +51 -80
  366. package/dist/cjs/w/local/config.js.map +1 -0
  367. package/dist/cjs/w/local/index.js +225 -290
  368. package/dist/cjs/w/local/index.js.map +1 -0
  369. package/dist/cjs/w/local/local.d.ts +2 -2
  370. package/dist/cjs/w/local/local.js +638 -646
  371. package/dist/cjs/w/local/local.js.map +1 -0
  372. package/dist/cjs/w/local/storage.js +210 -164
  373. package/dist/cjs/w/local/storage.js.map +1 -0
  374. package/dist/cjs/w/local/token.js +158 -175
  375. package/dist/cjs/w/local/token.js.map +1 -0
  376. package/dist/cjs/w/local/util.js +80 -51
  377. package/dist/cjs/w/local/util.js.map +1 -0
  378. package/dist/cjs/w/local/wip.js +1078 -802
  379. package/dist/cjs/w/local/wip.js.map +1 -0
  380. package/dist/cjs/w/messenger/crypto.js +496 -389
  381. package/dist/cjs/w/messenger/crypto.js.map +1 -0
  382. package/dist/cjs/w/messenger/index.js +53 -35
  383. package/dist/cjs/w/messenger/index.js.map +1 -0
  384. package/dist/cjs/w/messenger/messenger-api.js +1159 -1035
  385. package/dist/cjs/w/messenger/messenger-api.js.map +1 -0
  386. package/dist/cjs/w/messenger/messenger-manager.js +954 -1083
  387. package/dist/cjs/w/messenger/messenger-manager.js.map +1 -0
  388. package/dist/cjs/w/messenger/messenger.d.ts +1 -1
  389. package/dist/cjs/w/messenger/messenger.js +1304 -1450
  390. package/dist/cjs/w/messenger/messenger.js.map +1 -0
  391. package/dist/cjs/w/messenger/server.js +390 -512
  392. package/dist/cjs/w/messenger/server.js.map +1 -0
  393. package/dist/cjs/w/messenger/session.js +399 -403
  394. package/dist/cjs/w/messenger/session.js.map +1 -0
  395. package/dist/cjs/w/messenger/storage.js +881 -777
  396. package/dist/cjs/w/messenger/storage.js.map +1 -0
  397. package/dist/cjs/w/messenger/types.d.ts +2 -2
  398. package/dist/cjs/w/messenger/types.js +83 -103
  399. package/dist/cjs/w/messenger/types.js.map +1 -0
  400. package/dist/cjs/w/messenger/utils.js +29 -34
  401. package/dist/cjs/w/messenger/utils.js.map +1 -0
  402. package/dist/cjs/w/query/bult-in.js +101 -110
  403. package/dist/cjs/w/query/bult-in.js.map +1 -0
  404. package/dist/cjs/w/query/event.js +134 -146
  405. package/dist/cjs/w/query/event.js.map +1 -0
  406. package/dist/cjs/w/query/index.js +22 -20
  407. package/dist/cjs/w/query/index.js.map +1 -0
  408. package/dist/cjs/w/query/object.js +1576 -1576
  409. package/dist/cjs/w/query/object.js.map +1 -0
  410. package/dist/cjs/w/query/received.js +66 -88
  411. package/dist/cjs/w/query/received.js.map +1 -0
  412. package/dist/cjs/w/query/util.js +53 -77
  413. package/dist/cjs/w/query/util.js.map +1 -0
  414. package/dist/cjs/w/util.js +589 -675
  415. package/dist/cjs/w/util.js.map +1 -0
  416. package/dist/esm/bcs/bcs.d.ts +199 -199
  417. package/dist/esm/bcs/bcs.js +269 -310
  418. package/dist/esm/bcs/bcs.js.map +1 -0
  419. package/dist/esm/bcs/effects.d.ts +109 -109
  420. package/dist/esm/bcs/effects.js +171 -179
  421. package/dist/esm/bcs/effects.js.map +1 -0
  422. package/dist/esm/bcs/index.d.ts +1 -2584
  423. package/dist/esm/bcs/index.js +51 -94
  424. package/dist/esm/bcs/index.js.map +1 -0
  425. package/dist/esm/bcs/pure.js +35 -38
  426. package/dist/esm/bcs/pure.js.map +1 -0
  427. package/dist/esm/bcs/type-tag-serializer.js +98 -95
  428. package/dist/esm/bcs/type-tag-serializer.js.map +1 -0
  429. package/dist/esm/bcs/types.js +5 -5
  430. package/dist/esm/bcs/types.js.map +1 -0
  431. package/dist/esm/client/index.js +7 -23
  432. package/dist/esm/client/index.js.map +1 -0
  433. package/dist/esm/client/network.js +23 -22
  434. package/dist/esm/client/network.js.map +1 -0
  435. package/dist/esm/cryptography/index.js +9 -46
  436. package/dist/esm/cryptography/index.js.map +1 -0
  437. package/dist/esm/cryptography/intent.d.ts +1 -1
  438. package/dist/esm/cryptography/intent.js +18 -12
  439. package/dist/esm/cryptography/intent.js.map +1 -0
  440. package/dist/esm/cryptography/keypair.js +95 -99
  441. package/dist/esm/cryptography/keypair.js.map +1 -0
  442. package/dist/esm/cryptography/mnemonics.js +40 -24
  443. package/dist/esm/cryptography/mnemonics.js.map +1 -0
  444. package/dist/esm/cryptography/publickey.js +104 -115
  445. package/dist/esm/cryptography/publickey.js.map +1 -0
  446. package/dist/esm/cryptography/signature-scheme.js +22 -24
  447. package/dist/esm/cryptography/signature-scheme.js.map +1 -0
  448. package/dist/esm/cryptography/signature.d.ts +2 -24
  449. package/dist/esm/cryptography/signature.js +44 -48
  450. package/dist/esm/cryptography/signature.js.map +1 -0
  451. package/dist/esm/experimental/cache.js +61 -0
  452. package/dist/esm/experimental/cache.js.map +1 -0
  453. package/dist/esm/experimental/client.js +23 -0
  454. package/dist/esm/experimental/client.js.map +1 -0
  455. package/dist/esm/experimental/core.js +85 -0
  456. package/dist/esm/experimental/core.js.map +1 -0
  457. package/dist/esm/experimental/errors.js +27 -0
  458. package/dist/esm/experimental/errors.js.map +1 -0
  459. package/dist/esm/experimental/index.js +8 -0
  460. package/dist/esm/experimental/index.js.map +1 -0
  461. package/dist/esm/experimental/persistent-storage.js +337 -0
  462. package/dist/esm/experimental/persistent-storage.js.map +1 -0
  463. package/dist/esm/experimental/persistent-storage.test.js +198 -0
  464. package/dist/esm/experimental/persistent-storage.test.js.map +1 -0
  465. package/dist/esm/experimental/transports/utils.js +100 -0
  466. package/dist/esm/experimental/transports/utils.js.map +1 -0
  467. package/dist/esm/experimental/types.js +5 -0
  468. package/dist/esm/experimental/types.js.map +1 -0
  469. package/dist/esm/faucet/faucet.js +104 -111
  470. package/dist/esm/faucet/faucet.js.map +1 -0
  471. package/dist/esm/faucet/index.js +4 -16
  472. package/dist/esm/faucet/index.js.map +1 -0
  473. package/dist/esm/grpc/client.js +34 -34
  474. package/dist/esm/grpc/client.js.map +1 -0
  475. package/dist/esm/grpc/core.js +570 -601
  476. package/dist/esm/grpc/core.js.map +1 -0
  477. package/dist/esm/grpc/index.js +5 -6
  478. package/dist/esm/grpc/index.js.map +1 -0
  479. package/dist/esm/grpc/proto/google/protobuf/any.js +161 -111
  480. package/dist/esm/grpc/proto/google/protobuf/any.js.map +1 -0
  481. package/dist/esm/grpc/proto/google/protobuf/duration.js +99 -67
  482. package/dist/esm/grpc/proto/google/protobuf/duration.js.map +1 -0
  483. package/dist/esm/grpc/proto/google/protobuf/empty.js +46 -7
  484. package/dist/esm/grpc/proto/google/protobuf/empty.js.map +1 -0
  485. package/dist/esm/grpc/proto/google/protobuf/field_mask.js +90 -52
  486. package/dist/esm/grpc/proto/google/protobuf/field_mask.js.map +1 -0
  487. package/dist/esm/grpc/proto/google/protobuf/struct.js +258 -190
  488. package/dist/esm/grpc/proto/google/protobuf/struct.js.map +1 -0
  489. package/dist/esm/grpc/proto/google/protobuf/timestamp.js +144 -108
  490. package/dist/esm/grpc/proto/google/protobuf/timestamp.js.map +1 -0
  491. package/dist/esm/grpc/proto/google/rpc/error_details.js +313 -267
  492. package/dist/esm/grpc/proto/google/rpc/error_details.js.map +1 -0
  493. package/dist/esm/grpc/proto/google/rpc/status.js +45 -28
  494. package/dist/esm/grpc/proto/google/rpc/status.js.map +1 -0
  495. package/dist/esm/grpc/proto/sui/rpc/v2/argument.js +80 -47
  496. package/dist/esm/grpc/proto/sui/rpc/v2/argument.js.map +1 -0
  497. package/dist/esm/grpc/proto/sui/rpc/v2/balance_change.js +41 -29
  498. package/dist/esm/grpc/proto/sui/rpc/v2/balance_change.js.map +1 -0
  499. package/dist/esm/grpc/proto/sui/rpc/v2/bcs.js +34 -22
  500. package/dist/esm/grpc/proto/sui/rpc/v2/bcs.js.map +1 -0
  501. package/dist/esm/grpc/proto/sui/rpc/v2/checkpoint.js +61 -49
  502. package/dist/esm/grpc/proto/sui/rpc/v2/checkpoint.js.map +1 -0
  503. package/dist/esm/grpc/proto/sui/rpc/v2/checkpoint_contents.js +72 -57
  504. package/dist/esm/grpc/proto/sui/rpc/v2/checkpoint_contents.js.map +1 -0
  505. package/dist/esm/grpc/proto/sui/rpc/v2/checkpoint_summary.js +173 -139
  506. package/dist/esm/grpc/proto/sui/rpc/v2/checkpoint_summary.js.map +1 -0
  507. package/dist/esm/grpc/proto/sui/rpc/v2/effects.js +358 -268
  508. package/dist/esm/grpc/proto/sui/rpc/v2/effects.js.map +1 -0
  509. package/dist/esm/grpc/proto/sui/rpc/v2/epoch.js +72 -60
  510. package/dist/esm/grpc/proto/sui/rpc/v2/epoch.js.map +1 -0
  511. package/dist/esm/grpc/proto/sui/rpc/v2/error_reason.js +29 -9
  512. package/dist/esm/grpc/proto/sui/rpc/v2/error_reason.js.map +1 -0
  513. package/dist/esm/grpc/proto/sui/rpc/v2/event.js +74 -59
  514. package/dist/esm/grpc/proto/sui/rpc/v2/event.js.map +1 -0
  515. package/dist/esm/grpc/proto/sui/rpc/v2/executed_transaction.js +69 -57
  516. package/dist/esm/grpc/proto/sui/rpc/v2/executed_transaction.js.map +1 -0
  517. package/dist/esm/grpc/proto/sui/rpc/v2/execution_status.js +861 -474
  518. package/dist/esm/grpc/proto/sui/rpc/v2/execution_status.js.map +1 -0
  519. package/dist/esm/grpc/proto/sui/rpc/v2/gas_cost_summary.js +52 -40
  520. package/dist/esm/grpc/proto/sui/rpc/v2/gas_cost_summary.js.map +1 -0
  521. package/dist/esm/grpc/proto/sui/rpc/v2/input.js +98 -61
  522. package/dist/esm/grpc/proto/sui/rpc/v2/input.js.map +1 -0
  523. package/dist/esm/grpc/proto/sui/rpc/v2/jwk.js +71 -56
  524. package/dist/esm/grpc/proto/sui/rpc/v2/jwk.js.map +1 -0
  525. package/dist/esm/grpc/proto/sui/rpc/v2/ledger_service.client.js +65 -100
  526. package/dist/esm/grpc/proto/sui/rpc/v2/ledger_service.client.js.map +1 -0
  527. package/dist/esm/grpc/proto/sui/rpc/v2/ledger_service.js +365 -306
  528. package/dist/esm/grpc/proto/sui/rpc/v2/ledger_service.js.map +1 -0
  529. package/dist/esm/grpc/proto/sui/rpc/v2/move_package.js +585 -442
  530. package/dist/esm/grpc/proto/sui/rpc/v2/move_package.js.map +1 -0
  531. package/dist/esm/grpc/proto/sui/rpc/v2/move_package_service.client.js +42 -59
  532. package/dist/esm/grpc/proto/sui/rpc/v2/move_package_service.client.js.map +1 -0
  533. package/dist/esm/grpc/proto/sui/rpc/v2/move_package_service.js +226 -191
  534. package/dist/esm/grpc/proto/sui/rpc/v2/move_package_service.js.map +1 -0
  535. package/dist/esm/grpc/proto/sui/rpc/v2/name_service.client.js +28 -33
  536. package/dist/esm/grpc/proto/sui/rpc/v2/name_service.client.js.map +1 -0
  537. package/dist/esm/grpc/proto/sui/rpc/v2/name_service.js +129 -107
  538. package/dist/esm/grpc/proto/sui/rpc/v2/name_service.js.map +1 -0
  539. package/dist/esm/grpc/proto/sui/rpc/v2/object.js +100 -85
  540. package/dist/esm/grpc/proto/sui/rpc/v2/object.js.map +1 -0
  541. package/dist/esm/grpc/proto/sui/rpc/v2/object_reference.js +42 -30
  542. package/dist/esm/grpc/proto/sui/rpc/v2/object_reference.js.map +1 -0
  543. package/dist/esm/grpc/proto/sui/rpc/v2/owner.js +72 -40
  544. package/dist/esm/grpc/proto/sui/rpc/v2/owner.js.map +1 -0
  545. package/dist/esm/grpc/proto/sui/rpc/v2/protocol_config.js +42 -38
  546. package/dist/esm/grpc/proto/sui/rpc/v2/protocol_config.js.map +1 -0
  547. package/dist/esm/grpc/proto/sui/rpc/v2/signature.js +544 -481
  548. package/dist/esm/grpc/proto/sui/rpc/v2/signature.js.map +1 -0
  549. package/dist/esm/grpc/proto/sui/rpc/v2/signature_scheme.js +52 -13
  550. package/dist/esm/grpc/proto/sui/rpc/v2/signature_scheme.js.map +1 -0
  551. package/dist/esm/grpc/proto/sui/rpc/v2/signature_verification_service.client.js +23 -28
  552. package/dist/esm/grpc/proto/sui/rpc/v2/signature_verification_service.client.js.map +1 -0
  553. package/dist/esm/grpc/proto/sui/rpc/v2/signature_verification_service.js +74 -60
  554. package/dist/esm/grpc/proto/sui/rpc/v2/signature_verification_service.js.map +1 -0
  555. package/dist/esm/grpc/proto/sui/rpc/v2/state_service.client.js +49 -66
  556. package/dist/esm/grpc/proto/sui/rpc/v2/state_service.client.js.map +1 -0
  557. package/dist/esm/grpc/proto/sui/rpc/v2/state_service.js +623 -490
  558. package/dist/esm/grpc/proto/sui/rpc/v2/state_service.js.map +1 -0
  559. package/dist/esm/grpc/proto/sui/rpc/v2/subscription_service.client.js +33 -32
  560. package/dist/esm/grpc/proto/sui/rpc/v2/subscription_service.client.js.map +1 -0
  561. package/dist/esm/grpc/proto/sui/rpc/v2/subscription_service.js +50 -36
  562. package/dist/esm/grpc/proto/sui/rpc/v2/subscription_service.js.map +1 -0
  563. package/dist/esm/grpc/proto/sui/rpc/v2/system_state.js +737 -701
  564. package/dist/esm/grpc/proto/sui/rpc/v2/system_state.js.map +1 -0
  565. package/dist/esm/grpc/proto/sui/rpc/v2/transaction.js +1177 -917
  566. package/dist/esm/grpc/proto/sui/rpc/v2/transaction.js.map +1 -0
  567. package/dist/esm/grpc/proto/sui/rpc/v2/transaction_execution_service.client.js +28 -27
  568. package/dist/esm/grpc/proto/sui/rpc/v2/transaction_execution_service.client.js.map +1 -0
  569. package/dist/esm/grpc/proto/sui/rpc/v2/transaction_execution_service.js +169 -133
  570. package/dist/esm/grpc/proto/sui/rpc/v2/transaction_execution_service.js.map +1 -0
  571. package/dist/esm/index.js +21 -107
  572. package/dist/esm/index.js.map +1 -0
  573. package/dist/esm/jsonRpc/client.js +646 -727
  574. package/dist/esm/jsonRpc/client.js.map +1 -0
  575. package/dist/esm/jsonRpc/core.d.ts +7 -7
  576. package/dist/esm/jsonRpc/core.js +550 -581
  577. package/dist/esm/jsonRpc/core.js.map +1 -0
  578. package/dist/esm/jsonRpc/errors.js +36 -41
  579. package/dist/esm/jsonRpc/errors.js.map +1 -0
  580. package/dist/esm/jsonRpc/http-transport.js +65 -93
  581. package/dist/esm/jsonRpc/http-transport.js.map +1 -0
  582. package/dist/esm/jsonRpc/index.js +6 -20
  583. package/dist/esm/jsonRpc/index.js.map +1 -0
  584. package/dist/esm/jsonRpc/json-rpc-resolver.js +281 -276
  585. package/dist/esm/jsonRpc/json-rpc-resolver.js.map +1 -0
  586. package/dist/esm/jsonRpc/rpc-websocket-client.js +147 -189
  587. package/dist/esm/jsonRpc/rpc-websocket-client.js.map +1 -0
  588. package/dist/esm/jsonRpc/types/chain.js +4 -0
  589. package/dist/esm/jsonRpc/types/chain.js.map +1 -0
  590. package/dist/esm/jsonRpc/types/changes.js +4 -0
  591. package/dist/esm/jsonRpc/types/changes.js.map +1 -0
  592. package/dist/esm/jsonRpc/types/coins.js +4 -0
  593. package/dist/esm/jsonRpc/types/coins.js.map +1 -0
  594. package/dist/esm/jsonRpc/types/common.js +4 -0
  595. package/dist/esm/jsonRpc/types/common.js.map +1 -0
  596. package/dist/esm/jsonRpc/types/generated.d.ts +1 -1
  597. package/dist/esm/jsonRpc/types/generated.js +4 -0
  598. package/dist/esm/jsonRpc/types/generated.js.map +1 -0
  599. package/dist/esm/jsonRpc/types/index.js +4 -0
  600. package/dist/esm/jsonRpc/types/index.js.map +1 -0
  601. package/dist/esm/jsonRpc/types/params.js +4 -0
  602. package/dist/esm/jsonRpc/types/params.js.map +1 -0
  603. package/dist/esm/keypairs/ed25519/ed25519-hd-key.js +49 -48
  604. package/dist/esm/keypairs/ed25519/ed25519-hd-key.js.map +1 -0
  605. package/dist/esm/keypairs/ed25519/index.js +5 -10
  606. package/dist/esm/keypairs/ed25519/index.js.map +1 -0
  607. package/dist/esm/keypairs/ed25519/keypair.js +128 -146
  608. package/dist/esm/keypairs/ed25519/keypair.js.map +1 -0
  609. package/dist/esm/keypairs/ed25519/publickey.js +64 -67
  610. package/dist/esm/keypairs/ed25519/publickey.js.map +1 -0
  611. package/dist/esm/keypairs/index.js +3 -0
  612. package/dist/esm/keypairs/index.js.map +1 -0
  613. package/dist/esm/keypairs/passkey/index.js +5 -12
  614. package/dist/esm/keypairs/passkey/index.js.map +1 -0
  615. package/dist/esm/keypairs/passkey/keypair.js +236 -243
  616. package/dist/esm/keypairs/passkey/keypair.js.map +1 -0
  617. package/dist/esm/keypairs/passkey/publickey.js +154 -140
  618. package/dist/esm/keypairs/passkey/publickey.js.map +1 -0
  619. package/dist/esm/keypairs/passkey/types.js +4 -0
  620. package/dist/esm/keypairs/passkey/types.js.map +1 -0
  621. package/dist/esm/keypairs/secp256k1/index.js +5 -10
  622. package/dist/esm/keypairs/secp256k1/index.js.map +1 -0
  623. package/dist/esm/keypairs/secp256k1/keypair.js +120 -134
  624. package/dist/esm/keypairs/secp256k1/keypair.js.map +1 -0
  625. package/dist/esm/keypairs/secp256k1/publickey.js +64 -71
  626. package/dist/esm/keypairs/secp256k1/publickey.js.map +1 -0
  627. package/dist/esm/keypairs/secp256r1/index.js +5 -10
  628. package/dist/esm/keypairs/secp256r1/index.js.map +1 -0
  629. package/dist/esm/keypairs/secp256r1/keypair.js +118 -131
  630. package/dist/esm/keypairs/secp256r1/keypair.js.map +1 -0
  631. package/dist/esm/keypairs/secp256r1/publickey.js +63 -66
  632. package/dist/esm/keypairs/secp256r1/publickey.js.map +1 -0
  633. package/dist/esm/multisig/index.js +5 -10
  634. package/dist/esm/multisig/index.js.map +1 -0
  635. package/dist/esm/multisig/publickey.d.ts +1 -1
  636. package/dist/esm/multisig/publickey.js +216 -253
  637. package/dist/esm/multisig/publickey.js.map +1 -0
  638. package/dist/esm/multisig/signer.js +57 -89
  639. package/dist/esm/multisig/signer.js.map +1 -0
  640. package/dist/esm/transactions/Arguments.d.ts +4 -4
  641. package/dist/esm/transactions/Arguments.js +9 -13
  642. package/dist/esm/transactions/Arguments.js.map +1 -0
  643. package/dist/esm/transactions/Commands.js +105 -118
  644. package/dist/esm/transactions/Commands.js.map +1 -0
  645. package/dist/esm/transactions/Inputs.js +49 -61
  646. package/dist/esm/transactions/Inputs.js.map +1 -0
  647. package/dist/esm/transactions/ObjectCache.d.ts +8 -8
  648. package/dist/esm/transactions/ObjectCache.js +200 -223
  649. package/dist/esm/transactions/ObjectCache.js.map +1 -0
  650. package/dist/esm/transactions/Transaction.d.ts +32 -32
  651. package/dist/esm/transactions/Transaction.js +611 -696
  652. package/dist/esm/transactions/Transaction.js.map +1 -0
  653. package/dist/esm/transactions/TransactionData.d.ts +9 -9
  654. package/dist/esm/transactions/TransactionData.js +386 -415
  655. package/dist/esm/transactions/TransactionData.js.map +1 -0
  656. package/dist/esm/transactions/__tests__/Transaction.test.js +167 -0
  657. package/dist/esm/transactions/__tests__/Transaction.test.js.map +1 -0
  658. package/dist/esm/transactions/__tests__/bcs.test.js +200 -0
  659. package/dist/esm/transactions/__tests__/bcs.test.js.map +1 -0
  660. package/dist/esm/transactions/data/internal.js +158 -205
  661. package/dist/esm/transactions/data/internal.js.map +1 -0
  662. package/dist/esm/transactions/data/v1.js +419 -487
  663. package/dist/esm/transactions/data/v1.js.map +1 -0
  664. package/dist/esm/transactions/data/v2.d.ts +5 -5
  665. package/dist/esm/transactions/data/v2.js +89 -107
  666. package/dist/esm/transactions/data/v2.js.map +1 -0
  667. package/dist/esm/transactions/executor/caching.d.ts +2 -2
  668. package/dist/esm/transactions/executor/caching.js +66 -93
  669. package/dist/esm/transactions/executor/caching.js.map +1 -0
  670. package/dist/esm/transactions/executor/parallel.js +329 -352
  671. package/dist/esm/transactions/executor/parallel.js.map +1 -0
  672. package/dist/esm/transactions/executor/queue.js +58 -64
  673. package/dist/esm/transactions/executor/queue.js.map +1 -0
  674. package/dist/esm/transactions/executor/serial.d.ts +5 -5
  675. package/dist/esm/transactions/executor/serial.js +96 -110
  676. package/dist/esm/transactions/executor/serial.js.map +1 -0
  677. package/dist/esm/transactions/hash.js +15 -9
  678. package/dist/esm/transactions/hash.js.map +1 -0
  679. package/dist/esm/transactions/index.js +15 -41
  680. package/dist/esm/transactions/index.js.map +1 -0
  681. package/dist/esm/transactions/intents/CoinWithBalance.js +127 -165
  682. package/dist/esm/transactions/intents/CoinWithBalance.js.map +1 -0
  683. package/dist/esm/transactions/object.js +86 -92
  684. package/dist/esm/transactions/object.js.map +1 -0
  685. package/dist/esm/transactions/plugins/NamedPackagesPlugin.js +18 -15
  686. package/dist/esm/transactions/plugins/NamedPackagesPlugin.js.map +1 -0
  687. package/dist/esm/transactions/pure.js +34 -39
  688. package/dist/esm/transactions/pure.js.map +1 -0
  689. package/dist/esm/transactions/resolve.js +58 -69
  690. package/dist/esm/transactions/resolve.js.map +1 -0
  691. package/dist/esm/transactions/serializer.js +145 -144
  692. package/dist/esm/transactions/serializer.js.map +1 -0
  693. package/dist/esm/transactions/utils.d.ts +1 -1
  694. package/dist/esm/transactions/utils.js +110 -109
  695. package/dist/esm/transactions/utils.js.map +1 -0
  696. package/dist/esm/utils/constants.js +26 -36
  697. package/dist/esm/utils/constants.js.map +1 -0
  698. package/dist/esm/utils/derived-objects.js +11 -10
  699. package/dist/esm/utils/derived-objects.js.map +1 -0
  700. package/dist/esm/utils/dynamic-fields.js +16 -16
  701. package/dist/esm/utils/dynamic-fields.js.map +1 -0
  702. package/dist/esm/utils/format.js +13 -13
  703. package/dist/esm/utils/format.js.map +1 -0
  704. package/dist/esm/utils/index.js +15 -76
  705. package/dist/esm/utils/index.js.map +1 -0
  706. package/dist/esm/utils/move-registry.js +34 -17
  707. package/dist/esm/utils/move-registry.js.map +1 -0
  708. package/dist/esm/utils/sui-types.js +70 -54
  709. package/dist/esm/utils/sui-types.js.map +1 -0
  710. package/dist/esm/utils/suins.js +29 -29
  711. package/dist/esm/utils/suins.js.map +1 -0
  712. package/dist/esm/verify/index.js +5 -14
  713. package/dist/esm/verify/index.js.map +1 -0
  714. package/dist/esm/verify/verify.js +76 -93
  715. package/dist/esm/verify/verify.js.map +1 -0
  716. package/dist/esm/version.js +6 -6
  717. package/dist/esm/version.js.map +1 -0
  718. package/dist/esm/w/call/allocation.js +307 -402
  719. package/dist/esm/w/call/allocation.js.map +1 -0
  720. package/dist/esm/w/call/arb.js +100 -129
  721. package/dist/esm/w/call/arb.js.map +1 -0
  722. package/dist/esm/w/call/arbitration.js +1170 -1568
  723. package/dist/esm/w/call/arbitration.js.map +1 -0
  724. package/dist/esm/w/call/base.js +288 -315
  725. package/dist/esm/w/call/base.js.map +1 -0
  726. package/dist/esm/w/call/contact.js +318 -442
  727. package/dist/esm/w/call/contact.js.map +1 -0
  728. package/dist/esm/w/call/demand.js +673 -841
  729. package/dist/esm/w/call/demand.js.map +1 -0
  730. package/dist/esm/w/call/entity.js +162 -203
  731. package/dist/esm/w/call/entity.js.map +1 -0
  732. package/dist/esm/w/call/guard-ins.d.ts +1 -0
  733. package/dist/esm/w/call/guard-ins.js +4373 -4366
  734. package/dist/esm/w/call/guard-ins.js.map +1 -0
  735. package/dist/esm/w/call/guard.d.ts +10 -0
  736. package/dist/esm/w/call/guard.js +1061 -1115
  737. package/dist/esm/w/call/guard.js.map +1 -0
  738. package/dist/esm/w/call/index.d.ts +1 -1
  739. package/dist/esm/w/call/index.js +24 -54
  740. package/dist/esm/w/call/index.js.map +1 -0
  741. package/dist/esm/w/call/machine.js +1086 -1433
  742. package/dist/esm/w/call/machine.js.map +1 -0
  743. package/dist/esm/w/call/order.js +301 -448
  744. package/dist/esm/w/call/order.js.map +1 -0
  745. package/dist/esm/w/call/passport.js +204 -240
  746. package/dist/esm/w/call/passport.js.map +1 -0
  747. package/dist/esm/w/call/payment.js +177 -215
  748. package/dist/esm/w/call/payment.js.map +1 -0
  749. package/dist/esm/w/call/permission.js +1172 -1320
  750. package/dist/esm/w/call/permission.js.map +1 -0
  751. package/dist/esm/w/call/personal.js +121 -156
  752. package/dist/esm/w/call/personal.js.map +1 -0
  753. package/dist/esm/w/call/progress.js +625 -797
  754. package/dist/esm/w/call/progress.js.map +1 -0
  755. package/dist/esm/w/call/proof.js +61 -103
  756. package/dist/esm/w/call/proof.js.map +1 -0
  757. package/dist/esm/w/call/repository.js +1017 -1251
  758. package/dist/esm/w/call/repository.js.map +1 -0
  759. package/dist/esm/w/call/resource.js +108 -124
  760. package/dist/esm/w/call/resource.js.map +1 -0
  761. package/dist/esm/w/call/reward.js +660 -847
  762. package/dist/esm/w/call/reward.js.map +1 -0
  763. package/dist/esm/w/call/service.js +1849 -2400
  764. package/dist/esm/w/call/service.js.map +1 -0
  765. package/dist/esm/w/call/treasury.js +815 -1125
  766. package/dist/esm/w/call/treasury.js.map +1 -0
  767. package/dist/esm/w/call/util.js +553 -576
  768. package/dist/esm/w/call/util.js.map +1 -0
  769. package/dist/esm/w/common.d.ts +1 -1
  770. package/dist/esm/w/common.js +579 -580
  771. package/dist/esm/w/common.js.map +1 -0
  772. package/dist/esm/w/exception.js +570 -573
  773. package/dist/esm/w/exception.js.map +1 -0
  774. package/dist/esm/w/index.js +4 -0
  775. package/dist/esm/w/index.js.map +1 -0
  776. package/dist/esm/w/local/account.js +652 -709
  777. package/dist/esm/w/local/account.js.map +1 -0
  778. package/dist/esm/w/local/cache.js +176 -147
  779. package/dist/esm/w/local/cache.js.map +1 -0
  780. package/dist/esm/w/local/config.js +46 -60
  781. package/dist/esm/w/local/config.js.map +1 -0
  782. package/dist/esm/w/local/index.js +196 -273
  783. package/dist/esm/w/local/index.js.map +1 -0
  784. package/dist/esm/w/local/local.d.ts +2 -2
  785. package/dist/esm/w/local/local.js +631 -626
  786. package/dist/esm/w/local/local.js.map +1 -0
  787. package/dist/esm/w/local/storage.js +168 -136
  788. package/dist/esm/w/local/storage.js.map +1 -0
  789. package/dist/esm/w/local/token.js +149 -151
  790. package/dist/esm/w/local/token.js.map +1 -0
  791. package/dist/esm/w/local/util.js +45 -22
  792. package/dist/esm/w/local/util.js.map +1 -0
  793. package/dist/esm/w/local/wip.js +1038 -781
  794. package/dist/esm/w/local/wip.js.map +1 -0
  795. package/dist/esm/w/messenger/crypto.js +491 -387
  796. package/dist/esm/w/messenger/crypto.js.map +1 -0
  797. package/dist/esm/w/messenger/index.js +27 -24
  798. package/dist/esm/w/messenger/index.js.map +1 -0
  799. package/dist/esm/w/messenger/messenger-api.js +1111 -1017
  800. package/dist/esm/w/messenger/messenger-api.js.map +1 -0
  801. package/dist/esm/w/messenger/messenger-manager.js +944 -1052
  802. package/dist/esm/w/messenger/messenger-manager.js.map +1 -0
  803. package/dist/esm/w/messenger/messenger.d.ts +1 -1
  804. package/dist/esm/w/messenger/messenger.js +1258 -1421
  805. package/dist/esm/w/messenger/messenger.js.map +1 -0
  806. package/dist/esm/w/messenger/server.js +388 -499
  807. package/dist/esm/w/messenger/server.js.map +1 -0
  808. package/dist/esm/w/messenger/session.js +394 -399
  809. package/dist/esm/w/messenger/session.js.map +1 -0
  810. package/dist/esm/w/messenger/storage.js +840 -751
  811. package/dist/esm/w/messenger/storage.js.map +1 -0
  812. package/dist/esm/w/messenger/types.d.ts +2 -2
  813. package/dist/esm/w/messenger/types.js +80 -85
  814. package/dist/esm/w/messenger/types.js.map +1 -0
  815. package/dist/esm/w/messenger/utils.js +28 -16
  816. package/dist/esm/w/messenger/utils.js.map +1 -0
  817. package/dist/esm/w/query/bult-in.js +95 -100
  818. package/dist/esm/w/query/bult-in.js.map +1 -0
  819. package/dist/esm/w/query/event.js +128 -125
  820. package/dist/esm/w/query/event.js.map +1 -0
  821. package/dist/esm/w/query/index.js +3 -0
  822. package/dist/esm/w/query/index.js.map +1 -0
  823. package/dist/esm/w/query/object.js +1560 -1574
  824. package/dist/esm/w/query/object.js.map +1 -0
  825. package/dist/esm/w/query/received.js +57 -63
  826. package/dist/esm/w/query/received.js.map +1 -0
  827. package/dist/esm/w/query/util.js +48 -56
  828. package/dist/esm/w/query/util.js.map +1 -0
  829. package/dist/esm/w/util.js +578 -673
  830. package/dist/esm/w/util.js.map +1 -0
  831. package/package.json +14 -9
  832. package/dist/cjs/graphql/client.js +0 -98
  833. package/dist/cjs/graphql/core.js +0 -506
  834. package/dist/cjs/graphql/generated/2024.1/tada-env.js +0 -13141
  835. package/dist/cjs/graphql/generated/2024.1/tsconfig.tada.js +0 -11
  836. package/dist/cjs/graphql/generated/2024.4/tada-env.js +0 -13287
  837. package/dist/cjs/graphql/generated/2024.4/tsconfig.tada.js +0 -11
  838. package/dist/cjs/graphql/generated/latest/tada-env.js +0 -12925
  839. package/dist/cjs/graphql/generated/latest/tsconfig.tada.js +0 -11
  840. package/dist/cjs/graphql/generated/queries.js +0 -807
  841. package/dist/cjs/graphql/index.js +0 -25
  842. package/dist/cjs/graphql/schemas/2024.1/index.js +0 -28
  843. package/dist/cjs/graphql/schemas/2024.4/index.js +0 -28
  844. package/dist/cjs/graphql/schemas/latest/index.js +0 -28
  845. package/dist/cjs/graphql/types.js +0 -16
  846. package/dist/cjs/package.json +0 -5
  847. package/dist/cjs/w/local/.eslintrc.js +0 -15
  848. package/dist/cjs/w/messenger/.eslintrc.js +0 -15
  849. package/dist/cjs/zklogin/address.js +0 -93
  850. package/dist/cjs/zklogin/bcs.js +0 -41
  851. package/dist/cjs/zklogin/index.js +0 -45
  852. package/dist/cjs/zklogin/jwt-decode.js +0 -88
  853. package/dist/cjs/zklogin/jwt-utils.js +0 -128
  854. package/dist/cjs/zklogin/nonce.js +0 -60
  855. package/dist/cjs/zklogin/poseidon.js +0 -64
  856. package/dist/cjs/zklogin/publickey.js +0 -281
  857. package/dist/cjs/zklogin/signature.js +0 -57
  858. package/dist/cjs/zklogin/utils.js +0 -98
  859. package/dist/esm/graphql/client.js +0 -79
  860. package/dist/esm/graphql/core.js +0 -505
  861. package/dist/esm/graphql/generated/2024.1/tada-env.js +0 -13121
  862. package/dist/esm/graphql/generated/2024.1/tsconfig.tada.js +0 -16
  863. package/dist/esm/graphql/generated/2024.4/tada-env.js +0 -13267
  864. package/dist/esm/graphql/generated/2024.4/tsconfig.tada.js +0 -16
  865. package/dist/esm/graphql/generated/latest/tada-env.js +0 -12905
  866. package/dist/esm/graphql/generated/latest/tsconfig.tada.js +0 -16
  867. package/dist/esm/graphql/generated/queries.js +0 -788
  868. package/dist/esm/graphql/index.js +0 -8
  869. package/dist/esm/graphql/schemas/2024.1/index.js +0 -8
  870. package/dist/esm/graphql/schemas/2024.4/index.js +0 -8
  871. package/dist/esm/graphql/schemas/latest/index.js +0 -8
  872. package/dist/esm/graphql/types.js +0 -0
  873. package/dist/esm/package.json +0 -5
  874. package/dist/esm/w/local/.eslintrc.js +0 -23
  875. package/dist/esm/w/messenger/.eslintrc.js +0 -23
  876. package/dist/esm/zklogin/address.js +0 -78
  877. package/dist/esm/zklogin/bcs.js +0 -21
  878. package/dist/esm/zklogin/index.js +0 -38
  879. package/dist/esm/zklogin/jwt-decode.js +0 -68
  880. package/dist/esm/zklogin/jwt-utils.js +0 -108
  881. package/dist/esm/zklogin/nonce.js +0 -40
  882. package/dist/esm/zklogin/poseidon.js +0 -61
  883. package/dist/esm/zklogin/publickey.js +0 -265
  884. package/dist/esm/zklogin/signature.js +0 -37
  885. package/dist/esm/zklogin/utils.js +0 -78
  886. package/dist/tsconfig.esm.tsbuildinfo +0 -1
  887. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -1,33 +1,11 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import {
5
- toTxObject,
6
- toTxString,
7
- isValidDescription,
8
- MAX_DESCRIPTION_LENGTH,
9
- isValidU8,
10
- isValidName,
11
- ValueType,
12
- parseValueType,
13
- OperatorType,
14
- ContextType,
15
- isWitnessType,
16
- PackageAddress,
17
- ObjectType,
18
- MAX_INPUT_SIZE,
19
- MAX_DEPENDED_COUNT,
20
- MAX_MULTI_OPERANDS
21
- } from "../common.js";
22
- import _ from "lodash";
1
+ // Copyright (c) Wowok.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { toTxObject, toTxString, isValidDescription, MAX_DESCRIPTION_LENGTH, isValidU8, isValidName, ValueType, parseValueType, OperatorType, ContextType, isWitnessType, PackageAddress, ObjectType, MAX_INPUT_SIZE, MAX_DEPENDED_COUNT, MAX_MULTI_OPERANDS, } from "../common.js";
4
+ import _ from "lodash"; // Import lodash
23
5
  import { W_ERROR, WErrors } from "../exception.js";
24
6
  import { CallBase } from "./base.js";
25
7
  import { LocalMark } from "../local/local.js";
26
- import {
27
- WitnessSourceType,
28
- WitnessTargetType,
29
- query_objects
30
- } from "../query/object.js";
8
+ import { WitnessSourceType, WitnessTargetType, query_objects, } from "../query/object.js";
31
9
  import { bcs } from "../../bcs/index.js";
32
10
  import { valueToBcsBytes } from "../util.js";
33
11
  import { getGuardQueryInfo, GUARDQUERY } from "./guard-ins.js";
@@ -36,1167 +14,1135 @@ import { isValidWowAddress } from "../../utils/sui-types.js";
36
14
  import { get_guardSubmissions, verify_guard } from "./passport.js";
37
15
  import { writeFileSync } from "fs";
38
16
  import { resolve } from "path";
39
- function guardFn(name) {
40
- return `${PackageAddress}::guard::${name}`;
17
+ // ================================================
18
+ export function guardFn(name) {
19
+ return `${PackageAddress}::guard::${name}`;
41
20
  }
42
- class CallGuard extends CallBase {
43
- constructor(data) {
44
- super();
45
- __publicField(this, "data");
46
- this.data = data;
47
- }
48
- async call(env) {
49
- await this.prepare(env);
50
- return await this.exec(env);
51
- }
52
- async operate(env, tx, _passport, _submission) {
53
- if (!this.data.table || this.data.table.length === 0) {
54
- W_ERROR(WErrors.InvalidParam, "table is empty");
21
+ export class CallGuard extends CallBase {
22
+ data;
23
+ constructor(data) {
24
+ super();
25
+ this.data = data;
55
26
  }
56
- if (!this.data.root) {
57
- W_ERROR(WErrors.InvalidParam, "root is empty");
27
+ async call(env) {
28
+ await this.prepare(env);
29
+ return await this.exec(env);
58
30
  }
59
- const guard = await newGuard(
60
- tx,
61
- this.data?.description || "",
62
- this.data?.table,
63
- this.data?.root
64
- );
65
- if (this.data?.rely != null) {
66
- const relyGuards = await LocalMark.Instance().get_many_address(
67
- this.data.rely.guards
68
- );
69
- const undefinedIndex = relyGuards.findIndex((v) => v === void 0);
70
- if (undefinedIndex !== -1) {
71
- W_ERROR(
72
- WErrors.InvalidParam,
73
- `rely.guards invalid: guard at index ${undefinedIndex} not found`
74
- );
75
- }
76
- reliesAdd(
77
- tx,
78
- guard,
79
- relyGuards.filter((v) => v !== void 0)
80
- );
31
+ async operate(env, tx, _passport, _submission) {
32
+ if (!this.data.table || this.data.table.length === 0) {
33
+ W_ERROR(WErrors.InvalidParam, "table is empty");
34
+ }
35
+ if (!this.data.root) {
36
+ W_ERROR(WErrors.InvalidParam, "root is empty");
37
+ }
38
+ const guard = await newGuard(tx, this.data?.description || "", this.data?.table, this.data?.root);
39
+ if (this.data?.rely != null) {
40
+ const relyGuards = await LocalMark.Instance().get_many_address(this.data.rely.guards);
41
+ // 查找原始数组中undefined值的索引
42
+ const undefinedIndex = relyGuards.findIndex((v) => v === undefined);
43
+ if (undefinedIndex !== -1) {
44
+ W_ERROR(WErrors.InvalidParam, `rely.guards invalid: guard at index ${undefinedIndex} not found`);
45
+ }
46
+ reliesAdd(tx, guard, relyGuards.filter((v) => v !== undefined));
47
+ }
48
+ await this.new_with_mark(env, tx, ObjectType.Guard, create(tx, guard), this.data?.namedNew);
81
49
  }
82
- await this.new_with_mark(
83
- env,
84
- tx,
85
- ObjectType.Guard,
86
- create(tx, guard),
87
- this.data?.namedNew
88
- );
89
- }
90
50
  }
91
- const newGuard = async (tx, description, table, root) => {
92
- if (!isValidDescription(description)) {
93
- W_ERROR(
94
- WErrors.IsValidDescription,
95
- `Description exceeds maximum length ${MAX_DESCRIPTION_LENGTH}`
96
- );
97
- }
98
- for (let i = 0; i < table.length; i++) {
99
- const v = table[i];
100
- if (!isValidU8(v.identifier))
101
- W_ERROR(
102
- WErrors.InvalidParam,
103
- `table.identifier ${v.identifier} invalid`
104
- );
105
- if (!v.b_submission && (v.value === void 0 || v.value === null))
106
- W_ERROR(
107
- WErrors.InvalidParam,
108
- `table.value ${v.value} with identifier ${v.identifier} invalid`
109
- );
110
- if (!isValidName(v.name)) W_ERROR(WErrors.InvalidParam, "table.name");
111
- }
112
- const grouped = _.groupBy(table, "identifier");
113
- const duplicates = Object.keys(grouped).filter(
114
- (key) => grouped[key].length > 1
115
- );
116
- if (duplicates.length > 0) {
117
- W_ERROR(
118
- WErrors.InvalidParam,
119
- `table.identifier duplicates: ${duplicates.join(", ")}`
120
- );
121
- }
122
- var output = [];
123
- await buildNode(root, ValueType.Bool, table, output);
124
- const totalLength = output.reduce((acc, arr) => acc + arr.length, 0);
125
- const input = new Uint8Array(totalLength);
126
- let offset = 0;
127
- for (const arr of output) {
128
- input.set(arr, offset);
129
- offset += arr.length;
130
- }
131
- if (input.length > MAX_INPUT_SIZE) {
132
- W_ERROR(
133
- WErrors.NewGuardCheckFailed,
134
- `Input size exceeds maximum limit ${MAX_INPUT_SIZE}`
135
- );
136
- }
137
- if (input.length === 0) {
138
- W_ERROR(WErrors.NewGuardCheckFailed, `Input cannot be empty`);
139
- }
140
- const tableItems = [];
141
- for (let i = 0; i < table.length; i++) {
142
- const item = table[i];
143
- const valueType = parseValueType(item.value_type);
144
- let bcsValue;
145
- if (item.b_submission) {
146
- bcsValue = new Uint8Array(1);
147
- bcsValue[0] = valueType;
148
- } else {
149
- if (item.value === void 0 || item.value === null) {
150
- W_ERROR(
151
- WErrors.NewGuardCheckFailed,
152
- `Table item value is required when b_submission is false`
153
- );
154
- }
155
- bcsValue = await valueToBcsBytes(valueType, item.value);
51
+ export const newGuard = async (tx, description, table, root) => {
52
+ if (!isValidDescription(description)) {
53
+ W_ERROR(WErrors.IsValidDescription, `Description exceeds maximum length ${MAX_DESCRIPTION_LENGTH}`);
54
+ }
55
+ // check const
56
+ for (let i = 0; i < table.length; i++) {
57
+ const v = table[i];
58
+ if (!isValidU8(v.identifier))
59
+ W_ERROR(WErrors.InvalidParam, `table.identifier ${v.identifier} invalid`);
60
+ if (!v.b_submission && (v.value === undefined || v.value === null))
61
+ W_ERROR(WErrors.InvalidParam, `table.value ${v.value} with identifier ${v.identifier} invalid`);
62
+ if (!isValidName(v.name))
63
+ W_ERROR(WErrors.InvalidParam, "table.name");
64
+ }
65
+ const grouped = _.groupBy(table, "identifier");
66
+ const duplicates = Object.keys(grouped).filter((key) => grouped[key].length > 1);
67
+ if (duplicates.length > 0) {
68
+ W_ERROR(WErrors.InvalidParam, `table.identifier duplicates: ${duplicates.join(", ")}`);
69
+ }
70
+ // check root
71
+ var output = [];
72
+ await buildNode(root, ValueType.Bool, table, output);
73
+ const totalLength = output.reduce((acc, arr) => acc + arr.length, 0);
74
+ const input = new Uint8Array(totalLength);
75
+ let offset = 0;
76
+ for (const arr of output) {
77
+ input.set(arr, offset);
78
+ offset += arr.length;
79
+ }
80
+ /*console.log(
81
+ "Input (decimal):",
82
+ Array.from(input)
83
+ .map((byte) => byte.toString(10))
84
+ .join(" "),
85
+ );*/
86
+ if (input.length > MAX_INPUT_SIZE) {
87
+ W_ERROR(WErrors.NewGuardCheckFailed, `Input size exceeds maximum limit ${MAX_INPUT_SIZE}`);
88
+ }
89
+ if (input.length === 0) {
90
+ W_ERROR(WErrors.NewGuardCheckFailed, `Input cannot be empty`);
91
+ }
92
+ const tableItems = [];
93
+ for (let i = 0; i < table.length; i++) {
94
+ const item = table[i];
95
+ // 转换 value_type 为枚举值(支持字符串输入)
96
+ const valueType = parseValueType(item.value_type);
97
+ // 根据b_submission的值计算bcsValue
98
+ let bcsValue;
99
+ if (item.b_submission) {
100
+ bcsValue = new Uint8Array(1);
101
+ bcsValue[0] = valueType;
102
+ }
103
+ else {
104
+ if (item.value === undefined || item.value === null) {
105
+ W_ERROR(WErrors.NewGuardCheckFailed, `Table item value is required when b_submission is false`);
106
+ }
107
+ bcsValue = await valueToBcsBytes(valueType, item.value);
108
+ }
109
+ tableItems.push(tx.moveCall({
110
+ target: guardFn("table_item"),
111
+ arguments: [
112
+ tx.pure.u8(item.identifier),
113
+ tx.pure.bool(item.b_submission),
114
+ tx.pure.vector("u8", Array.from(bcsValue)),
115
+ toTxString(tx, item.name),
116
+ ],
117
+ }));
156
118
  }
157
- tableItems.push(
158
- tx.moveCall({
159
- target: guardFn("table_item"),
119
+ return tx.moveCall({
120
+ target: guardFn("new"),
160
121
  arguments: [
161
- tx.pure.u8(item.identifier),
162
- tx.pure.bool(item.b_submission),
163
- tx.pure.vector("u8", Array.from(bcsValue)),
164
- toTxString(tx, item.name)
165
- ]
166
- })
167
- );
168
- }
169
- return tx.moveCall({
170
- target: guardFn("new"),
171
- arguments: [
172
- toTxString(tx, description),
173
- tx.makeMoveVec({
174
- elements: tableItems,
175
- type: `${PackageAddress}::guard::TableItem`
176
- }),
177
- tx.pure.vector("u8", Array.from(input))
178
- ]
179
- });
122
+ toTxString(tx, description),
123
+ tx.makeMoveVec({
124
+ elements: tableItems,
125
+ type: `${PackageAddress}::guard::TableItem`,
126
+ }),
127
+ tx.pure.vector("u8", Array.from(input)),
128
+ ],
129
+ });
180
130
  };
181
- function create(tx, guard) {
182
- return tx.moveCall({
183
- target: guardFn("create"),
184
- arguments: [
185
- toTxObject(tx, guard),
186
- tx.object.mutRegistrar(),
187
- tx.object.clock()
188
- ]
189
- });
131
+ export function create(tx, guard) {
132
+ return tx.moveCall({
133
+ target: guardFn("create"),
134
+ arguments: [
135
+ toTxObject(tx, guard),
136
+ tx.object.mutRegistrar(),
137
+ tx.object.clock(),
138
+ ],
139
+ });
190
140
  }
191
- function reliesAdd(tx, guard, rely_guards) {
192
- const guards = _.uniq(rely_guards);
193
- if (guards.length > MAX_DEPENDED_COUNT) {
194
- W_ERROR(
195
- WErrors.NewGuardCheckFailed,
196
- `Relies count exceeds maximum limit ${MAX_DEPENDED_COUNT}`
197
- );
198
- }
199
- guards.forEach((g) => {
200
- if (g === guard) {
201
- W_ERROR(WErrors.NewGuardCheckFailed, `Guard cannot rely on itself`);
141
+ export function reliesAdd(tx, guard, rely_guards) {
142
+ const guards = _.uniq(rely_guards);
143
+ if (guards.length > MAX_DEPENDED_COUNT) {
144
+ W_ERROR(WErrors.NewGuardCheckFailed, `Relies count exceeds maximum limit ${MAX_DEPENDED_COUNT}`);
202
145
  }
203
- tx.moveCall({
204
- target: guardFn("relies_add"),
205
- arguments: [
206
- toTxObject(tx, guard),
207
- toTxObject(tx, g),
208
- tx.object.mutRegistrar(),
209
- tx.object.clock()
210
- ]
146
+ guards.forEach((g) => {
147
+ if (g === guard) {
148
+ W_ERROR(WErrors.NewGuardCheckFailed, `Guard cannot rely on itself`);
149
+ }
150
+ tx.moveCall({
151
+ target: guardFn("relies_add"),
152
+ arguments: [
153
+ toTxObject(tx, guard),
154
+ toTxObject(tx, g),
155
+ tx.object.mutRegistrar(),
156
+ tx.object.clock(),
157
+ ],
158
+ });
211
159
  });
212
- });
213
160
  }
214
- function reliesRemove(tx, guard, rely_guards) {
215
- const guards = _.uniq(rely_guards);
216
- if (guards.length > MAX_DEPENDED_COUNT) {
217
- W_ERROR(
218
- WErrors.NewGuardCheckFailed,
219
- `Relies count exceeds maximum limit ${MAX_DEPENDED_COUNT}`
220
- );
221
- }
222
- guards.forEach((g) => {
223
- tx.moveCall({
224
- target: guardFn("relies_remove"),
225
- arguments: [
226
- toTxObject(tx, guard),
227
- toTxObject(tx, g),
228
- tx.object.mutRegistrar()
229
- ]
161
+ export function reliesRemove(tx, guard, rely_guards) {
162
+ const guards = _.uniq(rely_guards);
163
+ if (guards.length > MAX_DEPENDED_COUNT) {
164
+ W_ERROR(WErrors.NewGuardCheckFailed, `Relies count exceeds maximum limit ${MAX_DEPENDED_COUNT}`);
165
+ }
166
+ guards.forEach((g) => {
167
+ tx.moveCall({
168
+ target: guardFn("relies_remove"),
169
+ arguments: [
170
+ toTxObject(tx, guard),
171
+ toTxObject(tx, g),
172
+ tx.object.mutRegistrar(),
173
+ ],
174
+ });
230
175
  });
231
- });
232
176
  }
233
- function reliesClear(tx, guard) {
234
- tx.moveCall({
235
- target: guardFn("relies_clear"),
236
- arguments: [toTxObject(tx, guard), tx.object.mutRegistrar()]
237
- });
177
+ export function reliesClear(tx, guard) {
178
+ tx.moveCall({
179
+ target: guardFn("relies_clear"),
180
+ arguments: [toTxObject(tx, guard), tx.object.mutRegistrar()],
181
+ });
238
182
  }
239
- function reliesLogic(tx, guard, logic_and) {
240
- tx.moveCall({
241
- target: guardFn("relies_logic_and"),
242
- arguments: [toTxObject(tx, guard), tx.pure.bool(logic_and)]
243
- });
183
+ // set the logic(and/or) of the guard; default is and
184
+ export function reliesLogic(tx, guard, logic_and) {
185
+ tx.moveCall({
186
+ target: guardFn("relies_logic_and"),
187
+ arguments: [toTxObject(tx, guard), tx.pure.bool(logic_and)],
188
+ });
244
189
  }
190
+ // ================================================
245
191
  const buildNode = async (guard_node, type_required, table, output) => {
246
- const node = guard_node;
247
- switch (node.type) {
248
- case "identifier": {
249
- const f = table.find((v) => v.identifier === node.identifier);
250
- if (f) {
251
- const fValueType = parseValueType(f.value_type);
252
- checkType(fValueType, type_required, node);
253
- output.push(
254
- bcs.U8.serialize(ContextType.TypeConstant).toBytes()
255
- );
256
- output.push(bcs.U8.serialize(node.identifier).toBytes());
257
- } else {
258
- W_ERROR(
259
- WErrors.InvalidParam,
260
- "node identifier - " + JSON.stringify(node)
261
- );
262
- }
263
- break;
264
- }
265
- case "query": {
266
- const q = getGuardQueryInfo(node.query);
267
- if (!q) {
268
- W_ERROR(WErrors.InvalidParam, `query not found: ${node.query}`);
269
- }
270
- checkType(q.return, type_required, node);
271
- if (q.parameters.length === node.parameters.length) {
272
- for (let i = node.parameters.length - 1; i >= 0; --i) {
273
- await buildNode(
274
- node.parameters[i],
275
- q.parameters[i],
276
- table,
277
- output
278
- );
192
+ const node = guard_node;
193
+ switch (node.type) {
194
+ case "identifier": {
195
+ const f = table.find((v) => v.identifier === node.identifier);
196
+ if (f) {
197
+ const fValueType = parseValueType(f.value_type);
198
+ checkType(fValueType, type_required, node);
199
+ output.push(bcs.U8.serialize(ContextType.TypeConstant).toBytes());
200
+ output.push(bcs.U8.serialize(node.identifier).toBytes());
201
+ }
202
+ else {
203
+ W_ERROR(WErrors.InvalidParam, "node identifier - " + JSON.stringify(node));
204
+ }
205
+ break;
279
206
  }
280
- } else {
281
- W_ERROR(
282
- WErrors.InvalidParam,
283
- "node query parameters length not match - " + JSON.stringify(node)
284
- );
285
- }
286
- const tableItem = table.find(
287
- (v) => v.identifier === node.object.identifier
288
- );
289
- if (!tableItem) {
290
- W_ERROR(
291
- WErrors.InvalidParam,
292
- "node object from identifier - " + JSON.stringify(node)
293
- );
294
- }
295
- const tableItemValueType = parseValueType(tableItem.value_type);
296
- if (tableItemValueType !== ValueType.Address) {
297
- W_ERROR(
298
- WErrors.InvalidParam,
299
- `object to query must be address in table ${tableItem}. ${node.object}`
300
- );
301
- }
302
- output.push(bcs.U8.serialize(OperatorType.TypeQuery).toBytes());
303
- if (isWitnessType(node.object.convert_witness)) {
304
- const target = WitnessTargetType(node.object.convert_witness);
305
- if (target !== q.objectType) {
306
- W_ERROR(
307
- WErrors.InvalidParam,
308
- `witness object type(${target}) not consistent with query object type(${q.objectType})`
309
- );
207
+ case "query": {
208
+ const q = getGuardQueryInfo(node.query);
209
+ if (!q) {
210
+ W_ERROR(WErrors.InvalidParam, `query not found: ${node.query}`);
211
+ }
212
+ checkType(q.return, type_required, node);
213
+ if (q.parameters.length === node.parameters.length) {
214
+ for (let i = node.parameters.length - 1; i >= 0; --i) {
215
+ await buildNode(node.parameters[i], q.parameters[i], table, output);
216
+ }
217
+ }
218
+ else {
219
+ W_ERROR(WErrors.InvalidParam, "node query parameters length not match - " +
220
+ JSON.stringify(node));
221
+ }
222
+ const tableItem = table.find((v) => v.identifier === node.object.identifier);
223
+ if (!tableItem) {
224
+ W_ERROR(WErrors.InvalidParam, "node object from identifier - " + JSON.stringify(node));
225
+ }
226
+ const tableItemValueType = parseValueType(tableItem.value_type);
227
+ if (tableItemValueType !== ValueType.Address) {
228
+ W_ERROR(WErrors.InvalidParam, `object to query must be address in table ${tableItem}. ${node.object}`);
229
+ }
230
+ output.push(bcs.U8.serialize(OperatorType.TypeQuery).toBytes());
231
+ if (isWitnessType(node.object.convert_witness)) {
232
+ const target = WitnessTargetType(node.object.convert_witness);
233
+ if (target !== q.objectType) {
234
+ W_ERROR(WErrors.InvalidParam, `witness object type(${target}) not consistent with query object type(${q.objectType})`);
235
+ }
236
+ const source = WitnessSourceType(node.object.convert_witness);
237
+ if (tableItem.object_type) {
238
+ if (tableItem.object_type !== source) {
239
+ W_ERROR(WErrors.InvalidParam, `witness object type(${source}) not consistent with query object type(${tableItem.object_type})`);
240
+ }
241
+ }
242
+ else {
243
+ tableItem.object_type = source;
244
+ }
245
+ output.push(bcs.U8.serialize(node.object.convert_witness).toBytes());
246
+ }
247
+ else {
248
+ if (tableItem?.object_type) {
249
+ if (tableItem.object_type !== q.objectType) {
250
+ W_ERROR(WErrors.InvalidParam, `witness object type(${q.objectType}) not consistent with query object type(${tableItem.object_type})`);
251
+ }
252
+ }
253
+ else {
254
+ tableItem.object_type = q.objectType;
255
+ }
256
+ output.push(bcs.U8.serialize(ContextType.TypeConstant).toBytes());
257
+ }
258
+ output.push(bcs.U8.serialize(node.object.identifier).toBytes());
259
+ output.push(bcs.U16.serialize(q.id).toBytes());
260
+ break;
310
261
  }
311
- const source = WitnessSourceType(node.object.convert_witness);
312
- if (tableItem.object_type) {
313
- if (tableItem.object_type !== source) {
314
- W_ERROR(
315
- WErrors.InvalidParam,
316
- `witness object type(${source}) not consistent with query object type(${tableItem.object_type})`
317
- );
318
- }
319
- } else {
320
- tableItem.object_type = source;
262
+ case "logic_as_u256_greater_or_equal":
263
+ case "logic_as_u256_lesser_or_equal":
264
+ case "logic_as_u256_equal":
265
+ case "logic_as_u256_greater":
266
+ case "logic_as_u256_lesser":
267
+ case "logic_equal":
268
+ case "logic_and":
269
+ case "logic_or":
270
+ case "logic_string_contains":
271
+ case "logic_string_nocase_contains":
272
+ case "logic_string_nocase_equal":
273
+ case "calc_number_add":
274
+ case "calc_number_subtract":
275
+ case "calc_number_multiply":
276
+ case "calc_number_divide":
277
+ case "calc_number_mod":
278
+ case "calc_string_nocase_contains":
279
+ case "calc_string_nocase_equal":
280
+ case "calc_string_contains": {
281
+ const opCodeMap = {
282
+ logic_as_u256_greater_or_equal: OperatorType.TypeLogicAsU256GreaterEqual,
283
+ logic_as_u256_lesser_or_equal: OperatorType.TypeLogicAsU256LesserEqual,
284
+ logic_as_u256_equal: OperatorType.TypeLogicAsU256Equal,
285
+ logic_as_u256_greater: OperatorType.TypeLogicAsU256Greater,
286
+ logic_as_u256_lesser: OperatorType.TypeLogicAsU256Lesser,
287
+ logic_equal: OperatorType.TypeLogicEqual,
288
+ logic_and: OperatorType.TypeLogicAnd,
289
+ logic_or: OperatorType.TypeLogicOr,
290
+ logic_string_contains: OperatorType.TypeStringContains,
291
+ logic_string_nocase_contains: OperatorType.TypeStringNocaseContains,
292
+ logic_string_nocase_equal: OperatorType.TypeStringNocaseEqual,
293
+ calc_number_add: OperatorType.TypeNumberAdd,
294
+ calc_number_subtract: OperatorType.TypeNumberSubtract,
295
+ calc_number_multiply: OperatorType.TypeNumberMultiply,
296
+ calc_number_divide: OperatorType.TypeNumberDivide,
297
+ calc_number_mod: OperatorType.TypeNumberMod,
298
+ calc_string_nocase_contains: OperatorType.TypeStringNocaseContains,
299
+ calc_string_nocase_equal: OperatorType.TypeStringNocaseEqual,
300
+ calc_string_contains: OperatorType.TypeStringContains,
301
+ };
302
+ const requiredTypeMap = {
303
+ logic_as_u256_greater_or_equal: "number",
304
+ logic_as_u256_lesser_or_equal: "number",
305
+ logic_as_u256_equal: "number",
306
+ logic_as_u256_greater: "number",
307
+ logic_as_u256_lesser: "number",
308
+ logic_equal: "variable",
309
+ logic_and: ValueType.Bool,
310
+ logic_or: ValueType.Bool,
311
+ logic_string_contains: ValueType.String,
312
+ logic_string_nocase_contains: ValueType.String,
313
+ logic_string_nocase_equal: ValueType.String,
314
+ calc_number_add: "number",
315
+ calc_number_subtract: "number",
316
+ calc_number_multiply: "number",
317
+ calc_number_divide: "number",
318
+ calc_number_mod: "number",
319
+ calc_string_nocase_contains: ValueType.String,
320
+ calc_string_nocase_equal: ValueType.String,
321
+ calc_string_contains: ValueType.String,
322
+ };
323
+ const returnTypeMap = {
324
+ logic_as_u256_greater_or_equal: ValueType.Bool,
325
+ logic_as_u256_lesser_or_equal: ValueType.Bool,
326
+ logic_as_u256_equal: ValueType.Bool,
327
+ logic_as_u256_greater: ValueType.Bool,
328
+ logic_as_u256_lesser: ValueType.Bool,
329
+ logic_equal: ValueType.Bool,
330
+ logic_and: ValueType.Bool,
331
+ logic_or: ValueType.Bool,
332
+ logic_string_contains: ValueType.Bool,
333
+ logic_string_nocase_contains: ValueType.Bool,
334
+ logic_string_nocase_equal: ValueType.Bool,
335
+ calc_number_add: ValueType.U256,
336
+ calc_number_subtract: ValueType.U256,
337
+ calc_number_multiply: ValueType.U256,
338
+ calc_number_divide: ValueType.U256,
339
+ calc_number_mod: ValueType.U256,
340
+ calc_string_nocase_contains: ValueType.Bool,
341
+ calc_string_nocase_equal: ValueType.Bool,
342
+ calc_string_contains: ValueType.Bool,
343
+ };
344
+ checkType(returnTypeMap[node.type], type_required, node);
345
+ await multi_operand_op(opCodeMap[node.type], node.nodes, requiredTypeMap[node.type], table, output);
346
+ break;
321
347
  }
322
- output.push(
323
- bcs.U8.serialize(node.object.convert_witness).toBytes()
324
- );
325
- } else {
326
- if (tableItem?.object_type) {
327
- if (tableItem.object_type !== q.objectType) {
328
- W_ERROR(
329
- WErrors.InvalidParam,
330
- `witness object type(${q.objectType}) not consistent with query object type(${tableItem.object_type})`
331
- );
332
- }
333
- } else {
334
- tableItem.object_type = q.objectType;
348
+ case "vec_contains_bool":
349
+ case "vec_contains_address":
350
+ case "vec_contains_string":
351
+ case "vec_contains_string_nocase":
352
+ case "vec_contains_number": {
353
+ const opCodeMap = {
354
+ vec_contains_bool: OperatorType.TypedValueVecContains_Bool,
355
+ vec_contains_address: OperatorType.TypedValueVecContains_Address,
356
+ vec_contains_string: OperatorType.TypedValueVecContains_String,
357
+ vec_contains_string_nocase: OperatorType.TypedValueVecContains_StringNoCase,
358
+ vec_contains_number: OperatorType.TypedValueVecContains_Number,
359
+ };
360
+ const vecTypeMap = {
361
+ vec_contains_bool: ValueType.VecBool,
362
+ vec_contains_address: ValueType.VecAddress,
363
+ vec_contains_string: ValueType.VecString,
364
+ vec_contains_string_nocase: ValueType.VecString,
365
+ vec_contains_number: "vec_number",
366
+ };
367
+ const elemTypeMap = {
368
+ vec_contains_bool: ValueType.Bool,
369
+ vec_contains_address: ValueType.Address,
370
+ vec_contains_string: ValueType.String,
371
+ vec_contains_string_nocase: ValueType.String,
372
+ vec_contains_number: "number",
373
+ };
374
+ checkType(ValueType.Bool, type_required, node);
375
+ //@ 第一个节点是vec类型,后面的节点是元素类型
376
+ for (let i = node.nodes.length - 1; i >= 0; --i) {
377
+ const nodeType = i === 0 ? vecTypeMap[node.type] : elemTypeMap[node.type];
378
+ await buildNode(node.nodes[i], nodeType, table, output);
379
+ }
380
+ output.push(bcs.U8.serialize(opCodeMap[node.type]).toBytes());
381
+ output.push(bcs.U8.serialize(node.nodes.length).toBytes());
382
+ break;
383
+ }
384
+ case "logic_not":
385
+ case "calc_string_length":
386
+ case "convert_number_address":
387
+ case "convert_address_number":
388
+ case "convert_number_string":
389
+ case "convert_string_number":
390
+ case "convert_safe_u8":
391
+ case "convert_safe_u16":
392
+ case "convert_safe_u32":
393
+ case "convert_safe_u64":
394
+ case "convert_safe_u128":
395
+ case "convert_safe_u256":
396
+ case "value_type":
397
+ case "vec_length": {
398
+ const opCodeMap = {
399
+ logic_not: OperatorType.TypeLogicNot,
400
+ calc_string_length: OperatorType.TypeStringLength,
401
+ convert_number_address: OperatorType.TypeNumberAddress,
402
+ convert_address_number: OperatorType.TypeAddressNumber,
403
+ convert_number_string: OperatorType.TypeNumberString,
404
+ convert_string_number: OperatorType.TypeStringNumber,
405
+ //convert_string_lowercase: OperatorType.TypeStringLowercase,
406
+ convert_safe_u8: OperatorType.TypeSafeU8,
407
+ convert_safe_u16: OperatorType.TypeSafeU16,
408
+ convert_safe_u32: OperatorType.TypeSafeU32,
409
+ convert_safe_u64: OperatorType.TypeSafeU64,
410
+ convert_safe_u128: OperatorType.TypeSafeU128,
411
+ convert_safe_u256: OperatorType.TypeSafeU256,
412
+ value_type: OperatorType.TypedValueType,
413
+ vec_length: OperatorType.TypedValueVecLength,
414
+ };
415
+ const requiredTypeMap = {
416
+ logic_not: ValueType.Bool,
417
+ calc_string_length: ValueType.String,
418
+ convert_number_address: "number",
419
+ convert_address_number: ValueType.Address,
420
+ convert_number_string: "number",
421
+ convert_string_number: ValueType.String,
422
+ convert_safe_u8: "number",
423
+ convert_safe_u16: "number",
424
+ convert_safe_u32: "number",
425
+ convert_safe_u64: "number",
426
+ convert_safe_u128: "number",
427
+ convert_safe_u256: "number",
428
+ value_type: "variable",
429
+ vec_length: "vec",
430
+ };
431
+ const returnTypeMap = {
432
+ logic_not: ValueType.Bool,
433
+ calc_string_length: ValueType.U64,
434
+ convert_number_address: ValueType.Address,
435
+ convert_address_number: ValueType.U256,
436
+ convert_number_string: ValueType.String,
437
+ convert_string_number: ValueType.U256,
438
+ convert_safe_u8: ValueType.U8,
439
+ convert_safe_u16: ValueType.U16,
440
+ convert_safe_u32: ValueType.U32,
441
+ convert_safe_u64: ValueType.U64,
442
+ convert_safe_u128: ValueType.U128,
443
+ convert_safe_u256: ValueType.U256,
444
+ value_type: ValueType.U8,
445
+ vec_length: ValueType.U64,
446
+ };
447
+ checkType(returnTypeMap[node.type], type_required, node);
448
+ await single_operand_op(opCodeMap[node.type], node.node, requiredTypeMap[node.type], table, output);
449
+ break;
450
+ }
451
+ case "calc_string_indexof":
452
+ case "calc_string_nocase_indexof": {
453
+ const opCodeMap = {
454
+ calc_string_indexof: OperatorType.TypeStringIndexof,
455
+ calc_string_nocase_indexof: OperatorType.TypeStringNocaseIndexof,
456
+ };
457
+ checkType(ValueType.U64, type_required, node);
458
+ //@ 第一个元素在栈顶
459
+ await buildNode(node.nodeRight, ValueType.String, table, output);
460
+ await buildNode(node.nodeLeft, ValueType.String, table, output);
461
+ output.push(bcs.U8.serialize(opCodeMap[node.type]).toBytes());
462
+ output.push(bcs.U8.serialize(node.order === "forward" ? 0 : 1).toBytes());
463
+ break;
464
+ }
465
+ case "vec_indexof_bool":
466
+ case "vec_indexof_address":
467
+ case "vec_indexof_string":
468
+ case "vec_indexof_string_nocase":
469
+ case "vec_indexof_number": {
470
+ const opCodeMap = {
471
+ vec_indexof_bool: OperatorType.TypedValueVecIndexOf_Bool,
472
+ vec_indexof_address: OperatorType.TypedValueVecIndexOf_Address,
473
+ vec_indexof_string: OperatorType.TypedValueVecIndexOf_String,
474
+ vec_indexof_string_nocase: OperatorType.TypedValueVecIndexOf_StringNoCase,
475
+ vec_indexof_number: OperatorType.TypedValueVecIndexOf_Number,
476
+ };
477
+ const rightTypeMap = {
478
+ vec_indexof_bool: ValueType.Bool,
479
+ vec_indexof_address: ValueType.Address,
480
+ vec_indexof_string: ValueType.String,
481
+ vec_indexof_string_nocase: ValueType.String,
482
+ vec_indexof_number: "number",
483
+ };
484
+ const leftTypeMap = {
485
+ vec_indexof_bool: ValueType.VecBool,
486
+ vec_indexof_address: ValueType.VecAddress,
487
+ vec_indexof_string: ValueType.VecString,
488
+ vec_indexof_string_nocase: ValueType.VecString,
489
+ vec_indexof_number: "vec_number",
490
+ };
491
+ checkType(ValueType.U64, type_required, node);
492
+ //@ 第一个元素在栈顶
493
+ await buildNode(node.nodeRight, rightTypeMap[node.type], table, output);
494
+ await buildNode(node.nodeLeft, leftTypeMap[node.type], table, output);
495
+ output.push(bcs.U8.serialize(opCodeMap[node.type]).toBytes());
496
+ output.push(bcs.U8.serialize(node.order === "forward" ? 0 : 1).toBytes());
497
+ break;
498
+ }
499
+ case "context": {
500
+ let contextValue;
501
+ switch (node.context) {
502
+ case "Signer":
503
+ contextValue = ContextType.TypeSigner;
504
+ break;
505
+ case "Clock":
506
+ contextValue = ContextType.TypeClock;
507
+ break;
508
+ case "Guard":
509
+ contextValue = ContextType.TypeGuard;
510
+ break;
511
+ default:
512
+ W_ERROR(WErrors.InvalidParam, "Invalid context type: " + node.context);
513
+ }
514
+ output.push(bcs.U8.serialize(contextValue).toBytes());
515
+ checkType(ValueType.Address, type_required, node);
516
+ break;
335
517
  }
336
- output.push(
337
- bcs.U8.serialize(ContextType.TypeConstant).toBytes()
338
- );
339
- }
340
- output.push(bcs.U8.serialize(node.object.identifier).toBytes());
341
- output.push(bcs.U16.serialize(q.id).toBytes());
342
- break;
343
- }
344
- case "logic_as_u256_greater_or_equal":
345
- case "logic_as_u256_lesser_or_equal":
346
- case "logic_as_u256_equal":
347
- case "logic_as_u256_greater":
348
- case "logic_as_u256_lesser":
349
- case "logic_equal":
350
- case "logic_and":
351
- case "logic_or":
352
- case "logic_string_contains":
353
- case "logic_string_nocase_contains":
354
- case "logic_string_nocase_equal":
355
- case "calc_number_add":
356
- case "calc_number_subtract":
357
- case "calc_number_multiply":
358
- case "calc_number_divide":
359
- case "calc_number_mod":
360
- case "calc_string_nocase_contains":
361
- case "calc_string_nocase_equal":
362
- case "calc_string_contains": {
363
- const opCodeMap = {
364
- logic_as_u256_greater_or_equal: OperatorType.TypeLogicAsU256GreaterEqual,
365
- logic_as_u256_lesser_or_equal: OperatorType.TypeLogicAsU256LesserEqual,
366
- logic_as_u256_equal: OperatorType.TypeLogicAsU256Equal,
367
- logic_as_u256_greater: OperatorType.TypeLogicAsU256Greater,
368
- logic_as_u256_lesser: OperatorType.TypeLogicAsU256Lesser,
369
- logic_equal: OperatorType.TypeLogicEqual,
370
- logic_and: OperatorType.TypeLogicAnd,
371
- logic_or: OperatorType.TypeLogicOr,
372
- logic_string_contains: OperatorType.TypeStringContains,
373
- logic_string_nocase_contains: OperatorType.TypeStringNocaseContains,
374
- logic_string_nocase_equal: OperatorType.TypeStringNocaseEqual,
375
- calc_number_add: OperatorType.TypeNumberAdd,
376
- calc_number_subtract: OperatorType.TypeNumberSubtract,
377
- calc_number_multiply: OperatorType.TypeNumberMultiply,
378
- calc_number_divide: OperatorType.TypeNumberDivide,
379
- calc_number_mod: OperatorType.TypeNumberMod,
380
- calc_string_nocase_contains: OperatorType.TypeStringNocaseContains,
381
- calc_string_nocase_equal: OperatorType.TypeStringNocaseEqual,
382
- calc_string_contains: OperatorType.TypeStringContains
383
- };
384
- const requiredTypeMap = {
385
- logic_as_u256_greater_or_equal: "number",
386
- logic_as_u256_lesser_or_equal: "number",
387
- logic_as_u256_equal: "number",
388
- logic_as_u256_greater: "number",
389
- logic_as_u256_lesser: "number",
390
- logic_equal: "variable",
391
- logic_and: ValueType.Bool,
392
- logic_or: ValueType.Bool,
393
- logic_string_contains: ValueType.String,
394
- logic_string_nocase_contains: ValueType.String,
395
- logic_string_nocase_equal: ValueType.String,
396
- calc_number_add: "number",
397
- calc_number_subtract: "number",
398
- calc_number_multiply: "number",
399
- calc_number_divide: "number",
400
- calc_number_mod: "number",
401
- calc_string_nocase_contains: ValueType.String,
402
- calc_string_nocase_equal: ValueType.String,
403
- calc_string_contains: ValueType.String
404
- };
405
- const returnTypeMap = {
406
- logic_as_u256_greater_or_equal: ValueType.Bool,
407
- logic_as_u256_lesser_or_equal: ValueType.Bool,
408
- logic_as_u256_equal: ValueType.Bool,
409
- logic_as_u256_greater: ValueType.Bool,
410
- logic_as_u256_lesser: ValueType.Bool,
411
- logic_equal: ValueType.Bool,
412
- logic_and: ValueType.Bool,
413
- logic_or: ValueType.Bool,
414
- logic_string_contains: ValueType.Bool,
415
- logic_string_nocase_contains: ValueType.Bool,
416
- logic_string_nocase_equal: ValueType.Bool,
417
- calc_number_add: ValueType.U256,
418
- calc_number_subtract: ValueType.U256,
419
- calc_number_multiply: ValueType.U256,
420
- calc_number_divide: ValueType.U256,
421
- calc_number_mod: ValueType.U256,
422
- calc_string_nocase_contains: ValueType.Bool,
423
- calc_string_nocase_equal: ValueType.Bool,
424
- calc_string_contains: ValueType.Bool
425
- };
426
- checkType(returnTypeMap[node.type], type_required, node);
427
- await multi_operand_op(
428
- opCodeMap[node.type],
429
- node.nodes,
430
- requiredTypeMap[node.type],
431
- table,
432
- output
433
- );
434
- break;
435
- }
436
- case "vec_contains_bool":
437
- case "vec_contains_address":
438
- case "vec_contains_string":
439
- case "vec_contains_string_nocase":
440
- case "vec_contains_number": {
441
- const opCodeMap = {
442
- vec_contains_bool: OperatorType.TypedValueVecContains_Bool,
443
- vec_contains_address: OperatorType.TypedValueVecContains_Address,
444
- vec_contains_string: OperatorType.TypedValueVecContains_String,
445
- vec_contains_string_nocase: OperatorType.TypedValueVecContains_StringNoCase,
446
- vec_contains_number: OperatorType.TypedValueVecContains_Number
447
- };
448
- const vecTypeMap = {
449
- vec_contains_bool: ValueType.VecBool,
450
- vec_contains_address: ValueType.VecAddress,
451
- vec_contains_string: ValueType.VecString,
452
- vec_contains_string_nocase: ValueType.VecString,
453
- vec_contains_number: "vec_number"
454
- };
455
- const elemTypeMap = {
456
- vec_contains_bool: ValueType.Bool,
457
- vec_contains_address: ValueType.Address,
458
- vec_contains_string: ValueType.String,
459
- vec_contains_string_nocase: ValueType.String,
460
- vec_contains_number: "number"
461
- };
462
- checkType(ValueType.Bool, type_required, node);
463
- for (let i = node.nodes.length - 1; i >= 0; --i) {
464
- const nodeType = i === 0 ? vecTypeMap[node.type] : elemTypeMap[node.type];
465
- await buildNode(node.nodes[i], nodeType, table, output);
466
- }
467
- output.push(bcs.U8.serialize(opCodeMap[node.type]).toBytes());
468
- output.push(bcs.U8.serialize(node.nodes.length).toBytes());
469
- break;
470
- }
471
- case "logic_not":
472
- case "calc_string_length":
473
- case "convert_number_address":
474
- case "convert_address_number":
475
- case "convert_number_string":
476
- case "convert_string_number":
477
- case "convert_safe_u8":
478
- case "convert_safe_u16":
479
- case "convert_safe_u32":
480
- case "convert_safe_u64":
481
- case "convert_safe_u128":
482
- case "convert_safe_u256":
483
- case "value_type":
484
- case "vec_length": {
485
- const opCodeMap = {
486
- logic_not: OperatorType.TypeLogicNot,
487
- calc_string_length: OperatorType.TypeStringLength,
488
- convert_number_address: OperatorType.TypeNumberAddress,
489
- convert_address_number: OperatorType.TypeAddressNumber,
490
- convert_number_string: OperatorType.TypeNumberString,
491
- convert_string_number: OperatorType.TypeStringNumber,
492
- //convert_string_lowercase: OperatorType.TypeStringLowercase,
493
- convert_safe_u8: OperatorType.TypeSafeU8,
494
- convert_safe_u16: OperatorType.TypeSafeU16,
495
- convert_safe_u32: OperatorType.TypeSafeU32,
496
- convert_safe_u64: OperatorType.TypeSafeU64,
497
- convert_safe_u128: OperatorType.TypeSafeU128,
498
- convert_safe_u256: OperatorType.TypeSafeU256,
499
- value_type: OperatorType.TypedValueType,
500
- vec_length: OperatorType.TypedValueVecLength
501
- };
502
- const requiredTypeMap = {
503
- logic_not: ValueType.Bool,
504
- calc_string_length: ValueType.String,
505
- convert_number_address: "number",
506
- convert_address_number: ValueType.Address,
507
- convert_number_string: "number",
508
- convert_string_number: ValueType.String,
509
- convert_safe_u8: "number",
510
- convert_safe_u16: "number",
511
- convert_safe_u32: "number",
512
- convert_safe_u64: "number",
513
- convert_safe_u128: "number",
514
- convert_safe_u256: "number",
515
- value_type: "variable",
516
- vec_length: "vec"
517
- };
518
- const returnTypeMap = {
519
- logic_not: ValueType.Bool,
520
- calc_string_length: ValueType.U64,
521
- convert_number_address: ValueType.Address,
522
- convert_address_number: ValueType.U256,
523
- convert_number_string: ValueType.String,
524
- convert_string_number: ValueType.U256,
525
- convert_safe_u8: ValueType.U8,
526
- convert_safe_u16: ValueType.U16,
527
- convert_safe_u32: ValueType.U32,
528
- convert_safe_u64: ValueType.U64,
529
- convert_safe_u128: ValueType.U128,
530
- convert_safe_u256: ValueType.U256,
531
- value_type: ValueType.U8,
532
- vec_length: ValueType.U64
533
- };
534
- checkType(returnTypeMap[node.type], type_required, node);
535
- await single_operand_op(
536
- opCodeMap[node.type],
537
- node.node,
538
- requiredTypeMap[node.type],
539
- table,
540
- output
541
- );
542
- break;
543
- }
544
- case "calc_string_indexof":
545
- case "calc_string_nocase_indexof": {
546
- const opCodeMap = {
547
- calc_string_indexof: OperatorType.TypeStringIndexof,
548
- calc_string_nocase_indexof: OperatorType.TypeStringNocaseIndexof
549
- };
550
- checkType(ValueType.U64, type_required, node);
551
- await buildNode(node.nodeRight, ValueType.String, table, output);
552
- await buildNode(node.nodeLeft, ValueType.String, table, output);
553
- output.push(bcs.U8.serialize(opCodeMap[node.type]).toBytes());
554
- output.push(
555
- bcs.U8.serialize(node.order === "forward" ? 0 : 1).toBytes()
556
- );
557
- break;
558
- }
559
- case "vec_indexof_bool":
560
- case "vec_indexof_address":
561
- case "vec_indexof_string":
562
- case "vec_indexof_string_nocase":
563
- case "vec_indexof_number": {
564
- const opCodeMap = {
565
- vec_indexof_bool: OperatorType.TypedValueVecIndexOf_Bool,
566
- vec_indexof_address: OperatorType.TypedValueVecIndexOf_Address,
567
- vec_indexof_string: OperatorType.TypedValueVecIndexOf_String,
568
- vec_indexof_string_nocase: OperatorType.TypedValueVecIndexOf_StringNoCase,
569
- vec_indexof_number: OperatorType.TypedValueVecIndexOf_Number
570
- };
571
- const rightTypeMap = {
572
- vec_indexof_bool: ValueType.Bool,
573
- vec_indexof_address: ValueType.Address,
574
- vec_indexof_string: ValueType.String,
575
- vec_indexof_string_nocase: ValueType.String,
576
- vec_indexof_number: "number"
577
- };
578
- const leftTypeMap = {
579
- vec_indexof_bool: ValueType.VecBool,
580
- vec_indexof_address: ValueType.VecAddress,
581
- vec_indexof_string: ValueType.VecString,
582
- vec_indexof_string_nocase: ValueType.VecString,
583
- vec_indexof_number: "vec_number"
584
- };
585
- checkType(ValueType.U64, type_required, node);
586
- await buildNode(
587
- node.nodeRight,
588
- rightTypeMap[node.type],
589
- table,
590
- output
591
- );
592
- await buildNode(
593
- node.nodeLeft,
594
- leftTypeMap[node.type],
595
- table,
596
- output
597
- );
598
- output.push(bcs.U8.serialize(opCodeMap[node.type]).toBytes());
599
- output.push(
600
- bcs.U8.serialize(node.order === "forward" ? 0 : 1).toBytes()
601
- );
602
- break;
603
- }
604
- case "context": {
605
- let contextValue;
606
- switch (node.context) {
607
- case "Signer":
608
- contextValue = ContextType.TypeSigner;
609
- break;
610
- case "Clock":
611
- contextValue = ContextType.TypeClock;
612
- break;
613
- case "Guard":
614
- contextValue = ContextType.TypeGuard;
615
- break;
616
518
  default:
617
- W_ERROR(
618
- WErrors.InvalidParam,
619
- "Invalid context type: " + node.context
620
- );
621
- }
622
- output.push(bcs.U8.serialize(contextValue).toBytes());
623
- checkType(ValueType.Address, type_required, node);
624
- break;
519
+ W_ERROR(WErrors.InvalidParam, "node:" + JSON.stringify(node));
625
520
  }
626
- default:
627
- W_ERROR(WErrors.InvalidParam, "node:" + JSON.stringify(node));
628
- }
629
521
  };
630
522
  const multi_operand_op = async (op_code, parameters, required_type, table, output) => {
631
- if (parameters.length < 2 || parameters.length > MAX_MULTI_OPERANDS) {
632
- W_ERROR(
633
- WErrors.InvalidParam,
634
- `op ${op_code} parameters length must >= 2 and <=
523
+ if (parameters.length < 2 || parameters.length > MAX_MULTI_OPERANDS) {
524
+ W_ERROR(WErrors.InvalidParam, `op ${op_code} parameters length must >= 2 and <=
635
525
  ${MAX_MULTI_OPERANDS}. parameters:
636
- ${JSON.stringify(parameters)}`
637
- );
638
- }
639
- for (let i = parameters.length - 1; i >= 0; --i) {
640
- await buildNode(parameters[i], required_type, table, output);
641
- }
642
- output.push(bcs.U8.serialize(op_code).toBytes());
643
- output.push(bcs.U8.serialize(parameters.length).toBytes());
526
+ ${JSON.stringify(parameters)}`);
527
+ }
528
+ //@ 和query一样,栈顶是第一个参数
529
+ for (let i = parameters.length - 1; i >= 0; --i) {
530
+ await buildNode(parameters[i], required_type, table, output);
531
+ }
532
+ output.push(bcs.U8.serialize(op_code).toBytes()); // TYPE
533
+ output.push(bcs.U8.serialize(parameters.length).toBytes());
644
534
  };
645
535
  const single_operand_op = async (op_code, parameter, required_type, table, output) => {
646
- await buildNode(parameter, required_type, table, output);
647
- output.push(bcs.U8.serialize(op_code).toBytes());
536
+ await buildNode(parameter, required_type, table, output);
537
+ output.push(bcs.U8.serialize(op_code).toBytes()); // TYPE
648
538
  };
649
- const guard2file = async (guard, file_path, format = "json", network) => {
650
- const queryResult = await query_objects({
651
- objects: [guard],
652
- network
653
- });
654
- const objects = queryResult.objects;
655
- if (!objects || objects.length === 0 || objects[0].type !== "Guard") {
656
- W_ERROR(
657
- WErrors.InvalidParam,
658
- `guard2file: Guard object not found: ${guard}`
659
- );
660
- return;
661
- }
662
- const guardObj = objects[0];
663
- if (!guardObj) {
664
- W_ERROR(
665
- WErrors.InvalidParam,
666
- `guard2file: Failed to get Guard object data: ${guard}`
667
- );
668
- return;
669
- }
670
- let content;
671
- if (format === "json") {
672
- content = generateGuardJson(guardObj);
673
- } else {
674
- content = generateGuardMarkdown(guardObj);
675
- }
676
- try {
677
- const resolvedPath = resolve(file_path);
678
- writeFileSync(resolvedPath, content, "utf-8");
679
- } catch (e) {
680
- W_ERROR(
681
- WErrors.InvalidParam,
682
- `guard2file: Failed to write file '${file_path}': ${e.message}`
683
- );
684
- }
539
+ /**
540
+ * Query Guard object data and export to JSON or Markdown file
541
+ * @param guard - Guard object ID or name
542
+ * @param file_path - Output file path
543
+ * @param format - Output format: "json" or "markdown"
544
+ * @param network - Network entrypoint
545
+ * @throws Error if query fails or file write fails
546
+ */
547
+ export const guard2file = async (guard, file_path, format = "json", network) => {
548
+ // Query Guard object
549
+ const queryResult = await query_objects({
550
+ objects: [guard],
551
+ network,
552
+ });
553
+ const objects = queryResult.objects;
554
+ if (!objects || objects.length === 0 || objects[0].type !== "Guard") {
555
+ W_ERROR(WErrors.InvalidParam, `guard2file: Guard object not found: ${guard}`);
556
+ return;
557
+ }
558
+ const guardObj = objects[0];
559
+ if (!guardObj) {
560
+ W_ERROR(WErrors.InvalidParam, `guard2file: Failed to get Guard object data: ${guard}`);
561
+ return;
562
+ }
563
+ // Prepare output content based on format
564
+ let content;
565
+ if (format === "json") {
566
+ content = generateGuardJson(guardObj);
567
+ }
568
+ else {
569
+ content = generateGuardMarkdown(guardObj);
570
+ }
571
+ // Write to file
572
+ try {
573
+ const resolvedPath = resolve(file_path);
574
+ writeFileSync(resolvedPath, content, "utf-8");
575
+ }
576
+ catch (e) {
577
+ W_ERROR(WErrors.InvalidParam, `guard2file: Failed to write file '${file_path}': ${e.message}`);
578
+ }
685
579
  };
580
+ /**
581
+ * Generate JSON format Guard definition with comments
582
+ */
686
583
  const generateGuardJson = (guardObj) => {
687
- const output = {};
688
- if (guardObj.description) {
689
- output.description = guardObj.description;
690
- }
691
- if (guardObj.table && guardObj.table.length > 0) {
692
- output.table = guardObj.table.map((item) => ({
693
- identifier: item.identifier,
694
- b_submission: item.b_submission,
695
- value_type: item.value_type,
696
- value: item.value,
697
- name: item.name
698
- }));
699
- }
700
- if (guardObj.root) {
701
- output.root = guardObj.root;
702
- }
703
- if (guardObj.relies && guardObj.relies.length > 0) {
704
- output.rely = {
705
- guards: guardObj.relies,
706
- logic_or: !guardObj.relies_logic_and
707
- };
708
- }
709
- return JSON.stringify(output, null, 2);
584
+ const output = {};
585
+ // Description
586
+ if (guardObj.description) {
587
+ output.description = guardObj.description;
588
+ }
589
+ // Table
590
+ if (guardObj.table && guardObj.table.length > 0) {
591
+ output.table = guardObj.table.map((item) => ({
592
+ identifier: item.identifier,
593
+ b_submission: item.b_submission,
594
+ value_type: item.value_type,
595
+ value: item.value,
596
+ name: item.name,
597
+ }));
598
+ }
599
+ // Root node - use guardObj.root directly (already parsed tree structure)
600
+ if (guardObj.root) {
601
+ output.root = guardObj.root;
602
+ }
603
+ // Rely (dependencies)
604
+ if (guardObj.relies && guardObj.relies.length > 0) {
605
+ output.rely = {
606
+ guards: guardObj.relies,
607
+ logic_or: !guardObj.relies_logic_and,
608
+ };
609
+ }
610
+ return JSON.stringify(output, null, 2);
710
611
  };
612
+ /**
613
+ * Generate Markdown format Guard definition with comments
614
+ */
711
615
  const generateGuardMarkdown = (guardObj) => {
712
- const lines = [];
713
- lines.push(`# Guard Definition`);
714
- lines.push("");
715
- lines.push(`**Object ID:** ${guardObj.object}`);
716
- lines.push("");
717
- lines.push("## Description");
718
- lines.push("");
719
- lines.push(guardObj.description || "");
720
- lines.push("");
721
- lines.push("## Table (Data Definitions)");
722
- lines.push("");
723
- lines.push("| Identifier | b_submission | value_type | value | name |");
724
- lines.push("|------------|--------------|------------|-------|------|");
725
- if (guardObj.table && guardObj.table.length > 0) {
726
- for (const item of guardObj.table) {
727
- const itemValueType = parseValueType(item.value_type);
728
- const valueTypeStr = valueTypeToString(itemValueType);
729
- const valueStr = formatValueForMarkdown(item.value);
730
- lines.push(
731
- `| ${item.identifier} | ${item.b_submission} | ${valueTypeStr} (${item.value_type}) | ${valueStr} | ${item.name} |`
732
- );
733
- }
734
- } else {
735
- lines.push("| - | - | - | - | - |");
736
- }
737
- lines.push("");
738
- lines.push("## Root (Computational Tree)");
739
- lines.push("");
740
- lines.push("The root node MUST return a Bool value (pass/fail).");
741
- lines.push("");
742
- if (guardObj.root) {
743
- lines.push("```json");
744
- lines.push(JSON.stringify(guardObj.root, null, 2));
745
- lines.push("```");
616
+ const lines = [];
617
+ // Header
618
+ lines.push(`# Guard Definition`);
746
619
  lines.push("");
747
- const nodeComments = generateNodeComments(guardObj.root);
748
- if (nodeComments.length > 0) {
749
- lines.push("### Node Comments");
750
- lines.push("");
751
- for (const comment of nodeComments) {
752
- lines.push(`- **${comment.type}**: ${comment.description}`);
753
- }
754
- lines.push("");
755
- }
756
- } else {
757
- lines.push("*No root node data available*");
620
+ lines.push(`**Object ID:** ${guardObj.object}`);
621
+ lines.push("");
622
+ // Summary
623
+ lines.push("## Summary");
624
+ lines.push("");
625
+ const description = guardObj.description || "";
626
+ const tableCount = guardObj.table ? guardObj.table.length : 0;
627
+ let summary = `${description.length > 100 ? description.substring(0, 97) + "..." : description}`;
628
+ summary += ` [${tableCount} tables]`;
629
+ lines.push(summary);
758
630
  lines.push("");
759
- }
760
- if (guardObj.relies && guardObj.relies.length > 0) {
761
- lines.push("## Rely (Dependencies)");
631
+ // Description
632
+ lines.push("## Description");
762
633
  lines.push("");
763
- lines.push(`**Logic:** ${guardObj.relies_logic_and ? "AND" : "OR"}`);
634
+ lines.push(guardObj.description || "");
764
635
  lines.push("");
765
- lines.push("**Dependent Guards:**");
766
- for (const rely of guardObj.relies) {
767
- lines.push(`- ${rely}`);
636
+ // Table
637
+ lines.push("## Table (Data Definitions)");
638
+ lines.push("");
639
+ lines.push("| Identifier | b_submission | value_type | value | name |");
640
+ lines.push("|------------|--------------|------------|-------|------|");
641
+ if (guardObj.table && guardObj.table.length > 0) {
642
+ for (const item of guardObj.table) {
643
+ const itemValueType = parseValueType(item.value_type);
644
+ const valueTypeStr = valueTypeToString(itemValueType);
645
+ const valueStr = formatValueForMarkdown(item.value);
646
+ lines.push(`| ${item.identifier} | ${item.b_submission} | ${valueTypeStr} (${item.value_type}) | ${valueStr} | ${item.name} |`);
647
+ }
768
648
  }
649
+ else {
650
+ lines.push("| - | - | - | - | - |");
651
+ }
652
+ lines.push("");
653
+ // Root node - use guardObj.root directly (already parsed tree structure)
654
+ lines.push("## Root (Computational Tree)");
655
+ lines.push("");
656
+ lines.push("The root node MUST return a Bool value (pass/fail).");
769
657
  lines.push("");
770
- }
771
- lines.push("## Guard Instructions Reference");
772
- lines.push("");
773
- lines.push("Use these instructions in query nodes:");
774
- lines.push("");
775
- lines.push("| ID | Name | Object Type | Return Type | Description |");
776
- lines.push("|----|------|-------------|-------------|-------------|");
777
- for (const query of GUARDQUERY.slice(0, 20)) {
778
- lines.push(
779
- `| ${query.id} | ${query.name} | ${query.objectType} | ${valueTypeToString(query.return)} | ${query.description} |`
780
- );
781
- }
782
- lines.push("");
783
- lines.push(
784
- "*For complete list, use `wowok_buildin_info` with query='guard instructions'*"
785
- );
786
- lines.push("");
787
- return lines.join("\n");
658
+ if (guardObj.root) {
659
+ lines.push("```json");
660
+ lines.push(JSON.stringify(guardObj.root, null, 2));
661
+ lines.push("```");
662
+ lines.push("");
663
+ // Add node comments
664
+ const nodeComments = generateNodeComments(guardObj.root);
665
+ if (nodeComments.length > 0) {
666
+ lines.push("### Node Comments");
667
+ lines.push("");
668
+ for (const comment of nodeComments) {
669
+ lines.push(`- **${comment.type}**: ${comment.description}`);
670
+ }
671
+ lines.push("");
672
+ }
673
+ }
674
+ else {
675
+ lines.push("*No root node data available*");
676
+ lines.push("");
677
+ }
678
+ // Rely
679
+ if (guardObj.relies && guardObj.relies.length > 0) {
680
+ lines.push("## Rely (Dependencies)");
681
+ lines.push("");
682
+ lines.push(`**Logic:** ${guardObj.relies_logic_and ? "AND" : "OR"}`);
683
+ lines.push("");
684
+ lines.push("**Dependent Guards:**");
685
+ for (const rely of guardObj.relies) {
686
+ lines.push(`- ${rely}`);
687
+ }
688
+ lines.push("");
689
+ }
690
+ return lines.join("\n");
788
691
  };
692
+ /**
693
+ * Format value for markdown display
694
+ */
789
695
  const formatValueForMarkdown = (value) => {
790
- if (value === void 0 || value === null) {
791
- return "-";
792
- }
793
- if (typeof value === "boolean") {
794
- return value ? "true" : "false";
795
- }
796
- if (typeof value === "string") {
797
- if (value.length > 30) {
798
- return value.substring(0, 27) + "...";
696
+ if (value === undefined || value === null) {
697
+ return "-";
799
698
  }
800
- return value;
801
- }
802
- if (typeof value === "number") {
803
- return value.toString();
804
- }
805
- if (Array.isArray(value)) {
806
- if (value.length === 0) return "[]";
807
- if (value.length > 3) {
808
- return `[${value.slice(0, 3).join(", ")}, ... (${value.length} items)]`;
699
+ if (typeof value === "boolean") {
700
+ return value ? "true" : "false";
809
701
  }
810
- return `[${value.join(", ")}]`;
811
- }
812
- if (typeof value === "object") {
813
- return "{...}";
814
- }
815
- return String(value);
702
+ if (typeof value === "string") {
703
+ if (value.length > 30) {
704
+ return value.substring(0, 27) + "...";
705
+ }
706
+ return value;
707
+ }
708
+ if (typeof value === "number") {
709
+ return value.toString();
710
+ }
711
+ if (Array.isArray(value)) {
712
+ if (value.length === 0)
713
+ return "[]";
714
+ if (value.length > 3) {
715
+ return `[${value.slice(0, 3).join(", ")}, ... (${value.length} items)]`;
716
+ }
717
+ return `[${value.join(", ")}]`;
718
+ }
719
+ if (typeof value === "object") {
720
+ return "{...}";
721
+ }
722
+ return String(value);
816
723
  };
817
- const generateNodeComments = (node, comments = []) => {
818
- if (!node) return comments;
819
- if (node.type === "query") {
820
- const queryId = typeof node.query === "number" ? node.query : void 0;
821
- if (queryId !== void 0) {
822
- const queryInfo = GUARDQUERY.find((q) => q.id === queryId);
823
- if (queryInfo) {
724
+ /**
725
+ * Generate comments for Guard nodes
726
+ */
727
+ export const generateNodeComments = (node, comments = []) => {
728
+ if (!node)
729
+ return comments;
730
+ // Add comment for this node
731
+ if (node.type === "query") {
732
+ const queryId = typeof node.query === "number" ? node.query : undefined;
733
+ if (queryId !== undefined) {
734
+ const queryInfo = GUARDQUERY.find((q) => q.id === queryId);
735
+ if (queryInfo) {
736
+ comments.push({
737
+ type: `query(${node.query})`,
738
+ description: `${queryInfo.name}: ${queryInfo.description}`,
739
+ });
740
+ }
741
+ }
742
+ }
743
+ else if (node.type.startsWith("logic_")) {
824
744
  comments.push({
825
- type: `query(${node.query})`,
826
- description: `${queryInfo.name}: ${queryInfo.description}`
745
+ type: node.type,
746
+ description: `Logic operation: ${node.type.replace(/_/g, " ")}`,
827
747
  });
828
- }
829
748
  }
830
- } else if (node.type.startsWith("logic_")) {
831
- comments.push({
832
- type: node.type,
833
- description: `Logic operation: ${node.type.replace(/_/g, " ")}`
834
- });
835
- } else if (node.type.startsWith("calc_")) {
836
- comments.push({
837
- type: node.type,
838
- description: `Calculation: ${node.type.replace(/_/g, " ")}`
839
- });
840
- } else if (node.type.startsWith("convert_")) {
841
- comments.push({
842
- type: node.type,
843
- description: `Type conversion: ${node.type.replace(/_/g, " ")}`
844
- });
845
- }
846
- if ("nodes" in node && Array.isArray(node.nodes)) {
847
- for (const childNode of node.nodes) {
848
- generateNodeComments(childNode, comments);
749
+ else if (node.type.startsWith("calc_")) {
750
+ comments.push({
751
+ type: node.type,
752
+ description: `Calculation: ${node.type.replace(/_/g, " ")}`,
753
+ });
754
+ }
755
+ else if (node.type.startsWith("convert_")) {
756
+ comments.push({
757
+ type: node.type,
758
+ description: `Type conversion: ${node.type.replace(/_/g, " ")}`,
759
+ });
760
+ }
761
+ // Recursively process child nodes
762
+ if ("nodes" in node && Array.isArray(node.nodes)) {
763
+ for (const childNode of node.nodes) {
764
+ generateNodeComments(childNode, comments);
765
+ }
766
+ }
767
+ if ("node" in node && node.node) {
768
+ generateNodeComments(node.node, comments);
769
+ }
770
+ if ("parameters" in node && Array.isArray(node.parameters)) {
771
+ for (const param of node.parameters) {
772
+ generateNodeComments(param, comments);
773
+ }
774
+ }
775
+ if ("nodeLeft" in node && node.nodeLeft) {
776
+ generateNodeComments(node.nodeLeft, comments);
849
777
  }
850
- }
851
- if ("node" in node && node.node) {
852
- generateNodeComments(node.node, comments);
853
- }
854
- if ("parameters" in node && Array.isArray(node.parameters)) {
855
- for (const param of node.parameters) {
856
- generateNodeComments(param, comments);
778
+ if ("nodeRight" in node && node.nodeRight) {
779
+ generateNodeComments(node.nodeRight, comments);
857
780
  }
858
- }
859
- if ("nodeLeft" in node && node.nodeLeft) {
860
- generateNodeComments(node.nodeLeft, comments);
861
- }
862
- if ("nodeRight" in node && node.nodeRight) {
863
- generateNodeComments(node.nodeRight, comments);
864
- }
865
- return comments;
781
+ return comments;
866
782
  };
783
+ /**
784
+ * Convert ValueType enum to string representation
785
+ */
867
786
  const valueTypeToString = (valueType) => {
868
- const typeMap = {
869
- [ValueType.Bool]: "Bool",
870
- [ValueType.Address]: "Address",
871
- [ValueType.String]: "String",
872
- [ValueType.U8]: "U8",
873
- [ValueType.U16]: "U16",
874
- [ValueType.U32]: "U32",
875
- [ValueType.U64]: "U64",
876
- [ValueType.U128]: "U128",
877
- [ValueType.U256]: "U256",
878
- [ValueType.VecBool]: "VecBool",
879
- [ValueType.VecAddress]: "VecAddress",
880
- [ValueType.VecString]: "VecString",
881
- [ValueType.VecU8]: "VecU8",
882
- [ValueType.VecU16]: "VecU16",
883
- [ValueType.VecU32]: "VecU32",
884
- [ValueType.VecU64]: "VecU64",
885
- [ValueType.VecU128]: "VecU128",
886
- [ValueType.VecU256]: "VecU256",
887
- [ValueType.VecVecU8]: "VecVecU8",
888
- [ValueType.Value]: "Value"
889
- };
890
- return typeMap[valueType] || `Unknown(${valueType})`;
787
+ const typeMap = {
788
+ [ValueType.Bool]: "Bool",
789
+ [ValueType.Address]: "Address",
790
+ [ValueType.String]: "String",
791
+ [ValueType.U8]: "U8",
792
+ [ValueType.U16]: "U16",
793
+ [ValueType.U32]: "U32",
794
+ [ValueType.U64]: "U64",
795
+ [ValueType.U128]: "U128",
796
+ [ValueType.U256]: "U256",
797
+ [ValueType.VecBool]: "VecBool",
798
+ [ValueType.VecAddress]: "VecAddress",
799
+ [ValueType.VecString]: "VecString",
800
+ [ValueType.VecU8]: "VecU8",
801
+ [ValueType.VecU16]: "VecU16",
802
+ [ValueType.VecU32]: "VecU32",
803
+ [ValueType.VecU64]: "VecU64",
804
+ [ValueType.VecU128]: "VecU128",
805
+ [ValueType.VecU256]: "VecU256",
806
+ [ValueType.VecVecU8]: "VecVecU8",
807
+ [ValueType.Value]: "Value",
808
+ };
809
+ return typeMap[valueType] || `Unknown(${valueType})`;
891
810
  };
892
- const gen_passport = async (env, guard, info) => {
893
- if (!isValidWowAddress(guard)) {
894
- W_ERROR(WErrors.InvalidParam, "guard invalid: guard empty");
895
- }
896
- await resolveCallEnv(env);
897
- const s = await get_guardSubmissions(env, [guard]);
898
- if (s.submission.length > 0) {
899
- if (!info) {
900
- return {
901
- type: "submission",
902
- guard: s.guard,
903
- submission: s.submission
904
- };
905
- } else {
906
- return await verify_guard(env, info);
811
+ export const gen_passport = async (env, guard, info) => {
812
+ if (!isValidWowAddress(guard)) {
813
+ W_ERROR(WErrors.InvalidParam, "guard invalid: guard empty");
814
+ }
815
+ await resolveCallEnv(env);
816
+ const s = await get_guardSubmissions(env, [guard]);
817
+ if (s.submission.length > 0) {
818
+ if (!info) {
819
+ return {
820
+ type: "submission",
821
+ guard: s.guard,
822
+ submission: s.submission,
823
+ };
824
+ }
825
+ else {
826
+ return await verify_guard(env, info);
827
+ }
828
+ }
829
+ else {
830
+ return await verify_guard(env, {
831
+ type: "submission",
832
+ guard: [{ object: guard, impack: true }],
833
+ submission: [],
834
+ });
907
835
  }
908
- } else {
909
- return await verify_guard(env, {
910
- type: "submission",
911
- guard: [{ object: guard, impack: true }],
912
- submission: []
913
- });
914
- }
915
836
  };
837
+ /**
838
+ * Detect file format from content or extension
839
+ */
916
840
  function detectFileFormatFromContent(text) {
917
- const trimmed = text.trim();
918
- if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
919
- return "json";
920
- }
921
- return "markdown";
841
+ const trimmed = text.trim();
842
+ if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
843
+ return "json";
844
+ }
845
+ return "markdown";
922
846
  }
847
+ /**
848
+ * Extract JSON from markdown code blocks
849
+ */
923
850
  function extractJsonFromMarkdown(markdown) {
924
- const codeBlockRegex = /```(?:json)?\s*\n([\s\S]*?)```/g;
925
- let match;
926
- let lastMatch = null;
927
- while ((match = codeBlockRegex.exec(markdown)) !== null) {
928
- const jsonContent = match[1].trim();
929
- if (jsonContent.startsWith("{") || jsonContent.startsWith("[")) {
930
- const beforeMatch = markdown.substring(0, match.index);
931
- const lineOffset = (beforeMatch.match(/\n/g) || []).length + 1;
932
- lastMatch = { json: jsonContent, lineOffset };
851
+ const codeBlockRegex = /```(?:json)?\s*\n([\s\S]*?)```/g;
852
+ let match;
853
+ let lastMatch = null;
854
+ while ((match = codeBlockRegex.exec(markdown)) !== null) {
855
+ const jsonContent = match[1].trim();
856
+ if (jsonContent.startsWith("{") || jsonContent.startsWith("[")) {
857
+ const beforeMatch = markdown.substring(0, match.index);
858
+ const lineOffset = (beforeMatch.match(/\n/g) || []).length + 1;
859
+ lastMatch = { json: jsonContent, lineOffset };
860
+ // Continue to find the last JSON block (most complete one)
861
+ }
933
862
  }
934
- }
935
- return lastMatch;
863
+ return lastMatch;
936
864
  }
865
+ /**
866
+ * Parse table from markdown section
867
+ * First tries JSON code block, then falls back to markdown table
868
+ */
937
869
  function parseTableFromMarkdown(section) {
938
- const jsonMatch = section.match(/```(?:json)?\s*\n([\s\S]*?)```/);
939
- if (jsonMatch) {
940
- try {
941
- const parsed = JSON.parse(jsonMatch[1]);
942
- if (Array.isArray(parsed)) {
943
- return parsed;
944
- }
945
- } catch {
946
- }
947
- }
948
- const tableRows = section.match(/\|[^\n]+\|/g);
949
- if (tableRows && tableRows.length > 2) {
950
- return tableRows.slice(2).map((row) => {
951
- const cells = row.split("|").filter((c) => c.trim()).map((c) => c.trim());
952
- const valueTypeCell = cells[2];
953
- let value_type;
954
- const numericMatch = valueTypeCell.match(/\d+/);
955
- if (numericMatch) {
956
- value_type = parseInt(numericMatch[0], 10);
957
- } else {
958
- const typeNameMatch = valueTypeCell.match(/^([A-Za-z]+)/);
959
- if (typeNameMatch) {
960
- value_type = typeNameMatch[1];
961
- } else {
962
- throw new Error(
963
- `Invalid value_type in table row: "${valueTypeCell}". Expected a number (0-19) or type name (e.g., "U64", "Address")`
964
- );
870
+ // Try JSON code block first
871
+ const jsonMatch = section.match(/```(?:json)?\s*\n([\s\S]*?)```/);
872
+ if (jsonMatch) {
873
+ try {
874
+ const parsed = JSON.parse(jsonMatch[1]);
875
+ if (Array.isArray(parsed)) {
876
+ return parsed;
877
+ }
965
878
  }
966
- }
967
- return {
968
- identifier: parseInt(cells[0], 10),
969
- b_submission: cells[1].toLowerCase() === "true",
970
- value_type,
971
- value: cells[3] === "-" ? void 0 : cells[3],
972
- name: cells[4] === "-" ? void 0 : cells[4]
973
- };
974
- });
975
- }
976
- return void 0;
879
+ catch {
880
+ // JSON parse failed, continue to table parsing
881
+ }
882
+ }
883
+ // Fallback to markdown table
884
+ const tableRows = section.match(/\|[^\n]+\|/g);
885
+ if (tableRows && tableRows.length > 2) {
886
+ // Skip header and separator rows
887
+ return tableRows.slice(2).map((row) => {
888
+ const cells = row
889
+ .split("|")
890
+ .filter((c) => c.trim())
891
+ .map((c) => c.trim());
892
+ // Parse value_type - can be number (6) or string ("U64" or "U64 (6)")
893
+ const valueTypeCell = cells[2];
894
+ let value_type;
895
+ // Try to parse as number first
896
+ const numericMatch = valueTypeCell.match(/\d+/);
897
+ if (numericMatch) {
898
+ value_type = parseInt(numericMatch[0], 10);
899
+ }
900
+ else {
901
+ // Try to extract type name (e.g., "U64" from "U64" or "U64 (6)")
902
+ const typeNameMatch = valueTypeCell.match(/^([A-Za-z]+)/);
903
+ if (typeNameMatch) {
904
+ value_type = typeNameMatch[1];
905
+ }
906
+ else {
907
+ throw new Error(`Invalid value_type in table row: "${valueTypeCell}". Expected a number (0-19) or type name (e.g., "U64", "Address")`);
908
+ }
909
+ }
910
+ return {
911
+ identifier: parseInt(cells[0], 10),
912
+ b_submission: cells[1].toLowerCase() === "true",
913
+ value_type,
914
+ value: cells[3] === "-" ? undefined : cells[3],
915
+ name: cells[4] === "-" ? undefined : cells[4],
916
+ };
917
+ });
918
+ }
919
+ return undefined;
977
920
  }
921
+ /**
922
+ * Parse rely from markdown section
923
+ */
978
924
  function parseRelyFromMarkdown(section) {
979
- const logicMatch = section.match(/\*\*Logic:\*\*\s*(AND|OR)/i);
980
- const guardListMatches = section.match(/^\s*[-*]\s*(\S+)$/gm);
981
- if (logicMatch || guardListMatches) {
982
- return {
983
- logic_or: logicMatch ? logicMatch[1].toUpperCase() === "OR" : false,
984
- guards: guardListMatches ? guardListMatches.map(
985
- (g) => g.replace(/^\s*[-*]\s*/, "").trim()
986
- ) : []
987
- };
988
- }
989
- return void 0;
925
+ const logicMatch = section.match(/\*\*Logic:\*\*\s*(AND|OR)/i);
926
+ const guardListMatches = section.match(/^\s*[-*]\s*(\S+)$/gm);
927
+ if (logicMatch || guardListMatches) {
928
+ return {
929
+ logic_or: logicMatch ? logicMatch[1].toUpperCase() === "OR" : false,
930
+ guards: guardListMatches
931
+ ? guardListMatches.map((g) => g.replace(/^\s*[-*]\s*/, "").trim())
932
+ : [],
933
+ };
934
+ }
935
+ return undefined;
990
936
  }
991
- function parseGuardFromMarkdown(content) {
992
- const errors = [];
993
- const result = {};
994
- const jsonMatch = extractJsonFromMarkdown(content);
995
- if (jsonMatch) {
996
- try {
997
- const parsed = JSON.parse(
998
- jsonMatch.json
999
- );
1000
- Object.assign(result, parsed);
1001
- } catch (e) {
1002
- errors.push({
1003
- message: `Failed to parse JSON from code block: ${e.message}`,
1004
- path: "/",
1005
- line: jsonMatch.lineOffset
1006
- });
937
+ /**
938
+ * Parse Guard definition from markdown content
939
+ * Unified parsing logic shared between SDK and MCP
940
+ */
941
+ export function parseGuardFromMarkdown(content) {
942
+ const errors = [];
943
+ const result = {};
944
+ // Try to extract full JSON from code blocks first
945
+ const jsonMatch = extractJsonFromMarkdown(content);
946
+ if (jsonMatch) {
947
+ try {
948
+ const parsed = JSON.parse(jsonMatch.json);
949
+ Object.assign(result, parsed);
950
+ }
951
+ catch (e) {
952
+ errors.push({
953
+ message: `Failed to parse JSON from code block: ${e.message}`,
954
+ path: "/",
955
+ line: jsonMatch.lineOffset,
956
+ });
957
+ }
1007
958
  }
1008
- }
1009
- if (!result.description) {
1010
- const descMatch = content.match(
1011
- /(?:^|\n)#+\s*(?:Description|Description|Description)[^\n]*\n+([^\n#]+)/i
1012
- );
1013
- if (descMatch) {
1014
- result.description = descMatch[1].trim();
959
+ // Parse description section (if not already from JSON)
960
+ if (!result.description) {
961
+ const descMatch = content.match(/(?:^|\n)#+\s*(?:Description|Description|Description)[^\n]*\n+([^\n#]+)/i);
962
+ if (descMatch) {
963
+ result.description = descMatch[1].trim();
964
+ }
1015
965
  }
1016
- }
1017
- if (!result.table) {
1018
- const tableMatch = content.match(
1019
- /(?:^|\n)#+\s*(?:Table|Data Table|数据表)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i
1020
- );
1021
- if (tableMatch) {
1022
- const table = parseTableFromMarkdown(tableMatch[1]);
1023
- if (table) {
1024
- result.table = table;
1025
- }
966
+ // Parse table section (if not already from JSON)
967
+ if (!result.table) {
968
+ const tableMatch = content.match(/(?:^|\n)#+\s*(?:Table|Data Table|数据表)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);
969
+ if (tableMatch) {
970
+ const table = parseTableFromMarkdown(tableMatch[1]);
971
+ if (table) {
972
+ result.table = table;
973
+ }
974
+ }
1026
975
  }
1027
- }
1028
- if (!result.root) {
1029
- const rootMatch = content.match(
1030
- /(?:^|\n)#+\s*(?:Root|根节点)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i
1031
- );
1032
- if (rootMatch) {
1033
- const rootSection = rootMatch[1];
1034
- const rootJsonMatch = rootSection.match(
1035
- /```(?:json)?\s*\n([\s\S]*?)```/
1036
- );
1037
- if (rootJsonMatch) {
1038
- try {
1039
- result.root = JSON.parse(rootJsonMatch[1]);
1040
- } catch (e) {
1041
- errors.push({
1042
- message: `Failed to parse root JSON: ${e.message}`,
1043
- path: "/root"
1044
- });
976
+ // Parse root section (if not already from JSON)
977
+ if (!result.root) {
978
+ const rootMatch = content.match(/(?:^|\n)#+\s*(?:Root|根节点)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);
979
+ if (rootMatch) {
980
+ const rootSection = rootMatch[1];
981
+ const rootJsonMatch = rootSection.match(/```(?:json)?\s*\n([\s\S]*?)```/);
982
+ if (rootJsonMatch) {
983
+ try {
984
+ result.root = JSON.parse(rootJsonMatch[1]);
985
+ }
986
+ catch (e) {
987
+ errors.push({
988
+ message: `Failed to parse root JSON: ${e.message}`,
989
+ path: "/root",
990
+ });
991
+ }
992
+ }
1045
993
  }
1046
- }
1047
994
  }
1048
- }
1049
- if (!result.rely) {
1050
- const relyMatch = content.match(
1051
- /(?:^|\n)#+\s*(?:Rely|Dependencies|依赖)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i
1052
- );
1053
- if (relyMatch) {
1054
- const rely = parseRelyFromMarkdown(relyMatch[1]);
1055
- if (rely) {
1056
- result.rely = rely;
1057
- }
995
+ // Parse rely section (if not already from JSON)
996
+ if (!result.rely) {
997
+ const relyMatch = content.match(/(?:^|\n)#+\s*(?:Rely|Dependencies|依赖)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);
998
+ if (relyMatch) {
999
+ const rely = parseRelyFromMarkdown(relyMatch[1]);
1000
+ if (rely) {
1001
+ result.rely = rely;
1002
+ }
1003
+ }
1058
1004
  }
1059
- }
1060
- if (!result.root) {
1061
- errors.push({
1062
- message: "Guard root node not found in markdown file",
1063
- path: "/root"
1064
- });
1065
- return { success: false, errors };
1066
- }
1067
- return {
1068
- success: true,
1069
- data: result,
1070
- errors
1071
- };
1005
+ if (!result.root) {
1006
+ errors.push({
1007
+ message: "Guard root node not found in markdown file",
1008
+ path: "/root",
1009
+ });
1010
+ return { success: false, errors };
1011
+ }
1012
+ return {
1013
+ success: true,
1014
+ data: result,
1015
+ errors,
1016
+ };
1072
1017
  }
1073
- function parseGuardFile(content, format) {
1074
- const detectedFormat = format ?? detectFileFormatFromContent(content);
1075
- if (detectedFormat === "json") {
1076
- try {
1077
- const parsed = JSON.parse(content);
1078
- if (!parsed.root) {
1079
- return {
1080
- success: false,
1081
- errors: [
1082
- {
1083
- message: "Missing required field: root",
1084
- path: "/root"
1018
+ /**
1019
+ * Parse Guard definition from file content
1020
+ * Supports both JSON and Markdown formats
1021
+ * Unified parsing logic shared between SDK and MCP
1022
+ */
1023
+ export function parseGuardFile(content, format) {
1024
+ const detectedFormat = format ?? detectFileFormatFromContent(content);
1025
+ if (detectedFormat === "json") {
1026
+ try {
1027
+ const parsed = JSON.parse(content);
1028
+ if (!parsed.root) {
1029
+ return {
1030
+ success: false,
1031
+ errors: [
1032
+ {
1033
+ message: "Missing required field: root",
1034
+ path: "/root",
1035
+ },
1036
+ ],
1037
+ };
1085
1038
  }
1086
- ]
1087
- };
1088
- }
1089
- return { success: true, data: parsed, errors: [] };
1090
- } catch (e) {
1091
- return {
1092
- success: false,
1093
- errors: [
1094
- {
1095
- message: `JSON parse error: ${e.message}`,
1096
- path: "/"
1097
- }
1098
- ]
1099
- };
1039
+ return { success: true, data: parsed, errors: [] };
1040
+ }
1041
+ catch (e) {
1042
+ return {
1043
+ success: false,
1044
+ errors: [
1045
+ {
1046
+ message: `JSON parse error: ${e.message}`,
1047
+ path: "/",
1048
+ },
1049
+ ],
1050
+ };
1051
+ }
1100
1052
  }
1101
- }
1102
- return parseGuardFromMarkdown(content);
1053
+ // Markdown format
1054
+ return parseGuardFromMarkdown(content);
1103
1055
  }
1104
- function validateGuardNode(node) {
1105
- const errors = [];
1106
- if (!node || typeof node !== "object") {
1107
- errors.push({ message: "GuardNode must be an object", path: "/" });
1108
- return { success: false, errors };
1109
- }
1110
- const n = node;
1111
- if (!n.type || typeof n.type !== "string") {
1112
- errors.push({
1113
- message: "GuardNode must have a 'type' property",
1114
- path: "/type"
1115
- });
1116
- return { success: false, errors };
1117
- }
1118
- const validTypes = [
1119
- "identifier",
1120
- "query",
1121
- "context",
1122
- "logic_not",
1123
- "logic_and",
1124
- "logic_or",
1125
- "logic_equal",
1126
- "logic_as_u256_greater_or_equal",
1127
- "logic_as_u256_lesser_or_equal",
1128
- "logic_as_u256_greater",
1129
- "logic_as_u256_lesser",
1130
- "logic_as_u256_equal",
1131
- "logic_string_contains",
1132
- "logic_string_nocase_contains",
1133
- "logic_string_nocase_equal",
1134
- "calc_number_add",
1135
- "calc_number_subtract",
1136
- "calc_number_multiply",
1137
- "calc_number_divide",
1138
- "calc_number_mod",
1139
- "calc_string_length",
1140
- "calc_string_nocase_contains",
1141
- "calc_string_nocase_equal",
1142
- "calc_string_contains",
1143
- "calc_string_indexof",
1144
- "calc_string_nocase_indexof",
1145
- "convert_number_address",
1146
- "convert_address_number",
1147
- "convert_number_string",
1148
- "convert_string_number",
1149
- "convert_safe_u8",
1150
- "convert_safe_u16",
1151
- "convert_safe_u32",
1152
- "convert_safe_u64",
1153
- "convert_safe_u128",
1154
- "convert_safe_u256",
1155
- "value_type",
1156
- "vec_length",
1157
- "vec_contains_bool",
1158
- "vec_contains_address",
1159
- "vec_contains_string",
1160
- "vec_contains_string_nocase",
1161
- "vec_contains_number",
1162
- "vec_indexof_bool",
1163
- "vec_indexof_address",
1164
- "vec_indexof_string",
1165
- "vec_indexof_string_nocase",
1166
- "vec_indexof_number"
1167
- ];
1168
- if (!validTypes.includes(n.type)) {
1169
- errors.push({
1170
- message: `Invalid GuardNode type: ${n.type}`,
1171
- path: "/type"
1172
- });
1173
- }
1174
- return { success: errors.length === 0, errors };
1175
- }
1176
- function formatGuardParseErrors(errors) {
1177
- return errors.map((e) => {
1178
- let msg = `Path: ${e.path}`;
1179
- if (e.line !== void 0 && e.column !== void 0) {
1180
- msg += ` (line ${e.line}, column ${e.column})`;
1056
+ /**
1057
+ * Validate GuardNode structure
1058
+ * Basic validation without Zod dependency
1059
+ */
1060
+ export function validateGuardNode(node) {
1061
+ const errors = [];
1062
+ if (!node || typeof node !== "object") {
1063
+ errors.push({ message: "GuardNode must be an object", path: "/" });
1064
+ return { success: false, errors };
1181
1065
  }
1182
- msg += `
1183
- Error: ${e.message}`;
1184
- return msg;
1185
- }).join("\n\n");
1066
+ const n = node;
1067
+ if (!n.type || typeof n.type !== "string") {
1068
+ errors.push({
1069
+ message: "GuardNode must have a 'type' property",
1070
+ path: "/type",
1071
+ });
1072
+ return { success: false, errors };
1073
+ }
1074
+ // Basic type validation based on node type
1075
+ const validTypes = [
1076
+ "identifier",
1077
+ "query",
1078
+ "context",
1079
+ "logic_not",
1080
+ "logic_and",
1081
+ "logic_or",
1082
+ "logic_equal",
1083
+ "logic_as_u256_greater_or_equal",
1084
+ "logic_as_u256_lesser_or_equal",
1085
+ "logic_as_u256_greater",
1086
+ "logic_as_u256_lesser",
1087
+ "logic_as_u256_equal",
1088
+ "logic_string_contains",
1089
+ "logic_string_nocase_contains",
1090
+ "logic_string_nocase_equal",
1091
+ "calc_number_add",
1092
+ "calc_number_subtract",
1093
+ "calc_number_multiply",
1094
+ "calc_number_divide",
1095
+ "calc_number_mod",
1096
+ "calc_string_length",
1097
+ "calc_string_nocase_contains",
1098
+ "calc_string_nocase_equal",
1099
+ "calc_string_contains",
1100
+ "calc_string_indexof",
1101
+ "calc_string_nocase_indexof",
1102
+ "convert_number_address",
1103
+ "convert_address_number",
1104
+ "convert_number_string",
1105
+ "convert_string_number",
1106
+ "convert_safe_u8",
1107
+ "convert_safe_u16",
1108
+ "convert_safe_u32",
1109
+ "convert_safe_u64",
1110
+ "convert_safe_u128",
1111
+ "convert_safe_u256",
1112
+ "value_type",
1113
+ "vec_length",
1114
+ "vec_contains_bool",
1115
+ "vec_contains_address",
1116
+ "vec_contains_string",
1117
+ "vec_contains_string_nocase",
1118
+ "vec_contains_number",
1119
+ "vec_indexof_bool",
1120
+ "vec_indexof_address",
1121
+ "vec_indexof_string",
1122
+ "vec_indexof_string_nocase",
1123
+ "vec_indexof_number",
1124
+ ];
1125
+ if (!validTypes.includes(n.type)) {
1126
+ errors.push({
1127
+ message: `Invalid GuardNode type: ${n.type}`,
1128
+ path: "/type",
1129
+ });
1130
+ }
1131
+ return { success: errors.length === 0, errors };
1186
1132
  }
1187
- export {
1188
- CallGuard,
1189
- create,
1190
- formatGuardParseErrors,
1191
- gen_passport,
1192
- guard2file,
1193
- guardFn,
1194
- newGuard,
1195
- parseGuardFile,
1196
- parseGuardFromMarkdown,
1197
- reliesAdd,
1198
- reliesClear,
1199
- reliesLogic,
1200
- reliesRemove,
1201
- validateGuardNode
1202
- };
1133
+ /**
1134
+ * Format parse errors for display
1135
+ */
1136
+ export function formatGuardParseErrors(errors) {
1137
+ return errors
1138
+ .map((e) => {
1139
+ let msg = `Path: ${e.path}`;
1140
+ if (e.line !== undefined && e.column !== undefined) {
1141
+ msg += ` (line ${e.line}, column ${e.column})`;
1142
+ }
1143
+ msg += `\n Error: ${e.message}`;
1144
+ return msg;
1145
+ })
1146
+ .join("\n\n");
1147
+ }
1148
+ //# sourceMappingURL=guard.js.map