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,442 +1,635 @@
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);
1
+ // Copyright (c) Wowok.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ /**
4
+ * WIP (Witness Immutable Promise) - 见证不可篡改承诺
5
+ *
6
+ * WIP 是一种用于通过网络向 AI 传递不可篡改承诺信息的 JSON 文件格式。
7
+ * 该格式设计用于确保内容完整性,支持文字和多图片的组合,并通过哈希值防止篡改。
8
+ *
9
+ * === 完整示例 ===
10
+ *
11
+ * 基础示例(无签名):
12
+ * ```json
13
+ * {
14
+ * "wip": "https://schema.wip/v1",
15
+ * "payload": {
16
+ * "content": {
17
+ * "text": "我承诺在2024年12月31日前完成项目交付。",
18
+ * "format": "plain"
19
+ * },
20
+ * "media": [
21
+ * {
22
+ * "id": "img-001",
23
+ * "type": "image/png",
24
+ * "data": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==",
25
+ * "filename": "contract-signature.png"
26
+ * }
27
+ * ]
28
+ * },
29
+ * "meta": {
30
+ * "type": "wip",
31
+ * "version": "1.0.0",
32
+ * "created": "2024-03-15T08:30:00Z",
33
+ * "hash": "sha256:3a6eb0790f39ac87c94f3856b2dd2c5d110e6811602261a9a923d3bb23adc8b7",
34
+ * "algorithm": "sha256"
35
+ * }
36
+ * }
37
+ * ```
38
+ *
39
+ * 带数字签名的示例:
40
+ * ```json
41
+ * {
42
+ * "wip": "https://schema.wip/v1",
43
+ * "payload": {
44
+ * "content": {
45
+ * "text": "我承诺在2024年12月31日前完成项目交付。",
46
+ * "format": "plain"
47
+ * },
48
+ * "media": [
49
+ * {
50
+ * "id": "img-001",
51
+ * "type": "image/png",
52
+ * "data": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="
53
+ * }
54
+ * ]
55
+ * },
56
+ * "meta": {
57
+ * "type": "wip",
58
+ * "version": "1.0.0",
59
+ * "created": "2024-03-15T08:30:00Z",
60
+ * "hash": "sha256:3a6eb0790f39ac87c94f3856b2dd2c5d110e6811602261a9a923d3bb23adc8b7",
61
+ * "algorithm": "sha256",
62
+ * "signature": {
63
+ * "value": "base64EncodedSignatureValue",
64
+ * "publicKey": "did:web:example.com#keys-1",
65
+ * "algorithm": "Ed25519"
66
+ * }
67
+ * }
68
+ * }
69
+ * ```
70
+ *
71
+ * === 字段说明 ===
72
+ *
73
+ * - wip: 根级标识,值为 schema URL
74
+ * - payload: 内容载荷
75
+ * - content: 文字内容
76
+ * - text: 文字内容
77
+ * - format: 格式 (plain | markdown | html)
78
+ * - media: 媒体文件数组
79
+ * - id: 唯一标识
80
+ * - type: MIME 类型 (image/png, image/jpeg, image/gif, image/webp)
81
+ * - data: Base64 编码的文件数据
82
+ * - filename: 可选文件名
83
+ * - meta: 元数据
84
+ * - type: 文件类型标识,固定为 "wip"
85
+ * - 全称: Witness Immutable Promise (见证不可篡改承诺)
86
+ * - 用途: 用于通过网络向 AI 传递不可篡改的承诺信息,确保内容完整性
87
+ * - version: 格式版本号
88
+ * - created: 创建时间 (ISO 8601)
89
+ * - hash: payload 的 SHA-256 哈希值,格式为 "sha256:hexString"
90
+ * - algorithm: 哈希算法标识
91
+ * - signature: 可选的数字签名
92
+ * - value: Base64 编码的签名值
93
+ * - publicKey: 验证公钥或 DID
94
+ * - algorithm: 签名算法
95
+ *
96
+ * === 缓存目录建议 ===
97
+ *
98
+ * 对于频繁使用的 WIP 文件,建议配置本地缓存目录:
99
+ *
100
+ * 1. 缓存目录位置:
101
+ * - Windows: %LOCALAPPDATA%\wip\cache\ (如 C:\Users\<user>\AppData\Local\wip\cache\)
102
+ * - macOS: ~/Library/Caches/wip/
103
+ * - Linux: ~/.cache/wip/
104
+ *
105
+ * 2. 缓存结构:
106
+ * ```
107
+ * wip-cache/
108
+ * ├── files/ # 缓存的 WIP JSON 文件
109
+ * │ ├── <hash1>.json
110
+ * │ └── <hash2>.json
111
+ * ├── images/ # 缓存的图片文件
112
+ * │ └── <hash>.png
113
+ * └── index.json # 缓存索引,记录元数据
114
+ * ```
115
+ *
116
+ * 3. 缓存策略:
117
+ * - 使用 content hash 作为文件名,天然去重
118
+ * - 设置最大缓存大小 (如 100MB),LRU 淘汰
119
+ * - 缓存过期时间 (如 30 天)
120
+ *
121
+ * 4. 使用示例:
122
+ * ```typescript
123
+ * const wip = new WIP();
124
+ * const cache = new WipCache("~/.cache/wip");
125
+ *
126
+ * // 检查缓存
127
+ * const cached = cache.get(hash);
128
+ * if (cached) return cached;
129
+ *
130
+ * // 从网络加载并缓存
131
+ * const wipFile = await wip.loadFromUrl(url);
132
+ * cache.set(hash, wipFile);
133
+ * ```
134
+ */
4
135
  import { sha256 } from "@noble/hashes/sha256";
5
136
  import { bytesToHex } from "@noble/hashes/utils";
6
137
  import * as fs from "fs";
7
138
  import * as path from "path";
139
+ // ========== 常量定义 ==========
8
140
  const WIP_SCHEMA_URL = "https://schema.wip/v1";
9
141
  const WIP_VERSION = "1.0.0";
10
- const DEFAULT_LIMITS = {
11
- maxImageSize: 2 * 1024 * 1024,
12
- // 2MB
13
- maxTotalSize: 10 * 1024 * 1024,
14
- // 10MB
15
- maxImageCount: 10,
16
- maxTextLength: 1e4
142
+ /**
143
+ * 默认限制配置
144
+ *
145
+ * 设计考虑:
146
+ * - maxImageSize: 2MB - 单张图片限制,确保 Base64 编码后不会过大
147
+ * - maxTotalSize: 10MB - 整个 WIP 文件大小限制,适合网络传输
148
+ * - maxImageCount: 10 - 最多10张图片,满足大多数承诺场景
149
+ * - maxTextLength: 10000 - 文字内容长度限制,约5000个汉字
150
+ */
151
+ export const DEFAULT_LIMITS = {
152
+ maxImageSize: 2 * 1024 * 1024, // 2MB
153
+ maxTotalSize: 10 * 1024 * 1024, // 10MB
154
+ maxImageCount: 10,
155
+ maxTextLength: 10000,
17
156
  };
18
- class WipError extends Error {
19
- constructor(message) {
20
- super(message);
21
- this.name = "WipError";
22
- }
157
+ // ========== 错误类 ==========
158
+ export class WipError extends Error {
159
+ constructor(message) {
160
+ super(message);
161
+ this.name = "WipError";
162
+ }
23
163
  }
24
- class WipValidationError extends WipError {
25
- constructor(message) {
26
- super(message);
27
- this.name = "WipValidationError";
28
- }
164
+ export class WipValidationError extends WipError {
165
+ constructor(message) {
166
+ super(message);
167
+ this.name = "WipValidationError";
168
+ }
29
169
  }
30
- class WipSizeError extends WipError {
31
- constructor(message) {
32
- super(message);
33
- this.name = "WipSizeError";
34
- }
170
+ export class WipSizeError extends WipError {
171
+ constructor(message) {
172
+ super(message);
173
+ this.name = "WipSizeError";
174
+ }
35
175
  }
176
+ // ========== 工具函数 ==========
177
+ /**
178
+ * 检测 MIME 类型从文件数据
179
+ */
36
180
  function detectMimeType(buffer) {
37
- if (buffer.length >= 4 && buffer[0] === 137 && buffer[1] === 80 && buffer[2] === 78 && buffer[3] === 71) {
38
- return "image/png";
39
- }
40
- if (buffer.length >= 3 && buffer[0] === 255 && buffer[1] === 216 && buffer[2] === 255) {
41
- return "image/jpeg";
42
- }
43
- if (buffer.length >= 6 && buffer[0] === 71 && buffer[1] === 73 && buffer[2] === 70) {
44
- return "image/gif";
45
- }
46
- if (buffer.length >= 12 && buffer[0] === 82 && buffer[1] === 73 && buffer[2] === 70 && buffer[3] === 70 && buffer[8] === 87 && buffer[9] === 69 && buffer[10] === 66 && buffer[11] === 80) {
47
- return "image/webp";
48
- }
49
- return null;
181
+ // PNG: 89 50 4E 47
182
+ if (buffer.length >= 4 &&
183
+ buffer[0] === 0x89 &&
184
+ buffer[1] === 0x50 &&
185
+ buffer[2] === 0x4e &&
186
+ buffer[3] === 0x47) {
187
+ return "image/png";
188
+ }
189
+ // JPEG: FF D8 FF
190
+ if (buffer.length >= 3 &&
191
+ buffer[0] === 0xff &&
192
+ buffer[1] === 0xd8 &&
193
+ buffer[2] === 0xff) {
194
+ return "image/jpeg";
195
+ }
196
+ // GIF: GIF87a 或 GIF89a
197
+ if (buffer.length >= 6 &&
198
+ buffer[0] === 0x47 &&
199
+ buffer[1] === 0x49 &&
200
+ buffer[2] === 0x46) {
201
+ return "image/gif";
202
+ }
203
+ // WebP: RIFF....WEBP
204
+ if (buffer.length >= 12 &&
205
+ buffer[0] === 0x52 &&
206
+ buffer[1] === 0x49 &&
207
+ buffer[2] === 0x46 &&
208
+ buffer[3] === 0x46 &&
209
+ buffer[8] === 0x57 &&
210
+ buffer[9] === 0x45 &&
211
+ buffer[10] === 0x42 &&
212
+ buffer[11] === 0x50) {
213
+ return "image/webp";
214
+ }
215
+ return null;
50
216
  }
217
+ /**
218
+ * 将 Uint8Array 转换为 Base64 字符串
219
+ */
51
220
  function uint8ArrayToBase64(array) {
52
- let binary = "";
53
- const len = array.length;
54
- for (let i = 0; i < len; i++) {
55
- binary += String.fromCharCode(array[i]);
56
- }
57
- return btoa(binary);
221
+ let binary = "";
222
+ const len = array.length;
223
+ for (let i = 0; i < len; i++) {
224
+ binary += String.fromCharCode(array[i]);
225
+ }
226
+ return btoa(binary);
58
227
  }
228
+ /**
229
+ * 将 Base64 字符串转换为 Uint8Array
230
+ */
59
231
  function base64ToUint8Array(base64) {
60
- const binary = atob(base64);
61
- const len = binary.length;
62
- const array = new Uint8Array(len);
63
- for (let i = 0; i < len; i++) {
64
- array[i] = binary.charCodeAt(i);
65
- }
66
- return array;
232
+ const binary = atob(base64);
233
+ const len = binary.length;
234
+ const array = new Uint8Array(len);
235
+ for (let i = 0; i < len; i++) {
236
+ array[i] = binary.charCodeAt(i);
237
+ }
238
+ return array;
67
239
  }
240
+ /**
241
+ * 规范化 JSON 对象(按键名排序)
242
+ */
68
243
  function canonicalizeJson(obj) {
69
- if (obj === null || typeof obj !== "object") {
70
- return JSON.stringify(obj);
71
- }
72
- if (Array.isArray(obj)) {
73
- return "[" + obj.map(canonicalizeJson).join(",") + "]";
74
- }
75
- const sortedObj = obj;
76
- const keys = Object.keys(sortedObj).sort();
77
- const pairs = keys.map(
78
- (key) => `"${key}":${canonicalizeJson(sortedObj[key])}`
79
- );
80
- return "{" + pairs.join(",") + "}";
244
+ if (obj === null || typeof obj !== "object") {
245
+ return JSON.stringify(obj);
246
+ }
247
+ if (Array.isArray(obj)) {
248
+ return "[" + obj.map(canonicalizeJson).join(",") + "]";
249
+ }
250
+ const sortedObj = obj;
251
+ const keys = Object.keys(sortedObj).sort();
252
+ const pairs = keys.map((key) => `"${key}":${canonicalizeJson(sortedObj[key])}`);
253
+ return "{" + pairs.join(",") + "}";
81
254
  }
255
+ /**
256
+ * 计算 SHA-256 哈希
257
+ */
82
258
  function computeHash(data) {
83
- const hash = sha256(new TextEncoder().encode(data));
84
- return "sha256:" + bytesToHex(hash);
259
+ const hash = sha256(new TextEncoder().encode(data));
260
+ return "sha256:" + bytesToHex(hash);
85
261
  }
262
+ /**
263
+ * 生成唯一 ID
264
+ */
86
265
  function generateId(prefix) {
87
- const timestamp = Date.now().toString(36);
88
- const random = Math.random().toString(36).substring(2, 8);
89
- return `${prefix}-${timestamp}-${random}`;
266
+ const timestamp = Date.now().toString(36);
267
+ const random = Math.random().toString(36).substring(2, 8);
268
+ return `${prefix}-${timestamp}-${random}`;
90
269
  }
270
+ /**
271
+ * 获取 MIME 类型对应的文件扩展名
272
+ */
91
273
  function getExtensionFromMimeType(mimeType) {
92
- const map = {
93
- "image/png": "png",
94
- "image/jpeg": "jpg",
95
- "image/gif": "gif",
96
- "image/webp": "webp"
97
- };
98
- return map[mimeType] || "bin";
274
+ const map = {
275
+ "image/png": "png",
276
+ "image/jpeg": "jpg",
277
+ "image/gif": "gif",
278
+ "image/webp": "webp",
279
+ };
280
+ return map[mimeType] || "bin";
99
281
  }
282
+ // ========== 文件加载器类(复用代码) ==========
283
+ /**
284
+ * 统一的资源加载器
285
+ * 支持本地文件、网络 URL、Data URL
286
+ */
100
287
  class ResourceLoader {
101
- constructor(maxSize) {
102
- __publicField(this, "maxSize");
103
- this.maxSize = maxSize;
104
- }
105
- /**
106
- * 加载资源
107
- */
108
- async load(source) {
109
- if (source.startsWith("data:")) {
110
- return this.loadFromDataUrl(source);
111
- }
112
- if (source.startsWith("http://") || source.startsWith("https://")) {
113
- return this.loadFromNetwork(source);
114
- }
115
- return this.loadFromFile(source);
116
- }
117
- /**
118
- * 从 Data URL 加载
119
- */
120
- loadFromDataUrl(dataUrl) {
121
- const match = dataUrl.match(/^data:image\/(\w+);base64,(.+)$/);
122
- if (!match) {
123
- throw new WipValidationError(
124
- `Invalid data URL format: ${dataUrl.substring(0, 50)}...`
125
- );
126
- }
127
- const base64Data = match[2];
128
- try {
129
- return base64ToUint8Array(base64Data);
130
- } catch (error) {
131
- throw new WipError(`Failed to decode data URL: ${error}`);
132
- }
133
- }
134
- /**
135
- * 从网络加载
136
- */
137
- async loadFromNetwork(url) {
138
- try {
139
- const controller = new AbortController();
140
- const timeoutId = setTimeout(() => controller.abort(), 3e4);
141
- const response = await fetch(url, {
142
- signal: controller.signal,
143
- headers: {
144
- Accept: "image/png,image/jpeg,image/gif,image/webp,image/*"
145
- }
146
- });
147
- clearTimeout(timeoutId);
148
- if (!response.ok) {
149
- throw new WipError(
150
- `Failed to fetch: ${response.status} ${response.statusText}`
151
- );
152
- }
153
- const contentLength = response.headers.get("content-length");
154
- if (contentLength && parseInt(contentLength) > this.maxSize) {
155
- throw new WipSizeError(
156
- `Resource from ${url} size (${contentLength} bytes) exceeds limit (${this.maxSize} bytes)`
157
- );
158
- }
159
- const arrayBuffer = await response.arrayBuffer();
160
- if (arrayBuffer.byteLength > this.maxSize) {
161
- throw new WipSizeError(
162
- `Resource from ${url} size (${arrayBuffer.byteLength} bytes) exceeds limit (${this.maxSize} bytes)`
163
- );
164
- }
165
- return new Uint8Array(arrayBuffer);
166
- } catch (error) {
167
- if (error instanceof WipError) {
168
- throw error;
169
- }
170
- if (error instanceof Error) {
171
- if (error.name === "AbortError") {
172
- throw new WipError(
173
- `Network timeout while fetching: ${url}`
174
- );
175
- }
176
- throw new WipError(`Network error: ${error.message}`);
177
- }
178
- throw error;
179
- }
180
- }
181
- /**
182
- * 从本地文件加载
183
- */
184
- loadFromFile(filePath) {
185
- const resolvedPath = path.resolve(filePath);
186
- if (!fs.existsSync(resolvedPath)) {
187
- throw new WipError(`File not found: ${resolvedPath}`);
188
- }
189
- const stats = fs.statSync(resolvedPath);
190
- if (!stats.isFile()) {
191
- throw new WipError(`Path is not a file: ${resolvedPath}`);
192
- }
193
- if (stats.size > this.maxSize) {
194
- throw new WipSizeError(
195
- `File ${resolvedPath} size (${stats.size} bytes) exceeds limit (${this.maxSize} bytes)`
196
- );
197
- }
198
- const buffer = fs.readFileSync(resolvedPath);
199
- return new Uint8Array(buffer);
200
- }
288
+ maxSize;
289
+ constructor(maxSize) {
290
+ this.maxSize = maxSize;
291
+ }
292
+ /**
293
+ * 加载资源
294
+ */
295
+ async load(source) {
296
+ // 处理 Data URL
297
+ if (source.startsWith("data:")) {
298
+ return this.loadFromDataUrl(source);
299
+ }
300
+ // 处理 HTTP/HTTPS 网络 URL
301
+ if (source.startsWith("http://") || source.startsWith("https://")) {
302
+ return this.loadFromNetwork(source);
303
+ }
304
+ // 处理本地文件
305
+ return this.loadFromFile(source);
306
+ }
307
+ /**
308
+ * Data URL 加载
309
+ */
310
+ loadFromDataUrl(dataUrl) {
311
+ const match = dataUrl.match(/^data:image\/(\w+);base64,(.+)$/);
312
+ if (!match) {
313
+ throw new WipValidationError(`Invalid data URL format: ${dataUrl.substring(0, 50)}...`);
314
+ }
315
+ const base64Data = match[2];
316
+ try {
317
+ return base64ToUint8Array(base64Data);
318
+ }
319
+ catch (error) {
320
+ throw new WipError(`Failed to decode data URL: ${error}`);
321
+ }
322
+ }
323
+ /**
324
+ * 从网络加载
325
+ */
326
+ async loadFromNetwork(url) {
327
+ try {
328
+ // 使用 AbortController 实现超时控制
329
+ const controller = new AbortController();
330
+ const timeoutId = setTimeout(() => controller.abort(), 30000);
331
+ const response = await fetch(url, {
332
+ signal: controller.signal,
333
+ headers: {
334
+ Accept: "image/png,image/jpeg,image/gif,image/webp,image/*",
335
+ },
336
+ });
337
+ clearTimeout(timeoutId);
338
+ if (!response.ok) {
339
+ throw new WipError(`Failed to fetch: ${response.status} ${response.statusText}`);
340
+ }
341
+ // 检查 Content-Length
342
+ const contentLength = response.headers.get("content-length");
343
+ if (contentLength && parseInt(contentLength) > this.maxSize) {
344
+ throw new WipSizeError(`Resource from ${url} size (${contentLength} bytes) exceeds limit (${this.maxSize} bytes)`);
345
+ }
346
+ const arrayBuffer = await response.arrayBuffer();
347
+ if (arrayBuffer.byteLength > this.maxSize) {
348
+ throw new WipSizeError(`Resource from ${url} size (${arrayBuffer.byteLength} bytes) exceeds limit (${this.maxSize} bytes)`);
349
+ }
350
+ return new Uint8Array(arrayBuffer);
351
+ }
352
+ catch (error) {
353
+ if (error instanceof WipError) {
354
+ throw error;
355
+ }
356
+ if (error instanceof Error) {
357
+ if (error.name === "AbortError") {
358
+ throw new WipError(`Network timeout while fetching: ${url}`);
359
+ }
360
+ throw new WipError(`Network error: ${error.message}`);
361
+ }
362
+ throw error;
363
+ }
364
+ }
365
+ /**
366
+ * 从本地文件加载
367
+ */
368
+ loadFromFile(filePath) {
369
+ const resolvedPath = path.resolve(filePath);
370
+ if (!fs.existsSync(resolvedPath)) {
371
+ throw new WipError(`File not found: ${resolvedPath}`);
372
+ }
373
+ const stats = fs.statSync(resolvedPath);
374
+ if (!stats.isFile()) {
375
+ throw new WipError(`Path is not a file: ${resolvedPath}`);
376
+ }
377
+ if (stats.size > this.maxSize) {
378
+ throw new WipSizeError(`File ${resolvedPath} size (${stats.size} bytes) exceeds limit (${this.maxSize} bytes)`);
379
+ }
380
+ const buffer = fs.readFileSync(resolvedPath);
381
+ return new Uint8Array(buffer);
382
+ }
201
383
  }
202
- class WIP {
203
- constructor(limits = {}) {
204
- __publicField(this, "limits");
205
- __publicField(this, "resourceLoader");
206
- this.limits = { ...DEFAULT_LIMITS, ...limits };
207
- this.resourceLoader = new ResourceLoader(this.limits.maxImageSize);
208
- }
209
- /**
210
- * 创建 WIP 文件
211
- */
212
- async create(options) {
213
- if (options.text.length > this.limits.maxTextLength) {
214
- throw new WipSizeError(
215
- `Text length (${options.text.length}) exceeds limit (${this.limits.maxTextLength})`
216
- );
217
- }
218
- const media = [];
219
- if (options.images && options.images.length > 0) {
220
- if (options.images.length > this.limits.maxImageCount) {
221
- throw new WipSizeError(
222
- `Image count (${options.images.length}) exceeds limit (${this.limits.maxImageCount})`
223
- );
224
- }
225
- for (let i = 0; i < options.images.length; i++) {
226
- const wipMedia = await this.processImage(options.images[i], i);
227
- media.push(wipMedia);
228
- }
229
- }
230
- const payload = {
231
- content: {
232
- text: options.text,
233
- format: options.textFormat || "plain"
234
- },
235
- media
236
- };
237
- const canonicalPayload = canonicalizeJson(payload);
238
- const hash = computeHash(canonicalPayload);
239
- const meta = {
240
- type: "wip",
241
- version: WIP_VERSION,
242
- created: (/* @__PURE__ */ new Date()).toISOString(),
243
- hash,
244
- algorithm: "sha256"
245
- };
246
- if (options.signKeyPair) {
247
- const signatureValue = await this.sign(
248
- hash,
249
- options.signKeyPair.privateKey,
250
- options.signAlgorithm || "Ed25519"
251
- );
252
- meta.signature = {
253
- value: signatureValue,
254
- publicKey: options.signKeyPair.publicKey,
255
- algorithm: options.signAlgorithm || "Ed25519"
256
- };
257
- }
258
- const wipFile = {
259
- wip: WIP_SCHEMA_URL,
260
- payload,
261
- meta
262
- };
263
- const jsonString = JSON.stringify(wipFile);
264
- if (jsonString.length > this.limits.maxTotalSize) {
265
- throw new WipSizeError(
266
- `Total WIP file size (${jsonString.length} bytes) exceeds limit (${this.limits.maxTotalSize} bytes)`
267
- );
268
- }
269
- return wipFile;
270
- }
271
- /**
272
- * 处理图片源
273
- */
274
- async processImage(source, index) {
275
- const data = await this.resourceLoader.load(source.source);
276
- const mimeType = detectMimeType(data);
277
- if (!mimeType) {
278
- throw new WipValidationError(
279
- `Unsupported image format: ${source.source}`
280
- );
281
- }
282
- let filename = source.filename;
283
- if (!filename) {
284
- if (source.source.startsWith("http")) {
285
- const url = new URL(source.source);
286
- const pathname = url.pathname;
287
- filename = pathname.substring(pathname.lastIndexOf("/") + 1) || `image-${index}`;
288
- } else {
289
- filename = source.source.substring(
290
- source.source.lastIndexOf("/") + 1
291
- ) || `image-${index}`;
292
- }
384
+ // ========== WIP 类 ==========
385
+ export class WIP {
386
+ limits;
387
+ resourceLoader;
388
+ constructor(limits = {}) {
389
+ this.limits = { ...DEFAULT_LIMITS, ...limits };
390
+ this.resourceLoader = new ResourceLoader(this.limits.maxImageSize);
293
391
  }
294
- return {
295
- id: source.id || generateId("img"),
296
- type: mimeType,
297
- data: uint8ArrayToBase64(data),
298
- filename
299
- };
300
- }
301
- /**
302
- * 签名(真实实现)
303
- */
304
- async sign(data, privateKey, algorithm) {
305
- if (algorithm !== "Ed25519") {
306
- throw new WipError(`Unsupported signature algorithm: ${algorithm}`);
307
- }
308
- const { Ed25519Keypair } = await import("../../keypairs/ed25519/index.js");
309
- const keypair = Ed25519Keypair.fromSecretKey(privateKey);
310
- const signature = await keypair.sign(new TextEncoder().encode(data));
311
- return uint8ArrayToBase64(signature);
312
- }
313
- /**
314
- * 验证 WIP 文件
315
- */
316
- async verify(wipFile) {
317
- try {
318
- if (!wipFile.wip || !wipFile.payload || !wipFile.meta) {
319
- return { valid: false, error: "Invalid WIP file structure" };
320
- }
321
- if (wipFile.meta.type !== "wip") {
322
- return {
323
- valid: false,
324
- error: `Invalid meta.type: ${wipFile.meta.type}`
392
+ /**
393
+ * 创建 WIP 文件
394
+ */
395
+ async create(options) {
396
+ // 验证文字长度
397
+ if (options.text.length > this.limits.maxTextLength) {
398
+ throw new WipSizeError(`Text length (${options.text.length}) exceeds limit (${this.limits.maxTextLength})`);
399
+ }
400
+ // 处理图片
401
+ const media = [];
402
+ if (options.images && options.images.length > 0) {
403
+ if (options.images.length > this.limits.maxImageCount) {
404
+ throw new WipSizeError(`Image count (${options.images.length}) exceeds limit (${this.limits.maxImageCount})`);
405
+ }
406
+ for (let i = 0; i < options.images.length; i++) {
407
+ const wipMedia = await this.processImage(options.images[i], i);
408
+ media.push(wipMedia);
409
+ }
410
+ }
411
+ // 构建 payload
412
+ const payload = {
413
+ content: {
414
+ text: options.text,
415
+ format: options.textFormat || "plain",
416
+ },
417
+ media,
325
418
  };
326
- }
327
- const canonicalPayload = canonicalizeJson(wipFile.payload);
328
- const computedHash = computeHash(canonicalPayload);
329
- if (computedHash !== wipFile.meta.hash) {
330
- return {
331
- valid: false,
332
- error: "Hash mismatch - content has been tampered"
419
+ // 计算哈希
420
+ const canonicalPayload = canonicalizeJson(payload);
421
+ const hash = computeHash(canonicalPayload);
422
+ // 构建 meta
423
+ const meta = {
424
+ type: "wip",
425
+ version: WIP_VERSION,
426
+ created: new Date().toISOString(),
427
+ hash,
428
+ algorithm: "sha256",
333
429
  };
334
- }
335
- const signatures = [];
336
- if (wipFile.meta.signature) {
337
- const sigArray = Array.isArray(wipFile.meta.signature) ? wipFile.meta.signature : [wipFile.meta.signature];
338
- for (const sig of sigArray) {
339
- const signValid = await this.verifySignature(
340
- wipFile.meta.hash,
341
- sig.value,
342
- sig.publicKey,
343
- sig.algorithm
344
- );
345
- signatures.push({
346
- address: sig.address,
347
- valid: signValid
348
- });
349
- if (!signValid) {
350
- return {
351
- valid: false,
352
- error: "Invalid signature",
353
- signatures
430
+ // 添加签名
431
+ if (options.signKeyPair) {
432
+ const signatureValue = await this.sign(hash, options.signKeyPair.privateKey, options.signAlgorithm || "Ed25519");
433
+ meta.signature = {
434
+ value: signatureValue,
435
+ publicKey: options.signKeyPair.publicKey,
436
+ algorithm: options.signAlgorithm || "Ed25519",
354
437
  };
355
- }
356
438
  }
357
- }
358
- return { valid: true, signatures };
359
- } catch (error) {
360
- return { valid: false, error: `Verification error: ${error}` };
439
+ const wipFile = {
440
+ wip: WIP_SCHEMA_URL,
441
+ payload,
442
+ meta,
443
+ };
444
+ // 验证总大小
445
+ const jsonString = JSON.stringify(wipFile);
446
+ if (jsonString.length > this.limits.maxTotalSize) {
447
+ throw new WipSizeError(`Total WIP file size (${jsonString.length} bytes) exceeds limit (${this.limits.maxTotalSize} bytes)`);
448
+ }
449
+ return wipFile;
361
450
  }
362
- }
363
- /**
364
- * 验证签名
365
- */
366
- async verifySignature(data, signature, publicKey, algorithm) {
367
- if (algorithm !== "Ed25519") {
368
- throw new WipError(`Unsupported signature algorithm: ${algorithm}`);
451
+ /**
452
+ * 处理图片源
453
+ */
454
+ async processImage(source, index) {
455
+ const data = await this.resourceLoader.load(source.source);
456
+ const mimeType = detectMimeType(data);
457
+ if (!mimeType) {
458
+ throw new WipValidationError(`Unsupported image format: ${source.source}`);
459
+ }
460
+ let filename = source.filename;
461
+ if (!filename) {
462
+ if (source.source.startsWith("http")) {
463
+ const url = new URL(source.source);
464
+ const pathname = url.pathname;
465
+ filename =
466
+ pathname.substring(pathname.lastIndexOf("/") + 1) ||
467
+ `image-${index}`;
468
+ }
469
+ else {
470
+ filename =
471
+ source.source.substring(source.source.lastIndexOf("/") + 1) || `image-${index}`;
472
+ }
473
+ }
474
+ return {
475
+ id: source.id || generateId("img"),
476
+ type: mimeType,
477
+ data: uint8ArrayToBase64(data),
478
+ filename,
479
+ };
369
480
  }
370
- try {
371
- const { Ed25519PublicKey } = await import("../../keypairs/ed25519/publickey.js");
372
- let pkToUse = publicKey;
373
- if (publicKey.startsWith("0x")) {
374
- const buffer = Buffer.from(publicKey.slice(2), "hex");
375
- if (buffer.length === 33) {
376
- pkToUse = buffer.slice(1).toString("base64");
377
- } else if (buffer.length === 32) {
378
- pkToUse = buffer.toString("base64");
481
+ /**
482
+ * 签名(真实实现)
483
+ */
484
+ async sign(data, privateKey, algorithm) {
485
+ if (algorithm !== "Ed25519") {
486
+ throw new WipError(`Unsupported signature algorithm: ${algorithm}`);
379
487
  }
380
- } else {
488
+ const { Ed25519Keypair } = await import("../../keypairs/ed25519/index.js");
489
+ const keypair = Ed25519Keypair.fromSecretKey(privateKey);
490
+ const signature = await keypair.sign(new TextEncoder().encode(data));
491
+ return uint8ArrayToBase64(signature);
492
+ }
493
+ /**
494
+ * 验证 WIP 文件
495
+ */
496
+ async verify(wipFile) {
381
497
  try {
382
- const buffer = Buffer.from(publicKey, "base64");
383
- if (buffer.length === 33) {
384
- pkToUse = buffer.slice(1).toString("base64");
385
- }
386
- } catch {
387
- }
388
- }
389
- const pubKey = new Ed25519PublicKey(pkToUse);
390
- const signatureBytes = Uint8Array.from(
391
- Buffer.from(signature, "base64")
392
- );
393
- return await pubKey.verify(
394
- new TextEncoder().encode(data),
395
- signatureBytes
396
- );
397
- } catch (error) {
398
- console.error("Signature verification error:", error);
399
- return false;
400
- }
401
- }
402
- /**
403
- * 转换为 HTML
404
- */
405
- async toHtml(wipFile, options = {}) {
406
- const { title = "WIP Document", theme = "light" } = options;
407
- const { payload, meta } = wipFile;
408
- const escapeHtml = (text) => {
409
- return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
410
- };
411
- const formatText = (text, format) => {
412
- switch (format) {
413
- case "html":
414
- return text;
415
- case "markdown":
416
- return text.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>").replace(/\*(.+?)\*/g, "<em>$1</em>").replace(/\n/g, "<br>");
417
- case "plain":
418
- default:
419
- return escapeHtml(text).replace(/\n/g, "<br>");
420
- }
421
- };
422
- const bgColor = theme === "dark" ? "#1a1a1a" : "#ffffff";
423
- const textColor = theme === "dark" ? "#e0e0e0" : "#333333";
424
- const borderColor = theme === "dark" ? "#444444" : "#e0e0e0";
425
- const verifiedColor = "#4caf50";
426
- const warningColor = "#ff9800";
427
- const verifyResult = await this.verify(wipFile);
428
- const statusBadge = verifyResult.valid ? `<span style="background: ${verifiedColor}; color: white; padding: 4px 8px; border-radius: 4px; font-size: 12px;">\u2713 Verified</span>` : `<span style="background: ${warningColor}; color: white; padding: 4px 8px; border-radius: 4px; font-size: 12px;">\u26A0 Tampered</span>`;
429
- const imagesHtml = payload.media.map(
430
- (media) => `
498
+ if (!wipFile.wip || !wipFile.payload || !wipFile.meta) {
499
+ return { valid: false, error: "Invalid WIP file structure" };
500
+ }
501
+ if (wipFile.meta.type !== "wip") {
502
+ return {
503
+ valid: false,
504
+ error: `Invalid meta.type: ${wipFile.meta.type}`,
505
+ };
506
+ }
507
+ const canonicalPayload = canonicalizeJson(wipFile.payload);
508
+ const computedHash = computeHash(canonicalPayload);
509
+ if (computedHash !== wipFile.meta.hash) {
510
+ return {
511
+ valid: false,
512
+ error: "Hash mismatch - content has been tampered",
513
+ };
514
+ }
515
+ const signatures = [];
516
+ if (wipFile.meta.signature) {
517
+ // 支持多签名验证
518
+ const sigArray = Array.isArray(wipFile.meta.signature)
519
+ ? wipFile.meta.signature
520
+ : [wipFile.meta.signature];
521
+ for (const sig of sigArray) {
522
+ const signValid = await this.verifySignature(wipFile.meta.hash, sig.value, sig.publicKey, sig.algorithm);
523
+ signatures.push({
524
+ address: sig.address,
525
+ valid: signValid,
526
+ });
527
+ if (!signValid) {
528
+ return {
529
+ valid: false,
530
+ error: "Invalid signature",
531
+ signatures,
532
+ };
533
+ }
534
+ }
535
+ }
536
+ return { valid: true, signatures };
537
+ }
538
+ catch (error) {
539
+ return { valid: false, error: `Verification error: ${error}` };
540
+ }
541
+ }
542
+ /**
543
+ * 验证签名
544
+ */
545
+ async verifySignature(data, signature, publicKey, algorithm) {
546
+ if (algorithm !== "Ed25519") {
547
+ throw new WipError(`Unsupported signature algorithm: ${algorithm}`);
548
+ }
549
+ try {
550
+ const { Ed25519PublicKey } = await import("../../keypairs/ed25519/publickey.js");
551
+ let pkToUse = publicKey;
552
+ if (publicKey.startsWith("0x")) {
553
+ const buffer = Buffer.from(publicKey.slice(2), "hex");
554
+ if (buffer.length === 33) {
555
+ pkToUse = buffer.slice(1).toString("base64");
556
+ }
557
+ else if (buffer.length === 32) {
558
+ pkToUse = buffer.toString("base64");
559
+ }
560
+ }
561
+ else {
562
+ // 处理 base64 公钥(可能是 33 字节带 flag 或 32 字节原始公钥)
563
+ try {
564
+ const buffer = Buffer.from(publicKey, "base64");
565
+ if (buffer.length === 33) {
566
+ // 33 字节:包含 flag,取后 32 字节
567
+ pkToUse = buffer.slice(1).toString("base64");
568
+ }
569
+ // 32 字节:直接使用
570
+ }
571
+ catch {
572
+ // 解码失败,使用原始值
573
+ }
574
+ }
575
+ const pubKey = new Ed25519PublicKey(pkToUse);
576
+ const signatureBytes = Uint8Array.from(Buffer.from(signature, "base64"));
577
+ return await pubKey.verify(new TextEncoder().encode(data), signatureBytes);
578
+ }
579
+ catch (error) {
580
+ console.error("Signature verification error:", error);
581
+ return false;
582
+ }
583
+ }
584
+ /**
585
+ * 转换为 HTML
586
+ */
587
+ async toHtml(wipFile, options = {}) {
588
+ const { title = "WIP Document", theme = "light" } = options;
589
+ const { payload, meta } = wipFile;
590
+ const escapeHtml = (text) => {
591
+ return text
592
+ .replace(/&/g, "&amp;")
593
+ .replace(/</g, "&lt;")
594
+ .replace(/>/g, "&gt;")
595
+ .replace(/"/g, "&quot;")
596
+ .replace(/'/g, "&#039;");
597
+ };
598
+ const formatText = (text, format) => {
599
+ switch (format) {
600
+ case "html":
601
+ return text;
602
+ case "markdown":
603
+ return text
604
+ .replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>")
605
+ .replace(/\*(.+?)\*/g, "<em>$1</em>")
606
+ .replace(/\n/g, "<br>");
607
+ case "plain":
608
+ default:
609
+ return escapeHtml(text).replace(/\n/g, "<br>");
610
+ }
611
+ };
612
+ const bgColor = theme === "dark" ? "#1a1a1a" : "#ffffff";
613
+ const textColor = theme === "dark" ? "#e0e0e0" : "#333333";
614
+ const borderColor = theme === "dark" ? "#444444" : "#e0e0e0";
615
+ const verifiedColor = "#4caf50";
616
+ const warningColor = "#ff9800";
617
+ const verifyResult = await this.verify(wipFile);
618
+ const statusBadge = verifyResult.valid
619
+ ? `<span style="background: ${verifiedColor}; color: white; padding: 4px 8px; border-radius: 4px; font-size: 12px;">✓ Verified</span>`
620
+ : `<span style="background: ${warningColor}; color: white; padding: 4px 8px; border-radius: 4px; font-size: 12px;">⚠ Tampered</span>`;
621
+ const imagesHtml = payload.media
622
+ .map((media) => `
431
623
  <div style="margin: 16px 0; border: 1px solid ${borderColor}; border-radius: 8px; overflow: hidden;">
432
624
  <img src="data:${media.type};base64,${media.data}"
433
625
  style="max-width: 100%; height: auto; display: block;"
434
626
  alt="${escapeHtml(media.filename || media.id)}" />
435
627
  ${media.filename ? `<div style="padding: 8px; font-size: 12px; color: #666; background: ${theme === "dark" ? "#2a2a2a" : "#f5f5f5"}; border-top: 1px solid ${borderColor};">${escapeHtml(media.filename)}</div>` : ""}
436
628
  </div>
437
- `
438
- ).join("");
439
- return `<!DOCTYPE html>
629
+ `)
630
+ .join("");
631
+ // 签名详情不在 HTML 中显示,只显示验证结果
632
+ return `<!DOCTYPE html>
440
633
  <html lang="en">
441
634
  <head>
442
635
  <meta charset="UTF-8">
@@ -450,7 +643,7 @@ class WIP {
450
643
  <div>
451
644
  <h1 style="margin: 0; font-size: 20px; font-weight: 600;">${escapeHtml(title)}</h1>
452
645
  <div style="font-size: 12px; color: #666; margin-top: 4px;">
453
- WIP v${meta.version} \u2022 ${new Date(meta.created).toLocaleString()}
646
+ WIP v${meta.version} ${new Date(meta.created).toLocaleString()}
454
647
  </div>
455
648
  </div>
456
649
  ${statusBadge}
@@ -458,18 +651,20 @@ class WIP {
458
651
  <div style="font-size: 11px; color: #999; margin-top: 12px; padding: 8px; background: ${theme === "dark" ? "#2a2a2a" : "#f5f5f5"}; border-radius: 4px; font-style: italic;">
459
652
  Important Note: This page is for document browsing and verification reference only. Please verify the document integrity through the API using the WIP file.
460
653
  </div>
461
- ${verifyResult.signatures && verifyResult.signatures.length > 0 ? `
654
+ ${verifyResult.signatures && verifyResult.signatures.length > 0
655
+ ? `
462
656
  <div style="margin-top: 12px; padding: 8px; background: ${theme === "dark" ? "#2a3f2a" : "#e8f5e9"}; border-radius: 4px;">
463
- <div style="font-size: 11px; color: ${theme === "dark" ? "#81c784" : "#2e7d32"}; margin-bottom: 4px;">\u2713 Signature Verification (${verifyResult.signatures.length} signature${verifyResult.signatures.length > 1 ? "s" : ""})</div>
464
- ${verifyResult.signatures.map(
465
- (s, idx) => `
657
+ <div style="font-size: 11px; color: ${theme === "dark" ? "#81c784" : "#2e7d32"}; margin-bottom: 4px;">✓ Signature Verification (${verifyResult.signatures.length} signature${verifyResult.signatures.length > 1 ? "s" : ""})</div>
658
+ ${verifyResult.signatures
659
+ .map((s, idx) => `
466
660
  <div style="font-size: 10px; color: ${textColor}; margin-left: 8px;">
467
- ${idx + 1}. ${s.address ? escapeHtml(s.address.slice(0, 20)) + "..." : "Unknown"}: ${s.valid ? '<span style="color: #4caf50;">\u2713 Valid</span>' : '<span style="color: #f44336;">\u2717 Invalid</span>'}
661
+ ${idx + 1}. ${s.address ? escapeHtml(s.address.slice(0, 20)) + "..." : "Unknown"}: ${s.valid ? '<span style="color: #4caf50;">✓ Valid</span>' : '<span style="color: #f44336;">✗ Invalid</span>'}
468
662
  </div>
469
- `
470
- ).join("")}
663
+ `)
664
+ .join("")}
471
665
  </div>
472
- ` : ""}
666
+ `
667
+ : ""}
473
668
  </div>
474
669
  <div style="padding: 24px;">
475
670
  <div style="font-size: 16px; line-height: 1.8; margin-bottom: 24px;">
@@ -490,393 +685,455 @@ class WIP {
490
685
  </div>
491
686
  </body>
492
687
  </html>`;
493
- }
494
- /**
495
- * 序列化为 JSON
496
- */
497
- stringify(wipFile, pretty = true) {
498
- return pretty ? JSON.stringify(wipFile, null, 2) : JSON.stringify(wipFile);
499
- }
500
- /**
501
- * 从 JSON 解析
502
- */
503
- parse(jsonString) {
504
- try {
505
- const obj = JSON.parse(jsonString);
506
- if (!obj.wip || !obj.payload || !obj.meta) {
507
- throw new WipValidationError("Invalid WIP file structure");
508
- }
509
- return obj;
510
- } catch (error) {
511
- if (error instanceof WipError) {
512
- throw error;
513
- }
514
- throw new WipValidationError(`Failed to parse WIP file: ${error}`);
515
- }
516
- }
517
- /**
518
- * 从 URL 或本地路径加载 WIP 文件
519
- */
520
- async load(source) {
521
- const data = await this.resourceLoader.load(source);
522
- const content = new TextDecoder().decode(data);
523
- return this.parse(content);
524
- }
525
- /**
526
- * 提取图片
527
- */
528
- extractImages(wipFile, outputDir) {
529
- if (!fs.existsSync(outputDir)) {
530
- fs.mkdirSync(outputDir, { recursive: true });
531
- }
532
- const savedPaths = [];
533
- for (const media of wipFile.payload.media) {
534
- const ext = getExtensionFromMimeType(media.type);
535
- const filename = media.filename || `${media.id}.${ext}`;
536
- const outputPath = path.join(outputDir, filename);
537
- const buffer = Buffer.from(base64ToUint8Array(media.data));
538
- fs.writeFileSync(outputPath, buffer);
539
- savedPaths.push(outputPath);
540
- }
541
- return savedPaths;
542
- }
543
- /**
544
- * 保存到文件
545
- */
546
- save(wipFile, filePath, pretty = true) {
547
- const dir = path.dirname(filePath);
548
- if (!fs.existsSync(dir)) {
549
- fs.mkdirSync(dir, { recursive: true });
550
- }
551
- fs.writeFileSync(filePath, this.stringify(wipFile, pretty), "utf-8");
552
- }
553
- /**
554
- * 获取限制配置
555
- */
556
- getLimits() {
557
- return { ...this.limits };
558
- }
559
- /**
560
- * 更新限制配置
561
- */
562
- setLimits(limits) {
563
- this.limits = { ...this.limits, ...limits };
564
- this.resourceLoader = new ResourceLoader(this.limits.maxImageSize);
565
- }
688
+ }
689
+ /**
690
+ * 序列化为 JSON
691
+ */
692
+ stringify(wipFile, pretty = true) {
693
+ return pretty
694
+ ? JSON.stringify(wipFile, null, 2)
695
+ : JSON.stringify(wipFile);
696
+ }
697
+ /**
698
+ * 从 JSON 解析
699
+ */
700
+ parse(jsonString) {
701
+ try {
702
+ const obj = JSON.parse(jsonString);
703
+ if (!obj.wip || !obj.payload || !obj.meta) {
704
+ throw new WipValidationError("Invalid WIP file structure");
705
+ }
706
+ return obj;
707
+ }
708
+ catch (error) {
709
+ if (error instanceof WipError) {
710
+ throw error;
711
+ }
712
+ throw new WipValidationError(`Failed to parse WIP file: ${error}`);
713
+ }
714
+ }
715
+ /**
716
+ * URL 或本地路径加载 WIP 文件
717
+ */
718
+ async load(source) {
719
+ const data = await this.resourceLoader.load(source);
720
+ const content = new TextDecoder().decode(data);
721
+ return this.parse(content);
722
+ }
723
+ /**
724
+ * 提取图片
725
+ */
726
+ extractImages(wipFile, outputDir) {
727
+ if (!fs.existsSync(outputDir)) {
728
+ fs.mkdirSync(outputDir, { recursive: true });
729
+ }
730
+ const savedPaths = [];
731
+ for (const media of wipFile.payload.media) {
732
+ const ext = getExtensionFromMimeType(media.type);
733
+ const filename = media.filename || `${media.id}.${ext}`;
734
+ const outputPath = path.join(outputDir, filename);
735
+ const buffer = Buffer.from(base64ToUint8Array(media.data));
736
+ fs.writeFileSync(outputPath, buffer);
737
+ savedPaths.push(outputPath);
738
+ }
739
+ return savedPaths;
740
+ }
741
+ /**
742
+ * 保存到文件
743
+ */
744
+ save(wipFile, filePath, pretty = true) {
745
+ const dir = path.dirname(filePath);
746
+ if (!fs.existsSync(dir)) {
747
+ fs.mkdirSync(dir, { recursive: true });
748
+ }
749
+ fs.writeFileSync(filePath, this.stringify(wipFile, pretty), "utf-8");
750
+ }
751
+ /**
752
+ * 获取限制配置
753
+ */
754
+ getLimits() {
755
+ return { ...this.limits };
756
+ }
757
+ /**
758
+ * 更新限制配置
759
+ */
760
+ setLimits(limits) {
761
+ this.limits = { ...this.limits, ...limits };
762
+ this.resourceLoader = new ResourceLoader(this.limits.maxImageSize);
763
+ }
566
764
  }
567
- async function createWip(options, limits) {
568
- const wip = new WIP(limits);
569
- return wip.create(options);
765
+ // ========== 便捷函数 ==========
766
+ export async function createWip(options, limits) {
767
+ const wip = new WIP(limits);
768
+ return wip.create(options);
570
769
  }
571
- async function verifyWip(wipFile, hash_equal) {
572
- if (hash_equal !== void 0 && wipFile.meta.hash.toLowerCase() !== hash_equal.toLowerCase()) {
573
- return { valid: false, error: "Hash mismatch" };
574
- }
575
- const wip = new WIP();
576
- return wip.verify(wipFile);
770
+ export async function verifyWip(wipFile, hash_equal) {
771
+ if (hash_equal !== undefined &&
772
+ wipFile.meta.hash.toLowerCase() !== hash_equal.toLowerCase()) {
773
+ return { valid: false, error: "Hash mismatch" };
774
+ }
775
+ const wip = new WIP();
776
+ return wip.verify(wipFile);
777
+ }
778
+ export async function wipToHtml(wipFile, options) {
779
+ const wip = new WIP();
780
+ return wip.toHtml(wipFile, options);
781
+ }
782
+ export async function loadWip(source, limits) {
783
+ const wip = new WIP(limits);
784
+ return wip.load(source);
577
785
  }
578
- async function wipToHtml(wipFile, options) {
579
- const wip = new WIP();
580
- return wip.toHtml(wipFile, options);
786
+ /**
787
+ * 生成 WIP 文件并保存到指定路径
788
+ *
789
+ * @param options 生成选项
790
+ * @param outputPath 输出文件路径
791
+ * @param limits 可选的限制配置
792
+ * @returns 生成的 WIP 文件路径
793
+ */
794
+ export async function generate_wip(options, outputPath) {
795
+ const wip = new WIP(DEFAULT_LIMITS);
796
+ // 1. 创建 WIP 文件(无签名)
797
+ let wipFile = await wip.create({
798
+ text: options.markdown_text,
799
+ textFormat: "markdown",
800
+ images: options.images,
801
+ });
802
+ // 2. 如果指定了 account,使用 Account 模块进行签名
803
+ if (options.account) {
804
+ const { Account } = await import("./account.js");
805
+ const address = await Account.Instance().get_address(options.account);
806
+ if (!address) {
807
+ throw new WipValidationError(`Account not found: ${options.account}`);
808
+ }
809
+ // 使用 Account 签名
810
+ const signature = await Account.Instance().sign(address, wipFile.meta.hash);
811
+ // 获取公钥
812
+ const accountData = await Account.Instance().get(address);
813
+ if (!accountData || !accountData.pubkey) {
814
+ throw new WipValidationError(`Cannot get public key for account: ${address}`);
815
+ }
816
+ // 转换公钥格式为 base64 (32字节)
817
+ let publicKeyBase64;
818
+ if (accountData.pubkey.startsWith("0x")) {
819
+ const buffer = Buffer.from(accountData.pubkey.slice(2), "hex");
820
+ if (buffer.length === 33) {
821
+ publicKeyBase64 = buffer.slice(1).toString("base64");
822
+ }
823
+ else if (buffer.length === 32) {
824
+ publicKeyBase64 = buffer.toString("base64");
825
+ }
826
+ else {
827
+ throw new WipValidationError(`Invalid public key length: ${buffer.length}, expected 32 or 33 bytes`);
828
+ }
829
+ }
830
+ else {
831
+ publicKeyBase64 = accountData.pubkey;
832
+ }
833
+ // 转换签名为 base64
834
+ const signatureBase64 = Buffer.from(signature.slice(2), "hex").toString("base64");
835
+ // 构建新签名
836
+ const newSignature = {
837
+ value: signatureBase64,
838
+ publicKey: publicKeyBase64,
839
+ algorithm: "Ed25519",
840
+ address,
841
+ };
842
+ // 处理多签名:如果已有签名,追加到数组中
843
+ let signatures;
844
+ if (wipFile.meta.signature) {
845
+ // 如果已有签名是数组,追加;如果是单个,转换为数组
846
+ signatures = Array.isArray(wipFile.meta.signature)
847
+ ? [...wipFile.meta.signature, newSignature]
848
+ : [wipFile.meta.signature, newSignature];
849
+ }
850
+ else {
851
+ signatures = [newSignature];
852
+ }
853
+ // 添加签名到 meta
854
+ wipFile = {
855
+ ...wipFile,
856
+ meta: {
857
+ ...wipFile.meta,
858
+ signature: signatures,
859
+ },
860
+ };
861
+ }
862
+ wip.save(wipFile, outputPath, true);
863
+ return outputPath;
581
864
  }
582
- async function loadWip(source, limits) {
583
- const wip = new WIP(limits);
584
- return wip.load(source);
865
+ /**
866
+ * 验证 WIP 文件
867
+ * 验证内容包括:
868
+ * 1. 基本结构验证
869
+ * 2. 哈希值验证(内容完整性)
870
+ * 3. 数字签名验证(如果存在)
871
+ *
872
+ * @param wipFilePath WIP 文件路径
873
+ * @returns 验证结果,包含哈希验证和签名验证状态
874
+ */
875
+ export async function verify_wip(wipFilePath, hash_equal) {
876
+ const wip = new WIP();
877
+ // 加载 WIP 文件
878
+ let wipFile;
879
+ try {
880
+ wipFile = await wip.load(wipFilePath);
881
+ }
882
+ catch (error) {
883
+ return {
884
+ valid: false,
885
+ error: `Failed to load WIP file: ${error}`,
886
+ hashValid: false,
887
+ hasSignature: false,
888
+ };
889
+ }
890
+ // 验证基本结构
891
+ if (!wipFile.wip || !wipFile.payload || !wipFile.meta) {
892
+ return {
893
+ valid: false,
894
+ error: "Invalid WIP file structure",
895
+ hashValid: false,
896
+ hasSignature: false,
897
+ };
898
+ }
899
+ if (wipFile.meta.type !== "wip") {
900
+ return {
901
+ valid: false,
902
+ error: `Invalid meta.type: ${wipFile.meta.type}`,
903
+ hashValid: false,
904
+ hasSignature: !!wipFile.meta.signature,
905
+ };
906
+ }
907
+ // 如果提供了 hash_equal,先验证文件 meta.hash 是否匹配
908
+ if (hash_equal !== undefined &&
909
+ wipFile.meta.hash.toLowerCase() !== hash_equal.toLowerCase()) {
910
+ return {
911
+ valid: false,
912
+ error: "Hash mismatch",
913
+ hashValid: false,
914
+ hasSignature: !!wipFile.meta.signature,
915
+ };
916
+ }
917
+ // 验证哈希
918
+ const canonicalPayload = canonicalizeJson(wipFile.payload);
919
+ const computedHash = computeHash(canonicalPayload);
920
+ const hashValid = computedHash === wipFile.meta.hash;
921
+ if (!hashValid) {
922
+ return {
923
+ valid: false,
924
+ error: "Hash mismatch - content has been tampered",
925
+ hashValid: false,
926
+ hasSignature: !!wipFile.meta.signature,
927
+ };
928
+ }
929
+ // 验证签名(如果存在)
930
+ let signatureValid;
931
+ const signatures = [];
932
+ if (wipFile.meta.signature) {
933
+ // 支持多签名验证
934
+ const sigArray = Array.isArray(wipFile.meta.signature)
935
+ ? wipFile.meta.signature
936
+ : [wipFile.meta.signature];
937
+ let allValid = true;
938
+ for (const sig of sigArray) {
939
+ const isValid = await wip["verifySignature"](wipFile.meta.hash, sig.value, sig.publicKey, sig.algorithm);
940
+ // 通过公钥推导地址
941
+ let address;
942
+ try {
943
+ const { Ed25519PublicKey } = await import("../../keypairs/ed25519/publickey.js");
944
+ const pubKey = new Ed25519PublicKey(sig.publicKey);
945
+ address = pubKey.toWAddress();
946
+ }
947
+ catch {
948
+ // 推导失败不影响验证结果
949
+ }
950
+ signatures.push({
951
+ publicKey: sig.publicKey,
952
+ address,
953
+ valid: isValid,
954
+ });
955
+ if (!isValid) {
956
+ allValid = false;
957
+ }
958
+ }
959
+ signatureValid = allValid;
960
+ if (!signatureValid) {
961
+ // 收集失败的地址
962
+ const failedAddresses = signatures
963
+ .filter((s) => !s.valid && s.address)
964
+ .map((s) => s.address);
965
+ return {
966
+ valid: false,
967
+ error: `Signatures from the following addresses are invalid: ${failedAddresses.join(", ")}`,
968
+ hashValid: true,
969
+ signatureValid: false,
970
+ hasSignature: true,
971
+ signatures,
972
+ };
973
+ }
974
+ }
975
+ return {
976
+ valid: true,
977
+ hashValid: true,
978
+ signatureValid,
979
+ hasSignature: !!wipFile.meta.signature,
980
+ signatures: signatures.length > 0 ? signatures : undefined,
981
+ };
585
982
  }
586
- async function generate_wip(options, outputPath) {
587
- const wip = new WIP(DEFAULT_LIMITS);
588
- let wipFile = await wip.create({
589
- text: options.markdown_text,
590
- textFormat: "markdown",
591
- images: options.images
592
- });
593
- if (options.account) {
983
+ /**
984
+ * WIP 文件进行签名
985
+ *
986
+ * 该函数会加载 WIP 文件、验证格式、使用 Account 添加数字签名并保存。
987
+ * 支持多签名,如果文件已有签名,新签名会追加到签名列表中。
988
+ *
989
+ * @param wipFilePath WIP 文件路径
990
+ * @param account 签名账号(账户名或地址)
991
+ * @param outputPath 输出文件路径(可选,默认覆盖原文件)
992
+ * @returns 签名后的 WIP 文件路径
993
+ */
994
+ export async function sign_wip(wipFilePath, account, outputPath) {
995
+ const wip = new WIP();
996
+ // 1. 加载 WIP 文件
997
+ const wipFile = await wip.load(wipFilePath);
998
+ // 2. 验证基本结构
999
+ if (!wipFile.wip || !wipFile.payload || !wipFile.meta) {
1000
+ throw new WipValidationError("Invalid WIP file structure");
1001
+ }
1002
+ if (wipFile.meta.type !== "wip") {
1003
+ throw new WipValidationError(`Invalid meta.type: ${wipFile.meta.type}`);
1004
+ }
1005
+ // 3. 获取签名者地址
594
1006
  const { Account } = await import("./account.js");
595
- const address = await Account.Instance().get_address(options.account);
1007
+ const address = await Account.Instance().get_address(account);
596
1008
  if (!address) {
597
- throw new WipValidationError(
598
- `Account not found: ${options.account}`
599
- );
600
- }
601
- const signature = await Account.Instance().sign(
602
- address,
603
- wipFile.meta.hash
604
- );
605
- const accountData = await Account.Instance().get(address);
606
- if (!accountData || !accountData.pubkey) {
607
- throw new WipValidationError(
608
- `Cannot get public key for account: ${address}`
609
- );
1009
+ throw new WipValidationError(`Account not found: ${account}`);
610
1010
  }
1011
+ // 4. 使用 Account 签名(同时获取公钥)
1012
+ const signResult = await Account.Instance().signData(address, wipFile.meta.hash);
1013
+ // 5. 转换公钥格式为 base64 (32字节)
611
1014
  let publicKeyBase64;
612
- if (accountData.pubkey.startsWith("0x")) {
613
- const buffer = Buffer.from(accountData.pubkey.slice(2), "hex");
614
- if (buffer.length === 33) {
615
- publicKeyBase64 = buffer.slice(1).toString("base64");
616
- } else if (buffer.length === 32) {
617
- publicKeyBase64 = buffer.toString("base64");
618
- } else {
619
- throw new WipValidationError(
620
- `Invalid public key length: ${buffer.length}, expected 32 or 33 bytes`
621
- );
622
- }
623
- } else {
624
- publicKeyBase64 = accountData.pubkey;
625
- }
626
- const signatureBase64 = Buffer.from(signature.slice(2), "hex").toString(
627
- "base64"
628
- );
1015
+ const pk = signResult.publicKey;
1016
+ if (pk.startsWith("0x")) {
1017
+ const buffer = Buffer.from(pk.slice(2), "hex");
1018
+ if (buffer.length === 33) {
1019
+ publicKeyBase64 = buffer.slice(1).toString("base64");
1020
+ }
1021
+ else if (buffer.length === 32) {
1022
+ publicKeyBase64 = buffer.toString("base64");
1023
+ }
1024
+ else {
1025
+ throw new WipValidationError(`Invalid public key length: ${buffer.length}, expected 32 or 33 bytes`);
1026
+ }
1027
+ }
1028
+ else {
1029
+ publicKeyBase64 = pk;
1030
+ }
1031
+ // 6. 构建新签名
629
1032
  const newSignature = {
630
- value: signatureBase64,
631
- publicKey: publicKeyBase64,
632
- algorithm: "Ed25519",
633
- address
1033
+ value: Buffer.from(signResult.signature.slice(2), "hex").toString("base64"),
1034
+ publicKey: publicKeyBase64,
1035
+ algorithm: "Ed25519",
1036
+ address: signResult.address,
634
1037
  };
1038
+ // 7. 处理多签名:相同公钥只能有一个签名(替换已有签名)
635
1039
  let signatures;
636
1040
  if (wipFile.meta.signature) {
637
- signatures = Array.isArray(wipFile.meta.signature) ? [...wipFile.meta.signature, newSignature] : [wipFile.meta.signature, newSignature];
638
- } else {
639
- signatures = [newSignature];
640
- }
641
- wipFile = {
642
- ...wipFile,
643
- meta: {
644
- ...wipFile.meta,
645
- signature: signatures
646
- }
647
- };
648
- }
649
- wip.save(wipFile, outputPath, true);
650
- return outputPath;
651
- }
652
- async function verify_wip(wipFilePath, hash_equal) {
653
- const wip = new WIP();
654
- let wipFile;
655
- try {
656
- wipFile = await wip.load(wipFilePath);
657
- } catch (error) {
658
- return {
659
- valid: false,
660
- error: `Failed to load WIP file: ${error}`,
661
- hashValid: false,
662
- hasSignature: false
663
- };
664
- }
665
- if (!wipFile.wip || !wipFile.payload || !wipFile.meta) {
666
- return {
667
- valid: false,
668
- error: "Invalid WIP file structure",
669
- hashValid: false,
670
- hasSignature: false
671
- };
672
- }
673
- if (wipFile.meta.type !== "wip") {
674
- return {
675
- valid: false,
676
- error: `Invalid meta.type: ${wipFile.meta.type}`,
677
- hashValid: false,
678
- hasSignature: !!wipFile.meta.signature
679
- };
680
- }
681
- if (hash_equal !== void 0 && wipFile.meta.hash.toLowerCase() !== hash_equal.toLowerCase()) {
682
- return {
683
- valid: false,
684
- error: "Hash mismatch",
685
- hashValid: false,
686
- hasSignature: !!wipFile.meta.signature
687
- };
688
- }
689
- const canonicalPayload = canonicalizeJson(wipFile.payload);
690
- const computedHash = computeHash(canonicalPayload);
691
- const hashValid = computedHash === wipFile.meta.hash;
692
- if (!hashValid) {
693
- return {
694
- valid: false,
695
- error: "Hash mismatch - content has been tampered",
696
- hashValid: false,
697
- hasSignature: !!wipFile.meta.signature
1041
+ // 将已有签名转换为数组
1042
+ const existingSigs = Array.isArray(wipFile.meta.signature)
1043
+ ? [...wipFile.meta.signature]
1044
+ : [wipFile.meta.signature];
1045
+ // 检查是否已存在相同公钥的签名
1046
+ const existingIndex = existingSigs.findIndex((sig) => sig.publicKey === publicKeyBase64);
1047
+ if (existingIndex >= 0) {
1048
+ // 替换已有签名
1049
+ existingSigs[existingIndex] = newSignature;
1050
+ signatures = existingSigs;
1051
+ }
1052
+ else {
1053
+ // 追加新签名
1054
+ signatures = [...existingSigs, newSignature];
1055
+ }
1056
+ }
1057
+ else {
1058
+ signatures = [newSignature];
1059
+ }
1060
+ // 8. 添加签名到 meta
1061
+ const signedWipFile = {
1062
+ ...wipFile,
1063
+ meta: {
1064
+ ...wipFile.meta,
1065
+ signature: signatures,
1066
+ },
698
1067
  };
699
- }
700
- let signatureValid;
701
- const signatures = [];
702
- if (wipFile.meta.signature) {
703
- const sigArray = Array.isArray(wipFile.meta.signature) ? wipFile.meta.signature : [wipFile.meta.signature];
704
- let allValid = true;
705
- for (const sig of sigArray) {
706
- const isValid = await wip["verifySignature"](
707
- wipFile.meta.hash,
708
- sig.value,
709
- sig.publicKey,
710
- sig.algorithm
711
- );
712
- let address;
713
- try {
714
- const { Ed25519PublicKey } = await import("../../keypairs/ed25519/publickey.js");
715
- const pubKey = new Ed25519PublicKey(sig.publicKey);
716
- address = pubKey.toWAddress();
717
- } catch {
718
- }
719
- signatures.push({
720
- publicKey: sig.publicKey,
721
- address,
722
- valid: isValid
723
- });
724
- if (!isValid) {
725
- allValid = false;
726
- }
727
- }
728
- signatureValid = allValid;
729
- if (!signatureValid) {
730
- const failedAddresses = signatures.filter((s) => !s.valid && s.address).map((s) => s.address);
731
- return {
732
- valid: false,
733
- error: `Signatures from the following addresses are invalid: ${failedAddresses.join(", ")}`,
734
- hashValid: true,
735
- signatureValid: false,
736
- hasSignature: true,
737
- signatures
738
- };
739
- }
740
- }
741
- return {
742
- valid: true,
743
- hashValid: true,
744
- signatureValid,
745
- hasSignature: !!wipFile.meta.signature,
746
- signatures: signatures.length > 0 ? signatures : void 0
747
- };
748
- }
749
- async function sign_wip(wipFilePath, account, outputPath) {
750
- const wip = new WIP();
751
- const wipFile = await wip.load(wipFilePath);
752
- if (!wipFile.wip || !wipFile.payload || !wipFile.meta) {
753
- throw new WipValidationError("Invalid WIP file structure");
754
- }
755
- if (wipFile.meta.type !== "wip") {
756
- throw new WipValidationError(`Invalid meta.type: ${wipFile.meta.type}`);
757
- }
758
- const { Account } = await import("./account.js");
759
- const address = await Account.Instance().get_address(account);
760
- if (!address) {
761
- throw new WipValidationError(`Account not found: ${account}`);
762
- }
763
- const signResult = await Account.Instance().signData(
764
- address,
765
- wipFile.meta.hash
766
- );
767
- let publicKeyBase64;
768
- const pk = signResult.publicKey;
769
- if (pk.startsWith("0x")) {
770
- const buffer = Buffer.from(pk.slice(2), "hex");
771
- if (buffer.length === 33) {
772
- publicKeyBase64 = buffer.slice(1).toString("base64");
773
- } else if (buffer.length === 32) {
774
- publicKeyBase64 = buffer.toString("base64");
775
- } else {
776
- throw new WipValidationError(
777
- `Invalid public key length: ${buffer.length}, expected 32 or 33 bytes`
778
- );
779
- }
780
- } else {
781
- publicKeyBase64 = pk;
782
- }
783
- const newSignature = {
784
- value: Buffer.from(signResult.signature.slice(2), "hex").toString(
785
- "base64"
786
- ),
787
- publicKey: publicKeyBase64,
788
- algorithm: "Ed25519",
789
- address: signResult.address
790
- };
791
- let signatures;
792
- if (wipFile.meta.signature) {
793
- const existingSigs = Array.isArray(wipFile.meta.signature) ? [...wipFile.meta.signature] : [wipFile.meta.signature];
794
- const existingIndex = existingSigs.findIndex(
795
- (sig) => sig.publicKey === publicKeyBase64
796
- );
797
- if (existingIndex >= 0) {
798
- existingSigs[existingIndex] = newSignature;
799
- signatures = existingSigs;
800
- } else {
801
- signatures = [...existingSigs, newSignature];
802
- }
803
- } else {
804
- signatures = [newSignature];
805
- }
806
- const signedWipFile = {
807
- ...wipFile,
808
- meta: {
809
- ...wipFile.meta,
810
- signature: signatures
811
- }
812
- };
813
- let savePath;
814
- if (outputPath) {
815
- savePath = outputPath;
816
- } else {
817
- const dir = path.dirname(wipFilePath);
818
- const ext = path.extname(wipFilePath);
819
- const baseName = path.basename(wipFilePath, ext);
820
- savePath = path.join(dir, `signed_${baseName}${ext}`);
821
- }
822
- wip.save(signedWipFile, savePath, true);
823
- return savePath;
1068
+ // 10. 确定保存路径
1069
+ let savePath;
1070
+ if (outputPath) {
1071
+ savePath = outputPath;
1072
+ }
1073
+ else {
1074
+ // 在原文件名前添加 signed_ 前缀
1075
+ const dir = path.dirname(wipFilePath);
1076
+ const ext = path.extname(wipFilePath);
1077
+ const baseName = path.basename(wipFilePath, ext);
1078
+ savePath = path.join(dir, `signed_${baseName}${ext}`);
1079
+ }
1080
+ wip.save(signedWipFile, savePath, true);
1081
+ return savePath;
824
1082
  }
825
- async function wip2html(wipPath, options = {}) {
826
- const fs2 = await import("fs");
827
- const path2 = await import("path");
828
- const stats = fs2.statSync(wipPath);
829
- if (stats.isFile()) {
830
- const wip = new WIP();
831
- const wipFile = await wip.load(wipPath);
832
- const html = await wip.toHtml(wipFile, options);
833
- if (options.outputPath) {
834
- fs2.writeFileSync(options.outputPath, html);
835
- return options.outputPath;
836
- }
837
- return html;
838
- } else if (stats.isDirectory()) {
839
- const files = fs2.readdirSync(wipPath);
840
- const wipFiles = files.filter((f) => f.endsWith(".wip"));
841
- if (wipFiles.length === 0) {
842
- throw new WipValidationError(
843
- `No .wip files found in directory: ${wipPath}`
844
- );
845
- }
846
- const results = [];
847
- const wip = new WIP();
848
- for (const file of wipFiles) {
849
- const filePath = path2.join(wipPath, file);
850
- const wipFile = await wip.load(filePath);
851
- const html = await wip.toHtml(wipFile, options);
852
- const outputFileName = file.replace(".wip", ".html");
853
- const outputFilePath = options.outputPath ? path2.join(options.outputPath, outputFileName) : path2.join(wipPath, outputFileName);
854
- const outputDir = path2.dirname(outputFilePath);
855
- if (!fs2.existsSync(outputDir)) {
856
- fs2.mkdirSync(outputDir, { recursive: true });
857
- }
858
- fs2.writeFileSync(outputFilePath, html);
859
- results.push(outputFilePath);
860
- }
861
- return results;
862
- } else {
863
- throw new WipValidationError(`Invalid path: ${wipPath}`);
864
- }
1083
+ /**
1084
+ * WIP 文件或文件夹转换为 HTML
1085
+ *
1086
+ * @param wipPath WIP 文件路径或文件夹路径
1087
+ * @param options 转换选项(支持 outputPath 直接保存到文件)
1088
+ * @returns HTML 字符串、保存的文件路径,或转换的文件路径数组
1089
+ */
1090
+ export async function wip2html(wipPath, options = {}) {
1091
+ const fs = await import("fs");
1092
+ const path = await import("path");
1093
+ // 检查是文件还是文件夹
1094
+ const stats = fs.statSync(wipPath);
1095
+ if (stats.isFile()) {
1096
+ // 处理单个文件
1097
+ const wip = new WIP();
1098
+ const wipFile = await wip.load(wipPath);
1099
+ const html = await wip.toHtml(wipFile, options);
1100
+ if (options.outputPath) {
1101
+ fs.writeFileSync(options.outputPath, html);
1102
+ return options.outputPath;
1103
+ }
1104
+ return html;
1105
+ }
1106
+ else if (stats.isDirectory()) {
1107
+ // 处理文件夹中的所有 .wip 文件
1108
+ const files = fs.readdirSync(wipPath);
1109
+ const wipFiles = files.filter((f) => f.endsWith(".wip"));
1110
+ if (wipFiles.length === 0) {
1111
+ throw new WipValidationError(`No .wip files found in directory: ${wipPath}`);
1112
+ }
1113
+ const results = [];
1114
+ const wip = new WIP();
1115
+ for (const file of wipFiles) {
1116
+ const filePath = path.join(wipPath, file);
1117
+ const wipFile = await wip.load(filePath);
1118
+ const html = await wip.toHtml(wipFile, options);
1119
+ // 生成输出文件名
1120
+ const outputFileName = file.replace(".wip", ".html");
1121
+ const outputFilePath = options.outputPath
1122
+ ? path.join(options.outputPath, outputFileName)
1123
+ : path.join(wipPath, outputFileName);
1124
+ // 确保输出目录存在
1125
+ const outputDir = path.dirname(outputFilePath);
1126
+ if (!fs.existsSync(outputDir)) {
1127
+ fs.mkdirSync(outputDir, { recursive: true });
1128
+ }
1129
+ fs.writeFileSync(outputFilePath, html);
1130
+ results.push(outputFilePath);
1131
+ }
1132
+ return results;
1133
+ }
1134
+ else {
1135
+ throw new WipValidationError(`Invalid path: ${wipPath}`);
1136
+ }
865
1137
  }
866
- var wip_default = WIP;
867
- export {
868
- DEFAULT_LIMITS,
869
- WIP,
870
- WipError,
871
- WipSizeError,
872
- WipValidationError,
873
- createWip,
874
- wip_default as default,
875
- generate_wip,
876
- loadWip,
877
- sign_wip,
878
- verifyWip,
879
- verify_wip,
880
- wip2html,
881
- wipToHtml
882
- };
1138
+ export default WIP;
1139
+ //# sourceMappingURL=wip.js.map