@hashgraphonline/standards-sdk 0.1.143 → 0.1.144-feat-solana-register.canary.d5edcec.80

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 (475) hide show
  1. package/dist/cjs/hcs-10/base-client.d.ts.map +1 -1
  2. package/dist/cjs/hcs-10/sdk.d.ts +8 -0
  3. package/dist/cjs/hcs-10/sdk.d.ts.map +1 -1
  4. package/dist/cjs/hcs-11/client.d.ts +2 -2
  5. package/dist/cjs/hcs-11/client.d.ts.map +1 -1
  6. package/dist/cjs/hcs-11/person-builder.d.ts +1 -0
  7. package/dist/cjs/hcs-11/person-builder.d.ts.map +1 -1
  8. package/dist/cjs/hcs-11/types.d.ts +1 -0
  9. package/dist/cjs/hcs-11/types.d.ts.map +1 -1
  10. package/dist/cjs/hcs-12/rendering/resource-manager.d.ts.map +1 -1
  11. package/dist/cjs/hcs-12/validation/schemas.d.ts +8 -8
  12. package/dist/cjs/hcs-14/issuers/hiero.d.ts.map +1 -1
  13. package/dist/cjs/hcs-15/browser.d.ts +2 -0
  14. package/dist/cjs/hcs-15/browser.d.ts.map +1 -1
  15. package/dist/cjs/hcs-15/sdk.d.ts +7 -1
  16. package/dist/cjs/hcs-15/sdk.d.ts.map +1 -1
  17. package/dist/cjs/hcs-15/tx.d.ts +4 -0
  18. package/dist/cjs/hcs-15/tx.d.ts.map +1 -1
  19. package/dist/cjs/hcs-15/types.d.ts +16 -1
  20. package/dist/cjs/hcs-15/types.d.ts.map +1 -1
  21. package/dist/cjs/hcs-16/browser.d.ts +11 -2
  22. package/dist/cjs/hcs-16/browser.d.ts.map +1 -1
  23. package/dist/cjs/hcs-16/sdk.d.ts +62 -1
  24. package/dist/cjs/hcs-16/sdk.d.ts.map +1 -1
  25. package/dist/cjs/hcs-16/tx.d.ts +21 -3
  26. package/dist/cjs/hcs-16/tx.d.ts.map +1 -1
  27. package/dist/cjs/hcs-17/base-client.d.ts +1 -0
  28. package/dist/cjs/hcs-17/base-client.d.ts.map +1 -1
  29. package/dist/cjs/hcs-17/sdk.d.ts.map +1 -1
  30. package/dist/cjs/hcs-17/tx.d.ts +2 -0
  31. package/dist/cjs/hcs-17/tx.d.ts.map +1 -1
  32. package/dist/cjs/hcs-17/types.d.ts +4 -0
  33. package/dist/cjs/hcs-17/types.d.ts.map +1 -1
  34. package/dist/cjs/hcs-21/types.d.ts +75 -75
  35. package/dist/cjs/index.d.ts.map +1 -1
  36. package/dist/cjs/services/registry-broker/client/adapters.d.ts +20 -0
  37. package/dist/cjs/services/registry-broker/client/adapters.d.ts.map +1 -0
  38. package/dist/cjs/services/registry-broker/client/agents.d.ts +16 -0
  39. package/dist/cjs/services/registry-broker/client/agents.d.ts.map +1 -0
  40. package/dist/cjs/services/registry-broker/client/base-client.d.ts +70 -0
  41. package/dist/cjs/services/registry-broker/client/base-client.d.ts.map +1 -0
  42. package/dist/cjs/services/registry-broker/client/chat-history.d.ts +23 -0
  43. package/dist/cjs/services/registry-broker/client/chat-history.d.ts.map +1 -0
  44. package/dist/cjs/services/registry-broker/client/chat.d.ts +33 -0
  45. package/dist/cjs/services/registry-broker/client/chat.d.ts.map +1 -0
  46. package/dist/cjs/services/registry-broker/client/credits.d.ts +40 -0
  47. package/dist/cjs/services/registry-broker/client/credits.d.ts.map +1 -0
  48. package/dist/cjs/services/registry-broker/client/encrypted-chat-manager.d.ts +35 -0
  49. package/dist/cjs/services/registry-broker/client/encrypted-chat-manager.d.ts.map +1 -0
  50. package/dist/cjs/services/registry-broker/client/encryption.d.ts +33 -0
  51. package/dist/cjs/services/registry-broker/client/encryption.d.ts.map +1 -0
  52. package/dist/cjs/services/registry-broker/client/errors.d.ts +19 -0
  53. package/dist/cjs/services/registry-broker/client/errors.d.ts.map +1 -0
  54. package/dist/cjs/services/registry-broker/client/feedback.d.ts +2 -0
  55. package/dist/cjs/services/registry-broker/client/feedback.d.ts.map +1 -0
  56. package/dist/cjs/services/registry-broker/client/ledger-auth.d.ts +10 -0
  57. package/dist/cjs/services/registry-broker/client/ledger-auth.d.ts.map +1 -0
  58. package/dist/cjs/services/registry-broker/client/search.d.ts +19 -0
  59. package/dist/cjs/services/registry-broker/client/search.d.ts.map +1 -0
  60. package/dist/cjs/services/registry-broker/client/utils.d.ts +21 -0
  61. package/dist/cjs/services/registry-broker/client/utils.d.ts.map +1 -0
  62. package/dist/cjs/services/registry-broker/client.d.ts +2 -205
  63. package/dist/cjs/services/registry-broker/client.d.ts.map +1 -1
  64. package/dist/cjs/services/registry-broker/private-key-signer.d.ts +1 -0
  65. package/dist/cjs/services/registry-broker/private-key-signer.d.ts.map +1 -1
  66. package/dist/cjs/services/registry-broker/schemas.d.ts +2509 -816
  67. package/dist/cjs/services/registry-broker/schemas.d.ts.map +1 -1
  68. package/dist/cjs/services/registry-broker/types.d.ts +64 -2
  69. package/dist/cjs/services/registry-broker/types.d.ts.map +1 -1
  70. package/dist/cjs/standards-sdk.cjs +3 -3
  71. package/dist/cjs/standards-sdk.cjs.map +1 -1
  72. package/dist/cjs/utils/crypto-abstraction.d.ts.map +1 -1
  73. package/dist/cjs/utils/crypto-env.d.ts.map +1 -1
  74. package/dist/cjs/utils/dynamic-import.d.ts +5 -1
  75. package/dist/cjs/utils/dynamic-import.d.ts.map +1 -1
  76. package/dist/cjs/utils/hash-adapter.d.ts.map +1 -1
  77. package/dist/es/hcs-10/base-client.d.ts.map +1 -1
  78. package/dist/es/hcs-10/sdk.d.ts +8 -0
  79. package/dist/es/hcs-10/sdk.d.ts.map +1 -1
  80. package/dist/es/hcs-11/client.d.ts +2 -2
  81. package/dist/es/hcs-11/client.d.ts.map +1 -1
  82. package/dist/es/hcs-11/person-builder.d.ts +1 -0
  83. package/dist/es/hcs-11/person-builder.d.ts.map +1 -1
  84. package/dist/es/hcs-11/types.d.ts +1 -0
  85. package/dist/es/hcs-11/types.d.ts.map +1 -1
  86. package/dist/es/hcs-12/rendering/resource-manager.d.ts.map +1 -1
  87. package/dist/es/hcs-12/validation/schemas.d.ts +8 -8
  88. package/dist/es/hcs-14/issuers/hiero.d.ts.map +1 -1
  89. package/dist/es/hcs-15/browser.d.ts +2 -0
  90. package/dist/es/hcs-15/browser.d.ts.map +1 -1
  91. package/dist/es/hcs-15/sdk.d.ts +7 -1
  92. package/dist/es/hcs-15/sdk.d.ts.map +1 -1
  93. package/dist/es/hcs-15/tx.d.ts +4 -0
  94. package/dist/es/hcs-15/tx.d.ts.map +1 -1
  95. package/dist/es/hcs-15/types.d.ts +16 -1
  96. package/dist/es/hcs-15/types.d.ts.map +1 -1
  97. package/dist/es/hcs-16/browser.d.ts +11 -2
  98. package/dist/es/hcs-16/browser.d.ts.map +1 -1
  99. package/dist/es/hcs-16/sdk.d.ts +62 -1
  100. package/dist/es/hcs-16/sdk.d.ts.map +1 -1
  101. package/dist/es/hcs-16/tx.d.ts +21 -3
  102. package/dist/es/hcs-16/tx.d.ts.map +1 -1
  103. package/dist/es/hcs-17/base-client.d.ts +1 -0
  104. package/dist/es/hcs-17/base-client.d.ts.map +1 -1
  105. package/dist/es/hcs-17/sdk.d.ts.map +1 -1
  106. package/dist/es/hcs-17/tx.d.ts +2 -0
  107. package/dist/es/hcs-17/tx.d.ts.map +1 -1
  108. package/dist/es/hcs-17/types.d.ts +4 -0
  109. package/dist/es/hcs-17/types.d.ts.map +1 -1
  110. package/dist/es/hcs-21/types.d.ts +75 -75
  111. package/dist/es/index.d.ts.map +1 -1
  112. package/dist/es/services/registry-broker/client/adapters.d.ts +20 -0
  113. package/dist/es/services/registry-broker/client/adapters.d.ts.map +1 -0
  114. package/dist/es/services/registry-broker/client/agents.d.ts +16 -0
  115. package/dist/es/services/registry-broker/client/agents.d.ts.map +1 -0
  116. package/dist/es/services/registry-broker/client/base-client.d.ts +70 -0
  117. package/dist/es/services/registry-broker/client/base-client.d.ts.map +1 -0
  118. package/dist/es/services/registry-broker/client/chat-history.d.ts +23 -0
  119. package/dist/es/services/registry-broker/client/chat-history.d.ts.map +1 -0
  120. package/dist/es/services/registry-broker/client/chat.d.ts +33 -0
  121. package/dist/es/services/registry-broker/client/chat.d.ts.map +1 -0
  122. package/dist/es/services/registry-broker/client/credits.d.ts +40 -0
  123. package/dist/es/services/registry-broker/client/credits.d.ts.map +1 -0
  124. package/dist/es/services/registry-broker/client/encrypted-chat-manager.d.ts +35 -0
  125. package/dist/es/services/registry-broker/client/encrypted-chat-manager.d.ts.map +1 -0
  126. package/dist/es/services/registry-broker/client/encryption.d.ts +33 -0
  127. package/dist/es/services/registry-broker/client/encryption.d.ts.map +1 -0
  128. package/dist/es/services/registry-broker/client/errors.d.ts +19 -0
  129. package/dist/es/services/registry-broker/client/errors.d.ts.map +1 -0
  130. package/dist/es/services/registry-broker/client/feedback.d.ts +2 -0
  131. package/dist/es/services/registry-broker/client/feedback.d.ts.map +1 -0
  132. package/dist/es/services/registry-broker/client/ledger-auth.d.ts +10 -0
  133. package/dist/es/services/registry-broker/client/ledger-auth.d.ts.map +1 -0
  134. package/dist/es/services/registry-broker/client/search.d.ts +19 -0
  135. package/dist/es/services/registry-broker/client/search.d.ts.map +1 -0
  136. package/dist/es/services/registry-broker/client/utils.d.ts +21 -0
  137. package/dist/es/services/registry-broker/client/utils.d.ts.map +1 -0
  138. package/dist/es/services/registry-broker/client.d.ts +2 -205
  139. package/dist/es/services/registry-broker/client.d.ts.map +1 -1
  140. package/dist/es/services/registry-broker/private-key-signer.d.ts +1 -0
  141. package/dist/es/services/registry-broker/private-key-signer.d.ts.map +1 -1
  142. package/dist/es/services/registry-broker/schemas.d.ts +2509 -816
  143. package/dist/es/services/registry-broker/schemas.d.ts.map +1 -1
  144. package/dist/es/services/registry-broker/types.d.ts +64 -2
  145. package/dist/es/services/registry-broker/types.d.ts.map +1 -1
  146. package/dist/es/standards-sdk.es.js +148 -133
  147. package/dist/es/standards-sdk.es.js.map +1 -1
  148. package/dist/es/standards-sdk.es10.js +70 -90
  149. package/dist/es/standards-sdk.es10.js.map +1 -1
  150. package/dist/es/standards-sdk.es100.js +229 -26
  151. package/dist/es/standards-sdk.es100.js.map +1 -1
  152. package/dist/es/standards-sdk.es101.js +109 -228
  153. package/dist/es/standards-sdk.es101.js.map +1 -1
  154. package/dist/es/standards-sdk.es102.js +15 -94
  155. package/dist/es/standards-sdk.es102.js.map +1 -1
  156. package/dist/es/standards-sdk.es103.js +80 -30
  157. package/dist/es/standards-sdk.es103.js.map +1 -1
  158. package/dist/es/standards-sdk.es104.js +27 -80
  159. package/dist/es/standards-sdk.es104.js.map +1 -1
  160. package/dist/es/standards-sdk.es105.js +136 -25
  161. package/dist/es/standards-sdk.es105.js.map +1 -1
  162. package/dist/es/standards-sdk.es106.js +27 -140
  163. package/dist/es/standards-sdk.es106.js.map +1 -1
  164. package/dist/es/standards-sdk.es107.js +20 -27
  165. package/dist/es/standards-sdk.es107.js.map +1 -1
  166. package/dist/es/standards-sdk.es108.js +156 -18
  167. package/dist/es/standards-sdk.es108.js.map +1 -1
  168. package/dist/es/standards-sdk.es109.js +198 -148
  169. package/dist/es/standards-sdk.es109.js.map +1 -1
  170. package/dist/es/standards-sdk.es11.js +121 -45
  171. package/dist/es/standards-sdk.es11.js.map +1 -1
  172. package/dist/es/standards-sdk.es110.js +747 -160
  173. package/dist/es/standards-sdk.es110.js.map +1 -1
  174. package/dist/es/standards-sdk.es111.js +9 -786
  175. package/dist/es/standards-sdk.es111.js.map +1 -1
  176. package/dist/es/standards-sdk.es112.js +567 -13
  177. package/dist/es/standards-sdk.es112.js.map +1 -1
  178. package/dist/es/standards-sdk.es113.js +576 -541
  179. package/dist/es/standards-sdk.es113.js.map +1 -1
  180. package/dist/es/standards-sdk.es114.js +12 -601
  181. package/dist/es/standards-sdk.es114.js.map +1 -1
  182. package/dist/es/standards-sdk.es115.js +2 -13
  183. package/dist/es/standards-sdk.es115.js.map +1 -1
  184. package/dist/es/standards-sdk.es116.js +87 -2
  185. package/dist/es/standards-sdk.es116.js.map +1 -1
  186. package/dist/es/standards-sdk.es117.js +37 -80
  187. package/dist/es/standards-sdk.es117.js.map +1 -1
  188. package/dist/es/standards-sdk.es118.js +2 -39
  189. package/dist/es/standards-sdk.es118.js.map +1 -1
  190. package/dist/es/standards-sdk.es119.js +231 -2
  191. package/dist/es/standards-sdk.es119.js.map +1 -1
  192. package/dist/es/standards-sdk.es12.js +60 -159
  193. package/dist/es/standards-sdk.es12.js.map +1 -1
  194. package/dist/es/standards-sdk.es120.js +1110 -193
  195. package/dist/es/standards-sdk.es120.js.map +1 -1
  196. package/dist/es/standards-sdk.es121.js +225 -1059
  197. package/dist/es/standards-sdk.es121.js.map +1 -1
  198. package/dist/es/standards-sdk.es122.js +419 -303
  199. package/dist/es/standards-sdk.es122.js.map +1 -1
  200. package/dist/es/standards-sdk.es123.js +351 -418
  201. package/dist/es/standards-sdk.es123.js.map +1 -1
  202. package/dist/es/standards-sdk.es124.js +872 -347
  203. package/dist/es/standards-sdk.es124.js.map +1 -1
  204. package/dist/es/standards-sdk.es125.js +182 -854
  205. package/dist/es/standards-sdk.es125.js.map +1 -1
  206. package/dist/es/standards-sdk.es126.js +1512 -153
  207. package/dist/es/standards-sdk.es126.js.map +1 -1
  208. package/dist/es/standards-sdk.es127.js +157 -1547
  209. package/dist/es/standards-sdk.es127.js.map +1 -1
  210. package/dist/es/standards-sdk.es128.js +184 -2190
  211. package/dist/es/standards-sdk.es128.js.map +1 -1
  212. package/dist/es/standards-sdk.es129.js +100 -63
  213. package/dist/es/standards-sdk.es129.js.map +1 -1
  214. package/dist/es/standards-sdk.es13.js +200 -60
  215. package/dist/es/standards-sdk.es13.js.map +1 -1
  216. package/dist/es/standards-sdk.es130.js +112 -78
  217. package/dist/es/standards-sdk.es130.js.map +1 -1
  218. package/dist/es/standards-sdk.es131.js +232 -144
  219. package/dist/es/standards-sdk.es131.js.map +1 -1
  220. package/dist/es/standards-sdk.es132.js +181 -8
  221. package/dist/es/standards-sdk.es132.js.map +1 -1
  222. package/dist/es/standards-sdk.es133.js +118 -82
  223. package/dist/es/standards-sdk.es133.js.map +1 -1
  224. package/dist/es/standards-sdk.es134.js +322 -61
  225. package/dist/es/standards-sdk.es134.js.map +1 -1
  226. package/dist/es/standards-sdk.es135.js +464 -28
  227. package/dist/es/standards-sdk.es135.js.map +1 -1
  228. package/dist/es/standards-sdk.es136.js +14 -135
  229. package/dist/es/standards-sdk.es136.js.map +1 -1
  230. package/dist/es/standards-sdk.es137.js +78 -39
  231. package/dist/es/standards-sdk.es137.js.map +1 -1
  232. package/dist/es/standards-sdk.es138.js +85 -764
  233. package/dist/es/standards-sdk.es138.js.map +1 -1
  234. package/dist/es/standards-sdk.es139.js +135 -12250
  235. package/dist/es/standards-sdk.es139.js.map +1 -1
  236. package/dist/es/standards-sdk.es14.js +149 -178
  237. package/dist/es/standards-sdk.es14.js.map +1 -1
  238. package/dist/es/standards-sdk.es140.js +7 -56
  239. package/dist/es/standards-sdk.es140.js.map +1 -1
  240. package/dist/es/standards-sdk.es141.js +72 -68
  241. package/dist/es/standards-sdk.es141.js.map +1 -1
  242. package/dist/es/standards-sdk.es142.js +61 -13
  243. package/dist/es/standards-sdk.es142.js.map +1 -1
  244. package/dist/es/standards-sdk.es143.js +30 -172
  245. package/dist/es/standards-sdk.es143.js.map +1 -1
  246. package/dist/es/standards-sdk.es144.js +34 -322
  247. package/dist/es/standards-sdk.es144.js.map +1 -1
  248. package/dist/es/standards-sdk.es145.js +28 -346
  249. package/dist/es/standards-sdk.es145.js.map +1 -1
  250. package/dist/es/standards-sdk.es146.js +112 -427
  251. package/dist/es/standards-sdk.es146.js.map +1 -1
  252. package/dist/es/standards-sdk.es147.js +40 -329
  253. package/dist/es/standards-sdk.es147.js.map +1 -1
  254. package/dist/es/standards-sdk.es148.js +12279 -66
  255. package/dist/es/standards-sdk.es148.js.map +1 -1
  256. package/dist/es/standards-sdk.es149.js +961 -0
  257. package/dist/es/standards-sdk.es149.js.map +1 -0
  258. package/dist/es/standards-sdk.es15.js +152 -151
  259. package/dist/es/standards-sdk.es15.js.map +1 -1
  260. package/dist/es/standards-sdk.es150.js +20 -0
  261. package/dist/es/standards-sdk.es150.js.map +1 -0
  262. package/dist/es/standards-sdk.es151.js +59 -0
  263. package/dist/es/standards-sdk.es151.js.map +1 -0
  264. package/dist/es/standards-sdk.es152.js +87 -0
  265. package/dist/es/standards-sdk.es152.js.map +1 -0
  266. package/dist/es/standards-sdk.es153.js +175 -0
  267. package/dist/es/standards-sdk.es153.js.map +1 -0
  268. package/dist/es/standards-sdk.es154.js +325 -0
  269. package/dist/es/standards-sdk.es154.js.map +1 -0
  270. package/dist/es/standards-sdk.es155.js +349 -0
  271. package/dist/es/standards-sdk.es155.js.map +1 -0
  272. package/dist/es/standards-sdk.es156.js +456 -0
  273. package/dist/es/standards-sdk.es156.js.map +1 -0
  274. package/dist/es/standards-sdk.es157.js +334 -0
  275. package/dist/es/standards-sdk.es157.js.map +1 -0
  276. package/dist/es/standards-sdk.es158.js +79 -0
  277. package/dist/es/standards-sdk.es158.js.map +1 -0
  278. package/dist/es/standards-sdk.es159.js +242 -0
  279. package/dist/es/standards-sdk.es159.js.map +1 -0
  280. package/dist/es/standards-sdk.es16.js +917 -136
  281. package/dist/es/standards-sdk.es16.js.map +1 -1
  282. package/dist/es/standards-sdk.es160.js +247 -0
  283. package/dist/es/standards-sdk.es160.js.map +1 -0
  284. package/dist/es/standards-sdk.es17.js +23 -938
  285. package/dist/es/standards-sdk.es17.js.map +1 -1
  286. package/dist/es/standards-sdk.es18.js +2422 -24
  287. package/dist/es/standards-sdk.es18.js.map +1 -1
  288. package/dist/es/standards-sdk.es19.js +826 -2075
  289. package/dist/es/standards-sdk.es19.js.map +1 -1
  290. package/dist/es/standards-sdk.es2.js +654 -189
  291. package/dist/es/standards-sdk.es2.js.map +1 -1
  292. package/dist/es/standards-sdk.es20.js +205 -1086
  293. package/dist/es/standards-sdk.es20.js.map +1 -1
  294. package/dist/es/standards-sdk.es21.js +858 -221
  295. package/dist/es/standards-sdk.es21.js.map +1 -1
  296. package/dist/es/standards-sdk.es22.js +179 -903
  297. package/dist/es/standards-sdk.es22.js.map +1 -1
  298. package/dist/es/standards-sdk.es23.js +164 -179
  299. package/dist/es/standards-sdk.es23.js.map +1 -1
  300. package/dist/es/standards-sdk.es24.js +62 -118
  301. package/dist/es/standards-sdk.es24.js.map +1 -1
  302. package/dist/es/standards-sdk.es25.js +377 -52
  303. package/dist/es/standards-sdk.es25.js.map +1 -1
  304. package/dist/es/standards-sdk.es26.js +36 -394
  305. package/dist/es/standards-sdk.es26.js.map +1 -1
  306. package/dist/es/standards-sdk.es27.js +901 -50
  307. package/dist/es/standards-sdk.es27.js.map +1 -1
  308. package/dist/es/standards-sdk.es28.js +134 -897
  309. package/dist/es/standards-sdk.es28.js.map +1 -1
  310. package/dist/es/standards-sdk.es29.js +7 -134
  311. package/dist/es/standards-sdk.es29.js.map +1 -1
  312. package/dist/es/standards-sdk.es3.js +63 -680
  313. package/dist/es/standards-sdk.es3.js.map +1 -1
  314. package/dist/es/standards-sdk.es30.js +344 -7
  315. package/dist/es/standards-sdk.es30.js.map +1 -1
  316. package/dist/es/standards-sdk.es31.js +302 -287
  317. package/dist/es/standards-sdk.es31.js.map +1 -1
  318. package/dist/es/standards-sdk.es32.js +94 -322
  319. package/dist/es/standards-sdk.es32.js.map +1 -1
  320. package/dist/es/standards-sdk.es33.js +458 -101
  321. package/dist/es/standards-sdk.es33.js.map +1 -1
  322. package/dist/es/standards-sdk.es34.js +132 -451
  323. package/dist/es/standards-sdk.es34.js.map +1 -1
  324. package/dist/es/standards-sdk.es35.js +216 -130
  325. package/dist/es/standards-sdk.es35.js.map +1 -1
  326. package/dist/es/standards-sdk.es36.js +274 -191
  327. package/dist/es/standards-sdk.es36.js.map +1 -1
  328. package/dist/es/standards-sdk.es37.js +148 -87
  329. package/dist/es/standards-sdk.es37.js.map +1 -1
  330. package/dist/es/standards-sdk.es38.js +183 -320
  331. package/dist/es/standards-sdk.es38.js.map +1 -1
  332. package/dist/es/standards-sdk.es39.js +238 -161
  333. package/dist/es/standards-sdk.es39.js.map +1 -1
  334. package/dist/es/standards-sdk.es4.js +425 -63
  335. package/dist/es/standards-sdk.es4.js.map +1 -1
  336. package/dist/es/standards-sdk.es40.js +136 -254
  337. package/dist/es/standards-sdk.es40.js.map +1 -1
  338. package/dist/es/standards-sdk.es41.js +225 -176
  339. package/dist/es/standards-sdk.es41.js.map +1 -1
  340. package/dist/es/standards-sdk.es42.js +199 -261
  341. package/dist/es/standards-sdk.es42.js.map +1 -1
  342. package/dist/es/standards-sdk.es43.js +237 -199
  343. package/dist/es/standards-sdk.es43.js.map +1 -1
  344. package/dist/es/standards-sdk.es44.js +209 -201
  345. package/dist/es/standards-sdk.es44.js.map +1 -1
  346. package/dist/es/standards-sdk.es45.js +305 -201
  347. package/dist/es/standards-sdk.es45.js.map +1 -1
  348. package/dist/es/standards-sdk.es46.js +371 -261
  349. package/dist/es/standards-sdk.es46.js.map +1 -1
  350. package/dist/es/standards-sdk.es47.js +316 -371
  351. package/dist/es/standards-sdk.es47.js.map +1 -1
  352. package/dist/es/standards-sdk.es48.js +404 -336
  353. package/dist/es/standards-sdk.es48.js.map +1 -1
  354. package/dist/es/standards-sdk.es49.js +83 -449
  355. package/dist/es/standards-sdk.es49.js.map +1 -1
  356. package/dist/es/standards-sdk.es5.js +232 -354
  357. package/dist/es/standards-sdk.es5.js.map +1 -1
  358. package/dist/es/standards-sdk.es50.js +179 -89
  359. package/dist/es/standards-sdk.es50.js.map +1 -1
  360. package/dist/es/standards-sdk.es51.js +231 -165
  361. package/dist/es/standards-sdk.es51.js.map +1 -1
  362. package/dist/es/standards-sdk.es52.js +25 -262
  363. package/dist/es/standards-sdk.es52.js.map +1 -1
  364. package/dist/es/standards-sdk.es53.js +56 -26
  365. package/dist/es/standards-sdk.es53.js.map +1 -1
  366. package/dist/es/standards-sdk.es54.js +12 -57
  367. package/dist/es/standards-sdk.es54.js.map +1 -1
  368. package/dist/es/standards-sdk.es55.js +49 -12
  369. package/dist/es/standards-sdk.es55.js.map +1 -1
  370. package/dist/es/standards-sdk.es56.js +115 -43
  371. package/dist/es/standards-sdk.es56.js.map +1 -1
  372. package/dist/es/standards-sdk.es57.js +42 -115
  373. package/dist/es/standards-sdk.es57.js.map +1 -1
  374. package/dist/es/standards-sdk.es58.js +52 -43
  375. package/dist/es/standards-sdk.es58.js.map +1 -1
  376. package/dist/es/standards-sdk.es59.js +36 -50
  377. package/dist/es/standards-sdk.es59.js.map +1 -1
  378. package/dist/es/standards-sdk.es6.js +125 -246
  379. package/dist/es/standards-sdk.es6.js.map +1 -1
  380. package/dist/es/standards-sdk.es60.js +207 -39
  381. package/dist/es/standards-sdk.es60.js.map +1 -1
  382. package/dist/es/standards-sdk.es61.js +24 -195
  383. package/dist/es/standards-sdk.es61.js.map +1 -1
  384. package/dist/es/standards-sdk.es62.js +87 -25
  385. package/dist/es/standards-sdk.es62.js.map +1 -1
  386. package/dist/es/standards-sdk.es63.js +3 -51
  387. package/dist/es/standards-sdk.es63.js.map +1 -1
  388. package/dist/es/standards-sdk.es64.js +100 -3
  389. package/dist/es/standards-sdk.es64.js.map +1 -1
  390. package/dist/es/standards-sdk.es65.js +61 -62
  391. package/dist/es/standards-sdk.es65.js.map +1 -1
  392. package/dist/es/standards-sdk.es66.js +17 -98
  393. package/dist/es/standards-sdk.es66.js.map +1 -1
  394. package/dist/es/standards-sdk.es67.js +77 -19
  395. package/dist/es/standards-sdk.es67.js.map +1 -1
  396. package/dist/es/standards-sdk.es68.js +458 -77
  397. package/dist/es/standards-sdk.es68.js.map +1 -1
  398. package/dist/es/standards-sdk.es69.js +106 -240
  399. package/dist/es/standards-sdk.es69.js.map +1 -1
  400. package/dist/es/standards-sdk.es7.js +28 -183
  401. package/dist/es/standards-sdk.es7.js.map +1 -1
  402. package/dist/es/standards-sdk.es70.js +170 -286
  403. package/dist/es/standards-sdk.es70.js.map +1 -1
  404. package/dist/es/standards-sdk.es71.js +71 -207
  405. package/dist/es/standards-sdk.es71.js.map +1 -1
  406. package/dist/es/standards-sdk.es72.js +71 -72
  407. package/dist/es/standards-sdk.es72.js.map +1 -1
  408. package/dist/es/standards-sdk.es73.js +143 -71
  409. package/dist/es/standards-sdk.es73.js.map +1 -1
  410. package/dist/es/standards-sdk.es74.js +62 -136
  411. package/dist/es/standards-sdk.es74.js.map +1 -1
  412. package/dist/es/standards-sdk.es75.js +380 -45
  413. package/dist/es/standards-sdk.es75.js.map +1 -1
  414. package/dist/es/standards-sdk.es76.js +222 -130
  415. package/dist/es/standards-sdk.es76.js.map +1 -1
  416. package/dist/es/standards-sdk.es77.js +320 -444
  417. package/dist/es/standards-sdk.es77.js.map +1 -1
  418. package/dist/es/standards-sdk.es78.js +88 -364
  419. package/dist/es/standards-sdk.es78.js.map +1 -1
  420. package/dist/es/standards-sdk.es79.js +125 -89
  421. package/dist/es/standards-sdk.es79.js.map +1 -1
  422. package/dist/es/standards-sdk.es8.js +80 -29
  423. package/dist/es/standards-sdk.es8.js.map +1 -1
  424. package/dist/es/standards-sdk.es80.js +8 -125
  425. package/dist/es/standards-sdk.es80.js.map +1 -1
  426. package/dist/es/standards-sdk.es81.js +45 -6
  427. package/dist/es/standards-sdk.es81.js.map +1 -1
  428. package/dist/es/standards-sdk.es82.js +98 -44
  429. package/dist/es/standards-sdk.es82.js.map +1 -1
  430. package/dist/es/standards-sdk.es83.js +331 -84
  431. package/dist/es/standards-sdk.es83.js.map +1 -1
  432. package/dist/es/standards-sdk.es84.js +93 -160
  433. package/dist/es/standards-sdk.es84.js.map +1 -1
  434. package/dist/es/standards-sdk.es85.js +55 -275
  435. package/dist/es/standards-sdk.es85.js.map +1 -1
  436. package/dist/es/standards-sdk.es86.js +43 -55
  437. package/dist/es/standards-sdk.es86.js.map +1 -1
  438. package/dist/es/standards-sdk.es87.js +145 -22
  439. package/dist/es/standards-sdk.es87.js.map +1 -1
  440. package/dist/es/standards-sdk.es88.js +34 -47
  441. package/dist/es/standards-sdk.es88.js.map +1 -1
  442. package/dist/es/standards-sdk.es89.js +22 -57
  443. package/dist/es/standards-sdk.es89.js.map +1 -1
  444. package/dist/es/standards-sdk.es9.js +104 -80
  445. package/dist/es/standards-sdk.es9.js.map +1 -1
  446. package/dist/es/standards-sdk.es90.js +23 -28
  447. package/dist/es/standards-sdk.es90.js.map +1 -1
  448. package/dist/es/standards-sdk.es91.js +238 -23
  449. package/dist/es/standards-sdk.es91.js.map +1 -1
  450. package/dist/es/standards-sdk.es92.js +265 -152
  451. package/dist/es/standards-sdk.es92.js.map +1 -1
  452. package/dist/es/standards-sdk.es93.js +95 -68
  453. package/dist/es/standards-sdk.es93.js.map +1 -1
  454. package/dist/es/standards-sdk.es94.js +124 -136
  455. package/dist/es/standards-sdk.es94.js.map +1 -1
  456. package/dist/es/standards-sdk.es95.js +42 -138
  457. package/dist/es/standards-sdk.es95.js.map +1 -1
  458. package/dist/es/standards-sdk.es96.js +259 -42
  459. package/dist/es/standards-sdk.es96.js.map +1 -1
  460. package/dist/es/standards-sdk.es97.js +82 -243
  461. package/dist/es/standards-sdk.es97.js.map +1 -1
  462. package/dist/es/standards-sdk.es98.js +48 -47
  463. package/dist/es/standards-sdk.es98.js.map +1 -1
  464. package/dist/es/standards-sdk.es99.js +29 -100
  465. package/dist/es/standards-sdk.es99.js.map +1 -1
  466. package/dist/es/utils/crypto-abstraction.d.ts.map +1 -1
  467. package/dist/es/utils/crypto-env.d.ts.map +1 -1
  468. package/dist/es/utils/dynamic-import.d.ts +5 -1
  469. package/dist/es/utils/dynamic-import.d.ts.map +1 -1
  470. package/dist/es/utils/hash-adapter.d.ts.map +1 -1
  471. package/package.json +15 -16
  472. package/dist/cjs/patches/topic-autorenew-patch.d.ts +0 -2
  473. package/dist/cjs/patches/topic-autorenew-patch.d.ts.map +0 -1
  474. package/dist/es/patches/topic-autorenew-patch.d.ts +0 -2
  475. package/dist/es/patches/topic-autorenew-patch.d.ts.map +0 -1
@@ -1,35 +1,34 @@
1
- import "./standards-sdk.es2.js";
2
- import { Client, PrivateKey, AccountCreateTransaction, Hbar, CustomFixedFee, AccountId, TokenId, KeyList, TopicMessageSubmitTransaction, Transaction, ScheduleCreateTransaction, Timestamp } from "@hashgraph/sdk";
3
- import { AccountCreationError, TopicCreationError, ConnectionConfirmationError, PayloadSizeError } from "./standards-sdk.es18.js";
4
- import { InscriptionSDK } from "./standards-sdk.es139.js";
5
- import { Logger } from "./standards-sdk.es106.js";
6
- import { accountIdsToExemptKeys } from "./standards-sdk.es108.js";
7
- import { ProgressReporter } from "./standards-sdk.es109.js";
1
+ import { KeyList, TopicCreateTransaction, AccountId, Transaction, TopicMessageSubmitTransaction, Hbar } from "@hashgraph/sdk";
2
+ import { Logger } from "./standards-sdk.es105.js";
8
3
  import "axios";
9
4
  import "@hashgraph/proto";
10
- import "node:path";
11
- import "node:buffer";
12
- import "node:crypto";
13
- import "@noble/curves/secp256k1.js";
5
+ import { ProgressReporter } from "./standards-sdk.es108.js";
6
+ import "./standards-sdk.es127.js";
7
+ import "./standards-sdk.es128.js";
8
+ import "./standards-sdk.es129.js";
14
9
  import "./standards-sdk.es130.js";
15
- import "./standards-sdk.es138.js";
16
- import "zod";
10
+ import "./standards-sdk.es131.js";
11
+ import "./standards-sdk.es132.js";
12
+ import "./standards-sdk.es133.js";
13
+ import "./standards-sdk.es134.js";
17
14
  import "buffer";
15
+ import "crypto";
16
+ import "@noble/curves/secp256k1.js";
17
+ import "zod";
18
+ import "./standards-sdk.es149.js";
19
+ import "./standards-sdk.es138.js";
18
20
  import "ethers";
19
- import "./standards-sdk.es123.js";
20
- import { detectKeyTypeFromString } from "./standards-sdk.es114.js";
21
- import { getTopicId } from "./standards-sdk.es115.js";
22
- import { createNodeOperatorContext, NodeOperatorResolver } from "./standards-sdk.es136.js";
23
- import { HCS10BaseClient, Hcs10MemoType } from "./standards-sdk.es17.js";
21
+ import "./standards-sdk.es122.js";
22
+ import "./standards-sdk.es113.js";
23
+ import { getTopicId } from "./standards-sdk.es114.js";
24
+ import { InscriptionSDK } from "./standards-sdk.es148.js";
25
+ import { HCS10BaseClient, Hcs10MemoType } from "./standards-sdk.es16.js";
24
26
  import * as mime from "mime-types";
25
- import { AgentBuilder } from "./standards-sdk.es24.js";
26
- import { InboundTopicType } from "./standards-sdk.es29.js";
27
- import { HCS11Client } from "./standards-sdk.es28.js";
28
- import { inscribe } from "./standards-sdk.es125.js";
29
- import { addSeconds } from "date-fns";
30
- import { buildTopicCreateTx, buildMessageTx } from "./standards-sdk.es137.js";
31
- import { buildHcs10CreateInboundTopicTx, buildHcs10CreateConnectionTopicTx, buildHcs10ConfirmConnectionTx, buildHcs10SendMessageTx, buildHcs10RegistryRegisterTx, buildHcs10CreateOutboundTopicTx, buildHcs10CreateRegistryTopicTx } from "./standards-sdk.es23.js";
32
- class HCS10Client extends HCS10BaseClient {
27
+ import { AgentBuilder } from "./standards-sdk.es23.js";
28
+ import { HCS11Client } from "./standards-sdk.es27.js";
29
+ import { inscribeWithSigner } from "./standards-sdk.es124.js";
30
+ const isBrowser = typeof window !== "undefined";
31
+ class BrowserHCSClient extends HCS10BaseClient {
33
32
  constructor(config) {
34
33
  super({
35
34
  network: config.network,
@@ -37,237 +36,194 @@ class HCS10Client extends HCS10BaseClient {
37
36
  prettyPrint: config.prettyPrint,
38
37
  feeAmount: config.feeAmount,
39
38
  mirrorNode: config.mirrorNode,
40
- silent: config.silent,
41
- keyType: config.keyType
39
+ silent: config.silent
42
40
  });
41
+ this.hcs11Client = null;
42
+ this.hwc = config.hwc;
43
+ if (!config.guardedRegistryBaseUrl) {
44
+ this.guardedRegistryBaseUrl = "https://moonscape.tech";
45
+ } else {
46
+ this.guardedRegistryBaseUrl = config.guardedRegistryBaseUrl;
47
+ }
48
+ let logLevel;
49
+ if (config.logLevel) {
50
+ logLevel = config.logLevel;
51
+ } else {
52
+ logLevel = "info";
53
+ }
43
54
  this.logger = Logger.getInstance({
44
- level: config.logLevel || "info",
45
- module: "HCS-SDK",
55
+ level: logLevel,
56
+ module: "HCS-Browser",
57
+ prettyPrint: config.prettyPrint,
46
58
  silent: config.silent
47
59
  });
48
- this.operatorAccountId = config.operatorId;
49
- this.operatorCtx = createNodeOperatorContext({
50
- network: this.network,
51
- operatorId: this.operatorAccountId,
52
- operatorKey: config.operatorPrivateKey,
53
- keyType: config.keyType,
54
- mirrorNode: this.mirrorNode,
55
- logger: this.logger,
56
- client: config.network === "mainnet" ? Client.forMainnet() : Client.forTestnet()
57
- });
58
- this.client = this.operatorCtx.client;
59
- this.network = config.network;
60
- this.guardedRegistryBaseUrl = config.guardedRegistryBaseUrl || "https://moonscape.tech";
61
- this.hcs11Client = new HCS11Client({
62
- network: config.network,
63
- auth: {
64
- operatorId: config.operatorId,
65
- privateKey: this.operatorCtx.operatorKey.toString()
66
- },
67
- logLevel: config.logLevel,
68
- silent: config.silent,
69
- keyType: config.keyType
70
- });
71
- }
72
- async ensureInitialized() {
73
- await this.operatorCtx.ensureInitialized();
74
- }
75
- getClient() {
76
- return this.client;
60
+ if (isBrowser) {
61
+ try {
62
+ const { accountId, signer } = this.getAccountAndSigner();
63
+ this.hcs11Client = new HCS11Client({
64
+ network: config.network,
65
+ auth: {
66
+ operatorId: accountId,
67
+ signer
68
+ },
69
+ logLevel: config.logLevel,
70
+ silent: config.silent
71
+ });
72
+ } catch (err) {
73
+ this.logger.warn(`Failed to initialize HCS11Client: ${err}`);
74
+ }
75
+ } else {
76
+ this.logger.error(
77
+ "BrowserHCSClient initialized in server environment - browser-specific features will not be available. Use HCS10Client instead."
78
+ );
79
+ }
77
80
  }
78
- /**
79
- * Creates a new Hedera account
80
- * @param initialBalance Optional initial balance in HBAR (default: 50)
81
- * @returns Object with account ID and private key
82
- */
83
- async createAccount(initialBalance = 50) {
84
- await this.ensureInitialized();
85
- this.logger.info(
86
- `Creating new account with ${initialBalance} HBAR initial balance`
81
+ async sendMessage(connectionTopicId, data, memo, submitKey, options) {
82
+ this.logger.info("Sending message");
83
+ const operatorId = await this.getOperatorId();
84
+ const payload = {
85
+ p: "hcs-10",
86
+ op: "message",
87
+ operator_id: operatorId,
88
+ data,
89
+ m: memo
90
+ };
91
+ const submissionCheck = await this.canSubmitToTopic(
92
+ connectionTopicId,
93
+ this.hwc.getAccountInfo().accountId
87
94
  );
88
- const newKey = PrivateKey.generateED25519();
89
- const accountTransaction = new AccountCreateTransaction().setKeyWithoutAlias(newKey.publicKey).setInitialBalance(new Hbar(initialBalance));
90
- const accountResponse = await accountTransaction.execute(this.client);
91
- const accountReceipt = await accountResponse.getReceipt(this.client);
92
- const newAccountId = accountReceipt.accountId;
93
- if (!newAccountId) {
94
- this.logger.error("Account creation failed: accountId is null");
95
- throw new AccountCreationError(
96
- "Failed to create account: accountId is null"
95
+ const payloadString = JSON.stringify(payload);
96
+ const isLargePayload = Buffer.from(payloadString).length > 1e3;
97
+ if (isLargePayload) {
98
+ this.logger.info(
99
+ "Message payload exceeds 1000 bytes, storing via inscription"
97
100
  );
101
+ try {
102
+ const contentBuffer = Buffer.from(data);
103
+ const fileName = `message-${Date.now()}.json`;
104
+ const inscriptionResult = await this.inscribeFile(
105
+ contentBuffer,
106
+ fileName,
107
+ {
108
+ progressCallback: options?.progressCallback,
109
+ waitMaxAttempts: options?.waitMaxAttempts,
110
+ waitIntervalMs: options?.waitIntervalMs
111
+ }
112
+ );
113
+ if (getTopicId(inscriptionResult)) {
114
+ payload.data = `hcs://1/${getTopicId(inscriptionResult)}`;
115
+ this.logger.info(
116
+ `Large message inscribed with topic ID: ${getTopicId(inscriptionResult)}`
117
+ );
118
+ } else {
119
+ throw new Error("Failed to inscribe large message content");
120
+ }
121
+ } catch (error) {
122
+ this.logger.error("Error inscribing large message:", error);
123
+ throw new Error(
124
+ `Failed to handle large message: ${error instanceof Error ? error.message : "Unknown error"}`
125
+ );
126
+ }
98
127
  }
99
- this.logger.info(
100
- `Account created successfully: ${newAccountId.toString()}`
128
+ return await this.submitPayload(
129
+ connectionTopicId,
130
+ payload,
131
+ submitKey,
132
+ submissionCheck.requiresFee
101
133
  );
102
- return {
103
- accountId: newAccountId.toString(),
104
- privateKey: newKey.toString()
105
- };
106
134
  }
107
- /**
108
- * Creates an inbound topic for an agent
109
- * @param accountId The account ID associated with the inbound topic
110
- * @param topicType Type of inbound topic (public, controlled, or fee-based)
111
- * @param ttl Optional Time-To-Live for the topic memo, defaults to 60
112
- * @param feeConfigBuilder Optional fee configuration builder for fee-based topics
113
- * @returns The topic ID of the created inbound topic
114
- */
115
- async createInboundTopic(accountId, topicType, ttl = 60, feeConfigBuilder) {
116
- await this.ensureInitialized();
117
- this._generateHcs10Memo(Hcs10MemoType.INBOUND, {
118
- accountId,
119
- ttl
120
- });
121
- let submitKey;
122
- let finalFeeConfig;
123
- switch (topicType) {
124
- case InboundTopicType.PUBLIC:
125
- submitKey = false;
126
- break;
127
- case InboundTopicType.CONTROLLED:
128
- submitKey = true;
129
- break;
130
- case InboundTopicType.FEE_BASED:
131
- submitKey = false;
132
- if (!feeConfigBuilder) {
133
- throw new Error(
134
- "Fee configuration builder is required for fee-based topics"
135
- );
136
- }
137
- const internalFees = feeConfigBuilder.customFees;
138
- internalFees.forEach((fee) => {
139
- if (!fee.feeCollectorAccountId) {
140
- fee.feeCollectorAccountId = accountId;
141
- }
142
- });
143
- finalFeeConfig = feeConfigBuilder.build();
144
- finalFeeConfig.customFees = finalFeeConfig.customFees.map((f) => ({
145
- ...f,
146
- feeCollectorAccountId: f.feeCollectorAccountId || accountId
147
- }));
148
- break;
149
- default:
150
- throw new Error(`Unsupported inbound topic type: ${topicType}`);
135
+ async getPublicKey(accountId) {
136
+ return await this.mirrorNode.getPublicKey(accountId);
137
+ }
138
+ async handleConnectionRequest(inboundTopicId, requestingAccountId, connectionId, connectionMemo = "Connection accepted. Looking forward to collaborating!", ttl = 60) {
139
+ this.logger.info("Handling connection request");
140
+ const userAccountId = this.hwc.getAccountInfo().accountId;
141
+ if (!userAccountId) {
142
+ throw new Error("Failed to retrieve user account ID");
151
143
  }
152
- const operatorPublicKey = this.client.operatorPublicKey || this.operatorCtx.operatorKey.publicKey;
153
- const transaction = buildHcs10CreateInboundTopicTx({
154
- accountId,
144
+ const requesterKey = await this.mirrorNode.getPublicKey(requestingAccountId);
145
+ const accountKey = await this.mirrorNode.getPublicKey(userAccountId);
146
+ if (!accountKey) {
147
+ throw new Error("Failed to retrieve public key");
148
+ }
149
+ const thresholdKey = new KeyList([accountKey, requesterKey], 1);
150
+ const memo = this._generateHcs10Memo(Hcs10MemoType.CONNECTION, {
155
151
  ttl,
156
- adminKey: true,
157
- submitKey,
158
- operatorPublicKey
152
+ inboundTopicId,
153
+ connectionId
159
154
  });
160
- this.logger.info("Creating inbound topic");
161
- const { topicId } = await this.executeTopicCreateTransaction({
155
+ const transaction = new TopicCreateTransaction().setTopicMemo(memo).setAutoRenewAccountId(AccountId.fromString(userAccountId)).setAdminKey(thresholdKey).setSubmitKey(thresholdKey);
156
+ this.logger.debug("Executing topic creation transaction");
157
+ const txResponse = await this.hwc.executeTransactionWithErrorHandling(
162
158
  transaction,
163
- feeConfig: finalFeeConfig
159
+ false
160
+ );
161
+ if (txResponse?.error) {
162
+ this.logger.error(txResponse.error);
163
+ throw new Error(txResponse.error);
164
+ }
165
+ const resultReceipt = txResponse?.result;
166
+ if (!resultReceipt?.topicId) {
167
+ this.logger.error("Failed to create topic: topicId is null");
168
+ throw new Error("Failed to create topic: topicId is null");
169
+ }
170
+ const connectionTopicId = resultReceipt.topicId.toString();
171
+ const operatorId = `${inboundTopicId}@${userAccountId}`;
172
+ const confirmedConnectionSequenceNumber = await this.confirmConnection(
173
+ inboundTopicId,
174
+ connectionTopicId,
175
+ requestingAccountId,
176
+ connectionId,
177
+ operatorId,
178
+ connectionMemo
179
+ );
180
+ const accountTopics = await this.retrieveCommunicationTopics(userAccountId);
181
+ const requestingAccountTopics = await this.retrieveCommunicationTopics(requestingAccountId);
182
+ const requestingAccountOperatorId = `${requestingAccountTopics.inboundTopic}@${requestingAccountId}`;
183
+ await this.recordOutboundConnectionConfirmation({
184
+ outboundTopicId: accountTopics.outboundTopic,
185
+ requestorOutboundTopicId: requestingAccountTopics.outboundTopic,
186
+ connectionRequestId: connectionId,
187
+ confirmedRequestId: confirmedConnectionSequenceNumber,
188
+ connectionTopicId,
189
+ operatorId: requestingAccountOperatorId,
190
+ memo: `Connection established with ${requestingAccountId}`
164
191
  });
165
- return topicId;
192
+ return {
193
+ connectionTopicId,
194
+ confirmedConnectionSequenceNumber,
195
+ operatorId
196
+ };
166
197
  }
167
- /**
168
- * Creates a new agent with inbound and outbound topics
169
- * @param builder The agent builder object
170
- * @param ttl Optional Time-To-Live for the topic memos, defaults to 60
171
- * @param existingState Optional existing state to resume from
172
- * @returns Object with topic IDs
173
- */
174
- async createAgent(builder, ttl = 60, existingState, progressCallback) {
175
- await this.ensureInitialized();
176
- const config = builder.build();
177
- const accountId = this.client.operatorAccountId?.toString();
178
- if (!accountId) {
179
- throw new Error("Failed to retrieve operator account ID");
180
- }
181
- const result = await this._createEntityTopics(
182
- ttl,
183
- {
184
- outboundTopicId: existingState?.outboundTopicId || "",
185
- inboundTopicId: existingState?.inboundTopicId || "",
186
- pfpTopicId: existingState?.pfpTopicId || config.existingPfpTopicId || "",
187
- profileTopicId: existingState?.profileTopicId || ""
188
- },
189
- accountId,
190
- config.inboundTopicType,
191
- config.feeConfig,
192
- config.pfpBuffer,
193
- config.pfpFileName,
194
- progressCallback
198
+ async confirmConnection(inboundTopicId, connectionTopicId, connectedAccountId, connectionId, operatorId, memo) {
199
+ this.logger.info("Confirming connection");
200
+ const payload = {
201
+ p: "hcs-10",
202
+ op: "connection_created",
203
+ connection_topic_id: connectionTopicId,
204
+ connected_account_id: connectedAccountId,
205
+ operator_id: operatorId,
206
+ connection_id: connectionId,
207
+ m: memo
208
+ };
209
+ const transactionResponse = await this.submitPayload(
210
+ inboundTopicId,
211
+ payload
195
212
  );
196
- if (!result.profileTopicId) {
197
- if (progressCallback) {
198
- progressCallback({
199
- stage: "preparing",
200
- message: "Creating agent profile",
201
- progressPercent: 60,
202
- details: {
203
- outboundTopicId: result.outboundTopicId,
204
- inboundTopicId: result.inboundTopicId,
205
- pfpTopicId: result.pfpTopicId,
206
- state: {
207
- currentStage: "profile",
208
- completedPercentage: 60
209
- }
210
- }
211
- });
212
- }
213
- const profileResult = await this.storeHCS11Profile(
214
- config.name,
215
- config.bio,
216
- result.inboundTopicId,
217
- result.outboundTopicId,
218
- config.capabilities,
219
- config.metadata,
220
- config.pfpBuffer && config.pfpBuffer.length > 0 && !result.pfpTopicId ? config.pfpBuffer : void 0,
221
- config.pfpFileName,
222
- result.pfpTopicId
223
- );
224
- result.profileTopicId = profileResult.profileTopicId;
225
- this.logger.info(
226
- `Profile stored with topic ID: ${result.profileTopicId}`
227
- );
228
- if (progressCallback) {
229
- progressCallback({
230
- stage: "preparing",
231
- message: "Agent profile created",
232
- progressPercent: 70,
233
- details: {
234
- outboundTopicId: result.outboundTopicId,
235
- inboundTopicId: result.inboundTopicId,
236
- pfpTopicId: result.pfpTopicId,
237
- profileTopicId: result.profileTopicId,
238
- state: {
239
- currentStage: "profile",
240
- completedPercentage: 70
241
- }
242
- }
243
- });
244
- }
245
- } else {
246
- this.logger.info(
247
- `Using existing profile topic ID: ${result.profileTopicId}`
213
+ if (!transactionResponse?.topicSequenceNumber) {
214
+ this.logger.error(
215
+ "Failed to confirm connection: sequence number is null"
248
216
  );
217
+ throw new Error("Failed to confirm connection: sequence number is null");
249
218
  }
250
- return result;
219
+ return transactionResponse.topicSequenceNumber.toNumber();
251
220
  }
252
- /**
253
- * Creates a profile (person or agent) with HCS-10 topics and HCS-11 profile.
254
- * This method provides a unified interface for creating both person and agent profiles.
255
- *
256
- * @param builder - AgentBuilder or PersonBuilder instance
257
- * @param options - Optional configuration including progress callback and state
258
- * @returns Promise resolving to profile creation result
259
- */
260
221
  async create(builder, options) {
261
222
  const progressCallback = options?.progressCallback;
262
223
  const progressReporter = new ProgressReporter({
263
224
  module: "ProfileCreate",
264
225
  logger: this.logger,
265
- callback: progressCallback ? (d) => progressCallback({
266
- stage: d.stage,
267
- message: d.message,
268
- progressPercent: d.progressPercent,
269
- details: d.details
270
- }) : void 0
226
+ callback: progressCallback
271
227
  });
272
228
  try {
273
229
  const isAgentBuilder = builder instanceof AgentBuilder;
@@ -295,19 +251,11 @@ class HCS10Client extends HCS10BaseClient {
295
251
  state
296
252
  }
297
253
  );
298
- const accountId = this.client.operatorAccountId?.toString();
299
- if (!accountId) {
300
- throw new Error("Failed to retrieve operator account ID");
301
- }
302
254
  const {
303
255
  inboundTopicId,
304
256
  outboundTopicId,
305
257
  state: updatedState
306
- } = await this.createCommunicationTopics(
307
- accountId,
308
- options,
309
- progressReporter
310
- );
258
+ } = await this.createCommunicationTopics(options, progressReporter);
311
259
  state = updatedState;
312
260
  builder.setInboundTopicId(inboundTopicId);
313
261
  builder.setOutboundTopicId(outboundTopicId);
@@ -405,1289 +353,57 @@ class HCS10Client extends HCS10BaseClient {
405
353
  };
406
354
  }
407
355
  }
408
- /**
409
- * Inscribes a profile picture to Hedera
410
- * @param buffer Profile picture buffer
411
- * @param fileName Filename
412
- * @returns Response with topic ID and transaction ID
413
- */
414
- async inscribePfp(buffer, fileName) {
415
- try {
416
- this.logger.info("Inscribing profile picture using HCS-11 client");
417
- const imageResult = await this.hcs11Client.inscribeImage(
418
- buffer,
419
- fileName
420
- );
421
- if (!imageResult.success) {
422
- this.logger.error(
423
- `Failed to inscribe profile picture: ${imageResult.error}`
424
- );
425
- throw new Error(
426
- imageResult?.error || "Failed to inscribe profile picture"
427
- );
356
+ async handleProfilePictureCreation(pfpBuffer, pfpFileName, state, progressReporter) {
357
+ state.currentStage = "pfp";
358
+ progressReporter.preparing("Creating profile picture", 30, {
359
+ state
360
+ });
361
+ const pfpProgress = progressReporter.createSubProgress({
362
+ minPercent: 30,
363
+ maxPercent: 50,
364
+ logPrefix: "PFP"
365
+ });
366
+ const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName, {
367
+ progressCallback: (data) => pfpProgress.report({
368
+ ...data,
369
+ progressPercent: data.progressPercent ?? 0,
370
+ details: { ...data.details, state }
371
+ })
372
+ });
373
+ if (!pfpResult.success) {
374
+ let errorMessage = "Failed to inscribe profile picture";
375
+ if (pfpResult.error) {
376
+ errorMessage = pfpResult.error;
428
377
  }
429
- this.logger.info(
430
- `Successfully inscribed profile picture with topic ID: ${imageResult.imageTopicId}`
431
- );
432
- return {
433
- pfpTopicId: imageResult.imageTopicId,
434
- transactionId: imageResult.transactionId,
435
- success: true
436
- };
437
- } catch (e) {
438
- const error = e;
439
- const logMessage = `Error inscribing profile picture: ${error.message}`;
440
- this.logger.error(logMessage);
441
- return {
442
- pfpTopicId: "",
443
- transactionId: "",
444
- success: false,
445
- error: error.message
446
- };
378
+ throw new Error(errorMessage);
379
+ }
380
+ const pfpTopicId = pfpResult.pfpTopicId;
381
+ state.pfpTopicId = pfpTopicId;
382
+ if (state.createdResources) {
383
+ state.createdResources.push(`pfp:${state.pfpTopicId}`);
447
384
  }
385
+ progressReporter.preparing("Profile picture created", 50, { state });
386
+ return pfpTopicId;
448
387
  }
449
- /**
450
- * Stores an HCS-11 profile for an agent
451
- * @param agentName Agent name
452
- * @param agentBio Agent description
453
- * @param inboundTopicId Inbound topic ID
454
- * @param outboundTopicId Outbound topic ID
455
- * @param capabilities Agent capability tags
456
- * @param metadata Additional metadata
457
- * @param pfpBuffer Optional profile picture buffer
458
- * @param pfpFileName Optional profile picture filename
459
- * @returns Response with topic IDs and transaction ID
460
- */
461
- async storeHCS11Profile(agentName, agentBio, inboundTopicId, outboundTopicId, capabilities = [], metadata, pfpBuffer, pfpFileName, existingPfpTopicId) {
462
- try {
463
- let pfpTopicId = existingPfpTopicId || "";
464
- if (!pfpTopicId && pfpBuffer && pfpFileName) {
465
- this.logger.info("Inscribing profile picture for HCS-11 profile");
466
- const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName);
467
- if (!pfpResult.success) {
468
- this.logger.warn(
469
- `Failed to inscribe profile picture: ${pfpResult.error}, proceeding without pfp`
470
- );
471
- } else {
472
- pfpTopicId = pfpResult.pfpTopicId;
473
- }
474
- } else if (existingPfpTopicId) {
475
- this.logger.info(
476
- `Using existing profile picture with topic ID: ${existingPfpTopicId} for HCS-11 profile`
388
+ async createAndInscribeProfile(isAgentBuilder, builder, pfpTopicId, state, inboundTopicId, outboundTopicId, options, progressReporter) {
389
+ if (!this.hcs11Client) {
390
+ if (progressReporter) {
391
+ progressReporter.failed("HCS11Client is not available");
392
+ }
393
+ throw new Error("HCS11Client is not available");
394
+ }
395
+ this.logger.info("Creating and inscribing profile");
396
+ if (!state.profileTopicId) {
397
+ if (progressReporter) {
398
+ progressReporter.preparing(
399
+ `Storing HCS-11 ${isAgentBuilder ? "agent" : "person"} profile`,
400
+ 80
477
401
  );
478
- pfpTopicId = existingPfpTopicId;
479
402
  }
480
- const agentType = this.hcs11Client.getAgentTypeFromMetadata({
481
- type: metadata.type || "autonomous"
482
- });
483
- const formattedSocials = metadata.socials ? Object.entries(metadata.socials).filter(([_, handle]) => handle).map(([platform, handle]) => ({
484
- platform,
485
- handle
486
- })) : void 0;
487
- const profile = this.hcs11Client.createAIAgentProfile(
488
- agentName,
489
- agentType,
490
- capabilities,
491
- metadata.model || "unknown",
492
- {
493
- alias: agentName.toLowerCase().replace(/\s+/g, "_"),
494
- bio: agentBio,
495
- profileImage: pfpTopicId ? `hcs://1/${pfpTopicId}` : void 0,
496
- socials: formattedSocials,
497
- properties: metadata.properties,
498
- inboundTopicId,
499
- outboundTopicId,
500
- creator: metadata.creator
501
- }
502
- );
503
- const profileResult = await this.hcs11Client.createAndInscribeProfile(
504
- profile,
505
- true
506
- );
507
- if (!profileResult.success) {
508
- this.logger.error(`Failed to inscribe profile: ${profileResult.error}`);
509
- throw new Error(profileResult.error || "Failed to inscribe profile");
510
- }
511
- this.logger.info(
512
- `Profile inscribed with topic ID: ${profileResult.profileTopicId}, transaction ID: ${profileResult.transactionId}`
513
- );
514
- return {
515
- profileTopicId: profileResult.profileTopicId,
516
- pfpTopicId,
517
- transactionId: profileResult.transactionId,
518
- success: true
519
- };
520
- } catch (e) {
521
- const error = e;
522
- const logMessage = `Error storing HCS-11 profile: ${error.message}`;
523
- this.logger.error(logMessage);
524
- return {
525
- profileTopicId: "",
526
- pfpTopicId: "",
527
- transactionId: "",
528
- success: false,
529
- error: error.message
530
- };
531
- }
532
- }
533
- async setupFees(transaction, feeConfig, additionalExemptAccounts = []) {
534
- let modifiedTransaction = transaction;
535
- if (!this.client.operatorPublicKey) {
536
- return modifiedTransaction;
537
- }
538
- if (!feeConfig.customFees || feeConfig.customFees.length === 0) {
539
- this.logger.warn("No custom fees provided in fee config for setupFees");
540
- return modifiedTransaction;
541
- }
542
- if (feeConfig.customFees.length > 10) {
543
- this.logger.warn(
544
- "More than 10 custom fees provided, only the first 10 will be used"
545
- );
546
- feeConfig.customFees = feeConfig.customFees.slice(0, 10);
547
- }
548
- const customFees = feeConfig.customFees.map((fee) => {
549
- if (!fee.feeCollectorAccountId) {
550
- this.logger.error(
551
- "Internal Error: Fee collector ID missing in setupFees"
552
- );
553
- return null;
554
- }
555
- if (fee.type === "FIXED_FEE") {
556
- const customFee = new CustomFixedFee().setAmount(Number(fee.feeAmount.amount)).setFeeCollectorAccountId(
557
- AccountId.fromString(fee.feeCollectorAccountId)
558
- );
559
- if (fee.feeTokenId) {
560
- customFee.setDenominatingTokenId(
561
- TokenId.fromString(fee.feeTokenId)
562
- );
563
- }
564
- return customFee;
565
- }
566
- return null;
567
- }).filter(Boolean);
568
- if (customFees.length === 0) {
569
- this.logger.warn("No valid custom fees to apply in setupFees");
570
- return modifiedTransaction;
571
- }
572
- const exemptAccountIds = [
573
- ...feeConfig.exemptAccounts || [],
574
- ...additionalExemptAccounts
575
- ];
576
- if (exemptAccountIds.length > 0) {
577
- modifiedTransaction = await this.setupExemptKeys(
578
- transaction,
579
- exemptAccountIds
580
- );
581
- }
582
- return modifiedTransaction.setFeeScheduleKey(this.client.operatorPublicKey).setCustomFees(customFees);
583
- }
584
- async setupExemptKeys(transaction, exemptAccountIds) {
585
- let modifiedTransaction = transaction;
586
- const uniqueExemptAccountIds = Array.from(new Set(exemptAccountIds));
587
- const filteredExemptAccounts = uniqueExemptAccountIds.filter(
588
- (account) => account !== this.client.operatorAccountId?.toString()
589
- );
590
- let exemptKeys = [];
591
- if (filteredExemptAccounts.length > 0) {
592
- try {
593
- exemptKeys = await accountIdsToExemptKeys(
594
- filteredExemptAccounts,
595
- this.network,
596
- this.logger
597
- );
598
- } catch (e) {
599
- const error = e;
600
- const logMessage = `Error getting exempt keys: ${error.message}, continuing without exempt keys`;
601
- this.logger.warn(logMessage);
602
- }
603
- }
604
- if (exemptKeys.length > 0) {
605
- modifiedTransaction = modifiedTransaction.setFeeExemptKeys(exemptKeys);
606
- }
607
- return modifiedTransaction;
608
- }
609
- /**
610
- * Handles a connection request from another account
611
- * @param inboundTopicId Inbound topic ID of your agent
612
- * @param requestingAccountId Requesting account ID
613
- * @param connectionRequestId Connection request ID
614
- * @param connectionFeeConfig Optional fee configuration for the connection topic
615
- * @param ttl Optional ttl parameter with default
616
- * @returns Response with connection details
617
- */
618
- async handleConnectionRequest(inboundTopicId, requestingAccountId, connectionRequestId, connectionFeeConfig, ttl = 60) {
619
- this.logger.info(
620
- `Handling connection request ${connectionRequestId} from ${requestingAccountId}`
621
- );
622
- const accountId = this.getClient().operatorAccountId?.toString();
623
- if (!accountId) {
624
- throw new Error("Failed to retrieve operator account ID");
625
- }
626
- let requesterKey = await this.mirrorNode.getPublicKey(requestingAccountId);
627
- const accountKey = await this.mirrorNode.getPublicKey(accountId);
628
- if (!accountKey) {
629
- throw new Error("Failed to retrieve public key");
630
- }
631
- const thresholdKey = new KeyList([accountKey, requesterKey], 1);
632
- let connectionTopicId;
633
- try {
634
- const connectionTransaction = buildHcs10CreateConnectionTopicTx({
635
- ttl,
636
- inboundTopicId,
637
- connectionId: connectionRequestId,
638
- adminKey: thresholdKey,
639
- submitKey: thresholdKey
640
- });
641
- if (connectionFeeConfig) {
642
- const feeConfig = connectionFeeConfig.build();
643
- const modifiedFeeConfig = {
644
- ...feeConfig,
645
- exemptAccounts: [...feeConfig.exemptAccounts || []]
646
- };
647
- const { topicId } = await this.executeTopicCreateTransaction({
648
- transaction: connectionTransaction,
649
- feeConfig: modifiedFeeConfig
650
- });
651
- connectionTopicId = topicId;
652
- } else {
653
- const { topicId } = await this.executeTopicCreateTransaction({
654
- transaction: connectionTransaction
655
- });
656
- connectionTopicId = topicId;
657
- }
658
- this.logger.info(`Created new connection topic ID: ${connectionTopicId}`);
659
- } catch (error) {
660
- const logMessage = `Failed to create connection topic: ${error}`;
661
- this.logger.error(logMessage);
662
- throw new TopicCreationError(logMessage);
663
- }
664
- const operatorId = `${inboundTopicId}@${accountId}`;
665
- const confirmedConnectionSequenceNumber = await this.confirmConnection(
666
- inboundTopicId,
667
- connectionTopicId,
668
- requestingAccountId,
669
- connectionRequestId,
670
- "Connection accepted. Looking forward to collaborating!"
671
- );
672
- const accountTopics = await this.retrieveCommunicationTopics(accountId);
673
- const requestingAccountTopics = await this.retrieveCommunicationTopics(requestingAccountId);
674
- const requestingAccountOperatorId = `${requestingAccountTopics.inboundTopic}@${requestingAccountId}`;
675
- await this.recordOutboundConnectionConfirmation({
676
- outboundTopicId: accountTopics.outboundTopic,
677
- requestorOutboundTopicId: requestingAccountTopics.outboundTopic,
678
- connectionRequestId,
679
- confirmedRequestId: confirmedConnectionSequenceNumber,
680
- connectionTopicId,
681
- operatorId: requestingAccountOperatorId,
682
- memo: `Connection established with ${requestingAccountId}`
683
- });
684
- return {
685
- connectionTopicId,
686
- confirmedConnectionSequenceNumber,
687
- operatorId
688
- };
689
- }
690
- /**
691
- * Confirms a connection request from another account
692
- * @param inboundTopicId Inbound topic ID
693
- * @param connectionTopicId Connection topic ID
694
- * @param connectedAccountId Connected account ID
695
- * @param connectionId Connection ID
696
- * @param memo Memo for the connection request
697
- * @param submitKey Optional submit key
698
- * @returns Sequence number of the confirmed connection
699
- */
700
- async confirmConnection(inboundTopicId, connectionTopicId, connectedAccountId, connectionId, memo, submitKey) {
701
- const operatorId = await this.getOperatorId();
702
- this.logger.info(`Confirming connection with ID ${connectionId}`);
703
- const submissionCheck = await this.canSubmitToTopic(
704
- inboundTopicId,
705
- this.client.operatorAccountId?.toString() || ""
706
- );
707
- const transaction = buildHcs10ConfirmConnectionTx({
708
- inboundTopicId,
709
- connectionTopicId,
710
- connectedAccountId,
711
- operatorId,
712
- connectionId,
713
- memo
714
- });
715
- const result = await this.submitPayload(
716
- transaction,
717
- void 0,
718
- submitKey,
719
- submissionCheck.requiresFee
720
- );
721
- const sequenceNumber = result.topicSequenceNumber?.toNumber();
722
- if (!sequenceNumber) {
723
- throw new ConnectionConfirmationError(
724
- "Failed to confirm connection: sequence number is null"
725
- );
726
- }
727
- return sequenceNumber;
728
- }
729
- async sendMessage(connectionTopicId, data, memo, submitKey, options) {
730
- const submissionCheck = await this.canSubmitToTopic(
731
- connectionTopicId,
732
- this.client.operatorAccountId?.toString() || ""
733
- );
734
- const operatorId = await this.getOperatorId();
735
- const payload = {
736
- p: "hcs-10",
737
- op: "message",
738
- operator_id: operatorId,
739
- data,
740
- m: memo
741
- };
742
- const payloadString = JSON.stringify(payload);
743
- const isLargePayload = Buffer.from(payloadString).length > 1e3;
744
- if (isLargePayload) {
745
- this.logger.info(
746
- "Message payload exceeds 1000 bytes, storing via inscription"
747
- );
748
- try {
749
- const contentBuffer = Buffer.from(data);
750
- const fileName = `message-${Date.now()}.json`;
751
- const inscriptionResult = await this.inscribeFile(
752
- contentBuffer,
753
- fileName,
754
- {
755
- progressCallback: options?.progressCallback,
756
- waitMaxAttempts: options?.waitMaxAttempts,
757
- waitIntervalMs: options?.waitIntervalMs
758
- }
759
- );
760
- if (getTopicId(inscriptionResult)) {
761
- payload.data = `hcs://1/${getTopicId(inscriptionResult)}`;
762
- this.logger.info(
763
- `Large message inscribed with topic ID: ${getTopicId(inscriptionResult)}`
764
- );
765
- } else {
766
- throw new Error("Failed to inscribe large message content");
767
- }
768
- } catch (error) {
769
- const err = error;
770
- const logMessage = `Error inscribing large message: ${err.message}`;
771
- this.logger.error(logMessage);
772
- throw new Error(logMessage);
773
- }
774
- }
775
- this.logger.info("Submitting message to connection topic", payload);
776
- const transaction = buildHcs10SendMessageTx({
777
- connectionTopicId,
778
- operatorId,
779
- data: payload.data,
780
- memo
781
- });
782
- return await this.submitPayload(
783
- transaction,
784
- void 0,
785
- submitKey,
786
- submissionCheck.requiresFee
787
- );
788
- }
789
- async executeTopicCreateTransaction(params) {
790
- let workingTransaction = params.transaction;
791
- if (params.feeConfig) {
792
- workingTransaction = await this.setupFees(
793
- workingTransaction,
794
- params.feeConfig,
795
- params.additionalExemptAccounts || []
796
- );
797
- }
798
- try {
799
- const response = await workingTransaction.execute(this.client);
800
- const receipt = await response.getReceipt(this.client);
801
- if (!receipt.topicId) {
802
- this.logger.error("Failed to create topic: topicId is null");
803
- throw new Error("Failed to create topic: topicId is null");
804
- }
805
- return {
806
- topicId: receipt.topicId.toString(),
807
- receipt,
808
- response
809
- };
810
- } catch (error) {
811
- this.logger.error("Topic creation failed", {
812
- error: error.message,
813
- transactionId: error.transactionId?.toString(),
814
- operatorId: this.client.operatorAccountId?.toString()
815
- });
816
- throw error;
817
- }
818
- }
819
- async createTopic(memo, adminKey, submitKey, feeConfig) {
820
- this.logger.info("Creating topic");
821
- const transaction = buildTopicCreateTx({
822
- memo,
823
- adminKey,
824
- submitKey,
825
- operatorPublicKey: this.client.operatorPublicKey || this.operatorCtx.operatorKey?.publicKey
826
- });
827
- const { topicId } = await this.executeTopicCreateTransaction({
828
- transaction,
829
- feeConfig
830
- });
831
- return topicId;
832
- }
833
- async submitPayload(topicOrTransaction, payload, submitKey, requiresFee = false) {
834
- const isTransaction = topicOrTransaction instanceof TopicMessageSubmitTransaction || typeof topicOrTransaction !== "string" && typeof topicOrTransaction.getMessage === "function";
835
- if (isTransaction) {
836
- const transaction2 = topicOrTransaction instanceof TopicMessageSubmitTransaction ? topicOrTransaction : topicOrTransaction;
837
- const messageBytes = transaction2.getMessage();
838
- if (!messageBytes) {
839
- throw new Error("Message payload is missing");
840
- }
841
- const payloadSizeInBytes2 = Buffer.from(messageBytes).length;
842
- if (payloadSizeInBytes2 > 1e3) {
843
- throw new PayloadSizeError(
844
- "Payload size exceeds 1000 bytes limit",
845
- payloadSizeInBytes2
846
- );
847
- }
848
- if (requiresFee) {
849
- this.logger.info(
850
- "Topic requires fee payment, setting max transaction fee"
851
- );
852
- transaction2.setMaxTransactionFee(new Hbar(this.feeAmount));
853
- }
854
- let transactionResponse2;
855
- if (submitKey) {
856
- const frozenTransaction = transaction2.freezeWith(this.client);
857
- const signedTransaction = await frozenTransaction.sign(submitKey);
858
- transactionResponse2 = await signedTransaction.execute(this.client);
859
- } else {
860
- transactionResponse2 = await transaction2.execute(this.client);
861
- }
862
- const receipt2 = await transactionResponse2.getReceipt(this.client);
863
- if (!receipt2) {
864
- this.logger.error("Failed to submit message: receipt is null");
865
- throw new Error("Failed to submit message: receipt is null");
866
- }
867
- this.logger.info("Message submitted successfully");
868
- return receipt2;
869
- }
870
- const message = typeof payload === "string" ? payload : JSON.stringify(payload);
871
- const payloadSizeInBytes = Buffer.byteLength(message, "utf8");
872
- if (payloadSizeInBytes > 1e3) {
873
- throw new PayloadSizeError(
874
- "Payload size exceeds 1000 bytes limit",
875
- payloadSizeInBytes
876
- );
877
- }
878
- const transactionMemo = this.getHcs10TransactionMemo(payload);
879
- const transaction = buildMessageTx({
880
- topicId: topicOrTransaction,
881
- message,
882
- transactionMemo: transactionMemo || void 0
883
- });
884
- if (requiresFee) {
885
- this.logger.info(
886
- "Topic requires fee payment, setting max transaction fee"
887
- );
888
- transaction.setMaxTransactionFee(new Hbar(this.feeAmount));
889
- }
890
- let transactionResponse;
891
- if (submitKey) {
892
- const frozenTransaction = transaction.freezeWith(this.client);
893
- const signedTransaction = await frozenTransaction.sign(submitKey);
894
- transactionResponse = await signedTransaction.execute(this.client);
895
- } else {
896
- transactionResponse = await transaction.execute(this.client);
897
- }
898
- const receipt = await transactionResponse.getReceipt(this.client);
899
- if (!receipt) {
900
- this.logger.error("Failed to submit message: receipt is null");
901
- throw new Error("Failed to submit message: receipt is null");
902
- }
903
- this.logger.info("Message submitted successfully");
904
- return receipt;
905
- }
906
- async inscribeFile(buffer, fileName, options) {
907
- this.logger.info("Inscribing file");
908
- if (!this.client.operatorAccountId) {
909
- this.logger.error("Operator account ID is not set");
910
- throw new Error("Operator account ID is not set");
911
- }
912
- if (!this.operatorCtx.operatorKey) {
913
- this.logger.error("Operator private key is not set");
914
- throw new Error("Operator private key is not set");
915
- }
916
- const mimeType = mime.lookup(fileName) || "application/octet-stream";
917
- const privateKey = this.operatorCtx.operatorKey;
918
- const sdk = await InscriptionSDK.createWithAuth({
919
- type: "server",
920
- accountId: this.client.operatorAccountId.toString(),
921
- privateKey,
922
- network: this.network
923
- });
924
- const inscriptionOptions = {
925
- mode: "file",
926
- waitForConfirmation: true,
927
- waitMaxAttempts: options?.waitMaxAttempts || 30,
928
- waitIntervalMs: options?.waitIntervalMs || 4e3,
929
- progressCallback: options?.progressCallback,
930
- logging: {
931
- level: this.logger.getLevel ? this.logger.getLevel() : "info"
932
- }
933
- };
934
- const response = await inscribe(
935
- {
936
- type: "buffer",
937
- buffer,
938
- fileName,
939
- mimeType
940
- },
941
- {
942
- accountId: this.client.operatorAccountId.toString(),
943
- privateKey,
944
- network: this.network
945
- },
946
- inscriptionOptions,
947
- sdk
948
- );
949
- if (!response.confirmed || !response.inscription) {
950
- throw new Error("Inscription was not confirmed");
951
- }
952
- return response.inscription;
953
- }
954
- /**
955
- * Waits for confirmation of a connection request
956
- * @param inboundTopicId Inbound topic ID
957
- * @param connectionRequestId Connection request ID
958
- * @param maxAttempts Maximum number of attempts
959
- * @param delayMs Delay between attempts in milliseconds
960
- * @returns Connection confirmation details
961
- */
962
- async waitForConnectionConfirmation(inboundTopicId, connectionRequestId, maxAttempts = 60, delayMs = 2e3, recordConfirmation = true) {
963
- this.logger.info(
964
- `Waiting for connection confirmation on inbound topic ${inboundTopicId} for request ID ${connectionRequestId}`
965
- );
966
- for (let attempt = 0; attempt < maxAttempts; attempt++) {
967
- this.logger.info(
968
- `Attempt ${attempt + 1}/${maxAttempts} to find connection confirmation`
969
- );
970
- const messages = await this.mirrorNode.getTopicMessages(inboundTopicId);
971
- const connectionCreatedMessages = messages.filter(
972
- (m) => m.op === "connection_created"
973
- );
974
- this.logger.info(
975
- `Found ${connectionCreatedMessages.length} connection_created messages`
976
- );
977
- if (connectionCreatedMessages.length > 0) {
978
- for (const message of connectionCreatedMessages) {
979
- if (Number(message.connection_id) === Number(connectionRequestId)) {
980
- const confirmationResult = {
981
- connectionTopicId: message.connection_topic_id,
982
- sequence_number: Number(message.sequence_number),
983
- confirmedBy: message.operator_id,
984
- memo: message.m
985
- };
986
- const confirmedByAccountId = this.extractAccountFromOperatorId(
987
- confirmationResult.confirmedBy
988
- );
989
- const account = this.getAccountAndSigner();
990
- const confirmedByConnectionTopics = await this.retrieveCommunicationTopics(confirmedByAccountId);
991
- const agentConnectionTopics = await this.retrieveCommunicationTopics(account.accountId);
992
- this.logger.info(
993
- "Connection confirmation found",
994
- confirmationResult
995
- );
996
- if (recordConfirmation) {
997
- await this.recordOutboundConnectionConfirmation({
998
- requestorOutboundTopicId: confirmedByConnectionTopics.outboundTopic,
999
- outboundTopicId: agentConnectionTopics.outboundTopic,
1000
- connectionRequestId,
1001
- confirmedRequestId: confirmationResult.sequence_number,
1002
- connectionTopicId: confirmationResult.connectionTopicId,
1003
- operatorId: confirmationResult.confirmedBy,
1004
- memo: confirmationResult.memo || "Connection confirmed"
1005
- });
1006
- }
1007
- return confirmationResult;
1008
- }
1009
- }
1010
- }
1011
- if (attempt < maxAttempts - 1) {
1012
- this.logger.info(
1013
- `No matching confirmation found, waiting ${delayMs}ms before retrying...`
1014
- );
1015
- await new Promise((resolve) => setTimeout(resolve, delayMs));
1016
- }
1017
- }
1018
- throw new Error(
1019
- `Connection confirmation not found after ${maxAttempts} attempts for request ID ${connectionRequestId}`
1020
- );
1021
- }
1022
- getAccountAndSigner() {
1023
- const PK = this.operatorCtx.operatorKey;
1024
- return {
1025
- accountId: this.client.operatorAccountId.toString(),
1026
- signer: PK
1027
- };
1028
- }
1029
- /**
1030
- * Creates and registers an agent with a Guarded registry.
1031
- *
1032
- * This function performs the following steps:
1033
- * 1. Creates a new account if no existing account is provided.
1034
- * 2. Initializes an HCS10 client with the new account.
1035
- * 3. Creates an agent on the client.
1036
- * 4. Registers the agent with the Hashgraph Online Guarded Registry.
1037
- *
1038
- * @param builder The agent builder object
1039
- * @param options Optional configuration including progress callback and state management
1040
- * @returns Agent registration result
1041
- */
1042
- async createAndRegisterAgent(builder, options) {
1043
- try {
1044
- const config = builder.build();
1045
- const progressCallback = options?.progressCallback;
1046
- const baseUrl = options?.baseUrl || this.guardedRegistryBaseUrl;
1047
- let state = options?.existingState || {
1048
- currentStage: "init",
1049
- completedPercentage: 0,
1050
- createdResources: []
1051
- };
1052
- state.agentMetadata = config.metadata;
1053
- if (progressCallback) {
1054
- progressCallback({
1055
- stage: "preparing",
1056
- message: "Starting agent creation process",
1057
- progressPercent: 0,
1058
- details: { state }
1059
- });
1060
- }
1061
- let account = config.existingAccount;
1062
- let agentClient;
1063
- if (!state.inboundTopicId || !state.outboundTopicId || !state.profileTopicId) {
1064
- if (!account) {
1065
- if (state.createdResources && state.createdResources.some((r) => r.startsWith("account:"))) {
1066
- const accountResource = state.createdResources.find(
1067
- (r) => r.startsWith("account:")
1068
- );
1069
- const existingAccountId = accountResource?.split(":")[1];
1070
- if (existingAccountId && config.existingAccount) {
1071
- account = config.existingAccount;
1072
- this.logger.info(
1073
- `Resuming with existing account: ${existingAccountId}`
1074
- );
1075
- } else {
1076
- account = await this.createAccount(options?.initialBalance);
1077
- state.createdResources = state.createdResources || [];
1078
- state.createdResources.push(`account:${account.accountId}`);
1079
- }
1080
- } else {
1081
- account = await this.createAccount(options?.initialBalance);
1082
- state.createdResources = state.createdResources || [];
1083
- state.createdResources.push(`account:${account.accountId}`);
1084
- }
1085
- }
1086
- if (progressCallback) {
1087
- progressCallback({
1088
- stage: "preparing",
1089
- message: "Created account or using existing account",
1090
- progressPercent: 20,
1091
- details: { state, account }
1092
- });
1093
- }
1094
- const resolver = new NodeOperatorResolver({
1095
- mirrorNode: this.mirrorNode,
1096
- logger: this.logger
1097
- });
1098
- const keyInfo = await resolver.resolveOperatorKey(
1099
- account.accountId,
1100
- account.privateKey
1101
- );
1102
- const publicKey = keyInfo.privateKey.publicKey.toString();
1103
- agentClient = new HCS10Client({
1104
- network: config.network,
1105
- operatorId: account.accountId,
1106
- operatorPrivateKey: keyInfo.privateKey.toString(),
1107
- operatorPublicKey: publicKey,
1108
- keyType: keyInfo.keyType,
1109
- logLevel: "info",
1110
- guardedRegistryBaseUrl: baseUrl
1111
- });
1112
- if (progressCallback) {
1113
- progressCallback({
1114
- stage: "preparing",
1115
- message: "Initialized agent client",
1116
- progressPercent: 25,
1117
- details: { state }
1118
- });
1119
- }
1120
- let outboundTopicId = state.outboundTopicId;
1121
- let inboundTopicId = state.inboundTopicId;
1122
- let pfpTopicId = state.pfpTopicId;
1123
- let profileTopicId = state.profileTopicId;
1124
- if (!outboundTopicId || !inboundTopicId || !profileTopicId) {
1125
- if (pfpTopicId) {
1126
- builder.setExistingProfilePicture(pfpTopicId);
1127
- }
1128
- const createResult = await agentClient.createAgent(
1129
- builder,
1130
- 60,
1131
- state,
1132
- (data) => {
1133
- if (progressCallback) {
1134
- progressCallback({
1135
- stage: data.stage,
1136
- message: data.message,
1137
- progressPercent: data.progressPercent || 0,
1138
- details: {
1139
- ...data.details,
1140
- state: {
1141
- ...state,
1142
- ...data.details?.state
1143
- }
1144
- }
1145
- });
1146
- }
1147
- }
1148
- );
1149
- outboundTopicId = createResult.outboundTopicId;
1150
- inboundTopicId = createResult.inboundTopicId;
1151
- pfpTopicId = createResult.pfpTopicId;
1152
- profileTopicId = createResult.profileTopicId;
1153
- state.outboundTopicId = outboundTopicId;
1154
- state.inboundTopicId = inboundTopicId;
1155
- state.pfpTopicId = pfpTopicId;
1156
- state.profileTopicId = profileTopicId;
1157
- if (!state.createdResources) {
1158
- state.createdResources = [];
1159
- }
1160
- if (pfpTopicId && !state.createdResources.includes(`pfp:${pfpTopicId}`)) {
1161
- state.createdResources.push(`pfp:${pfpTopicId}`);
1162
- }
1163
- if (!state.createdResources.includes(`inbound:${inboundTopicId}`)) {
1164
- state.createdResources.push(`inbound:${inboundTopicId}`);
1165
- }
1166
- if (!state.createdResources.includes(`outbound:${outboundTopicId}`)) {
1167
- state.createdResources.push(`outbound:${outboundTopicId}`);
1168
- }
1169
- if (!state.createdResources.includes(`profile:${profileTopicId}`)) {
1170
- state.createdResources.push(`profile:${profileTopicId}`);
1171
- }
1172
- }
1173
- state.currentStage = "profile";
1174
- state.completedPercentage = 60;
1175
- if (progressCallback) {
1176
- progressCallback({
1177
- stage: "submitting",
1178
- message: "Created agent with topics and profile",
1179
- progressPercent: 60,
1180
- details: {
1181
- state,
1182
- outboundTopicId,
1183
- inboundTopicId,
1184
- pfpTopicId,
1185
- profileTopicId
1186
- }
1187
- });
1188
- }
1189
- } else {
1190
- account = account || config.existingAccount;
1191
- if (!account) {
1192
- throw new Error(
1193
- "Cannot resume registration without account information"
1194
- );
1195
- }
1196
- const publicKey = this.operatorCtx.keyType === "ecdsa" ? PrivateKey.fromStringECDSA(
1197
- account.privateKey
1198
- ).publicKey.toString() : PrivateKey.fromStringED25519(
1199
- account.privateKey
1200
- ).publicKey.toString();
1201
- agentClient = new HCS10Client({
1202
- network: config.network,
1203
- operatorId: account.accountId,
1204
- operatorPrivateKey: account.privateKey,
1205
- operatorPublicKey: publicKey,
1206
- logLevel: "info",
1207
- guardedRegistryBaseUrl: baseUrl
1208
- });
1209
- this.logger.info("Resuming registration with existing state", {
1210
- inboundTopicId: state.inboundTopicId,
1211
- outboundTopicId: state.outboundTopicId,
1212
- profileTopicId: state.profileTopicId,
1213
- pfpTopicId: state.pfpTopicId
1214
- });
1215
- }
1216
- const operatorId = `${state.inboundTopicId}@${account.accountId}`;
1217
- if (state.currentStage !== "complete" || !state.createdResources?.includes(
1218
- `registration:${state.inboundTopicId}`
1219
- )) {
1220
- const registrationResult = await agentClient.registerAgentWithGuardedRegistry(
1221
- account.accountId,
1222
- config.network,
1223
- {
1224
- progressCallback: (data) => {
1225
- const adjustedPercent = 60 + (data.progressPercent || 0) * 0.4;
1226
- if (progressCallback) {
1227
- progressCallback({
1228
- stage: data.stage,
1229
- message: data.message,
1230
- progressPercent: adjustedPercent,
1231
- details: {
1232
- ...data.details,
1233
- outboundTopicId: state.outboundTopicId,
1234
- inboundTopicId: state.inboundTopicId,
1235
- pfpTopicId: state.pfpTopicId,
1236
- profileTopicId: state.profileTopicId,
1237
- operatorId,
1238
- state: data.details?.state || state
1239
- }
1240
- });
1241
- }
1242
- },
1243
- existingState: state
1244
- }
1245
- );
1246
- if (!registrationResult.success) {
1247
- return {
1248
- ...registrationResult,
1249
- state
1250
- };
1251
- }
1252
- state = registrationResult.state || state;
1253
- }
1254
- if (progressCallback) {
1255
- progressCallback({
1256
- stage: "completed",
1257
- message: "Agent creation and registration complete",
1258
- progressPercent: 100,
1259
- details: {
1260
- outboundTopicId: state.outboundTopicId,
1261
- inboundTopicId: state.inboundTopicId,
1262
- pfpTopicId: state.pfpTopicId,
1263
- profileTopicId: state.profileTopicId,
1264
- operatorId,
1265
- state
1266
- }
1267
- });
1268
- }
1269
- return {
1270
- success: true,
1271
- state,
1272
- metadata: {
1273
- accountId: account.accountId,
1274
- privateKey: account.privateKey,
1275
- operatorId,
1276
- inboundTopicId: state.inboundTopicId,
1277
- outboundTopicId: state.outboundTopicId,
1278
- profileTopicId: state.profileTopicId,
1279
- pfpTopicId: state.pfpTopicId
1280
- }
1281
- };
1282
- } catch (e) {
1283
- const error = e;
1284
- const logMessage = `Failed to create and register agent: ${error.message}`;
1285
- this.logger.error(logMessage);
1286
- return {
1287
- error: error.message,
1288
- success: false,
1289
- state: options?.existingState || {
1290
- currentStage: "init",
1291
- completedPercentage: 0,
1292
- error: error.message
1293
- }
1294
- };
1295
- }
1296
- }
1297
- /**
1298
- * Registers an agent with the guarded registry
1299
- * @param accountId Account ID to register
1300
- * @param inboundTopicId Inbound topic ID for the agent
1301
- * @param network Network type ('mainnet' or 'testnet')
1302
- * @param options Optional configuration including progress callback and confirmation settings
1303
- * @returns Registration result
1304
- */
1305
- async registerAgentWithGuardedRegistry(accountId, network = this.network, options) {
1306
- try {
1307
- this.logger.info("Registering agent with guarded registry");
1308
- const maxAttempts = options?.maxAttempts ?? 60;
1309
- const delayMs = options?.delayMs ?? 2e3;
1310
- const progressCallback = options?.progressCallback;
1311
- let state = options?.existingState || {
1312
- currentStage: "registration",
1313
- completedPercentage: 0,
1314
- createdResources: []
1315
- };
1316
- if (progressCallback) {
1317
- progressCallback({
1318
- stage: "preparing",
1319
- message: "Preparing agent registration",
1320
- progressPercent: 10,
1321
- details: {
1322
- state
1323
- }
1324
- });
1325
- }
1326
- const registrationResult = await this.executeRegistration(
1327
- accountId,
1328
- network,
1329
- this.guardedRegistryBaseUrl,
1330
- this.logger
1331
- );
1332
- if (!registrationResult.success) {
1333
- return {
1334
- ...registrationResult,
1335
- state
1336
- };
1337
- }
1338
- if (progressCallback) {
1339
- progressCallback({
1340
- stage: "submitting",
1341
- message: "Submitting registration to registry",
1342
- progressPercent: 30,
1343
- details: {
1344
- transactionId: registrationResult.transactionId,
1345
- state
1346
- }
1347
- });
1348
- }
1349
- if (registrationResult.transaction) {
1350
- const transaction = Transaction.fromBytes(
1351
- Buffer.from(registrationResult.transaction, "base64")
1352
- );
1353
- this.logger.info(`Processing registration transaction`);
1354
- await transaction.execute(this.client);
1355
- this.logger.info(`Successfully processed registration transaction`);
1356
- }
1357
- if (progressCallback) {
1358
- progressCallback({
1359
- stage: "confirming",
1360
- message: "Confirming registration transaction",
1361
- progressPercent: 60,
1362
- details: {
1363
- accountId,
1364
- transactionId: registrationResult.transactionId,
1365
- state
1366
- }
1367
- });
1368
- }
1369
- const confirmed = await this.waitForRegistrationConfirmation(
1370
- registrationResult.transactionId,
1371
- network,
1372
- this.guardedRegistryBaseUrl,
1373
- maxAttempts,
1374
- delayMs,
1375
- this.logger
1376
- );
1377
- state.currentStage = "complete";
1378
- state.completedPercentage = 100;
1379
- if (!state.createdResources) {
1380
- state.createdResources = [];
1381
- }
1382
- if (registrationResult.transactionId) {
1383
- state.createdResources.push(
1384
- `registration:${registrationResult.transactionId}`
1385
- );
1386
- }
1387
- if (progressCallback) {
1388
- progressCallback({
1389
- stage: "completed",
1390
- message: "Agent registration complete",
1391
- progressPercent: 100,
1392
- details: {
1393
- confirmed,
1394
- transactionId: registrationResult.transactionId,
1395
- state
1396
- }
1397
- });
1398
- }
1399
- return {
1400
- ...registrationResult,
1401
- confirmed,
1402
- state
1403
- };
1404
- } catch (e) {
1405
- const error = e;
1406
- const logMessage = `Failed to register agent: ${error.message}`;
1407
- this.logger.error(logMessage);
1408
- return {
1409
- error: error.message,
1410
- success: false
1411
- };
1412
- }
1413
- }
1414
- /**
1415
- * Registers an agent with the guarded registry. Should be called by a registry.
1416
- * @param registryTopicId - The topic ID of the guarded registry.
1417
- * @param accountId - The account ID of the agent
1418
- * @param inboundTopicId - The topic ID of the inbound topic
1419
- * @param memo - The memo of the agent
1420
- * @param submitKey - The submit key of the agent
1421
- */
1422
- async registerAgent(registryTopicId, accountId, inboundTopicId, memo, submitKey) {
1423
- this.logger.info("Registering agent");
1424
- const transaction = buildHcs10RegistryRegisterTx({
1425
- registryTopicId,
1426
- accountId,
1427
- inboundTopicId,
1428
- memo
1429
- });
1430
- await this.submitPayload(transaction, void 0, submitKey);
1431
- }
1432
- async getInboundTopicType(topicId) {
1433
- try {
1434
- const topicInfo = await this.mirrorNode.getTopicInfo(topicId);
1435
- if (!topicInfo) {
1436
- throw new Error("Topic does not exist");
1437
- }
1438
- const hasSubmitKey = topicInfo.submit_key && topicInfo.submit_key.key;
1439
- if (!hasSubmitKey) {
1440
- return InboundTopicType.PUBLIC;
1441
- }
1442
- const hasFeeScheduleKey = topicInfo.fee_schedule_key && topicInfo.fee_schedule_key.key;
1443
- if (hasFeeScheduleKey && topicInfo.custom_fees) {
1444
- const customFees = topicInfo.custom_fees;
1445
- if (customFees && customFees.fixed_fees && customFees.fixed_fees.length > 0) {
1446
- this.logger.info(
1447
- `Topic ${topicId} is fee-based with ${customFees.fixed_fees.length} custom fees`
1448
- );
1449
- return InboundTopicType.FEE_BASED;
1450
- }
1451
- }
1452
- return InboundTopicType.CONTROLLED;
1453
- } catch (e) {
1454
- const error = e;
1455
- const logMessage = `Error determining topic type: ${error.message}`;
1456
- this.logger.error(logMessage);
1457
- throw new Error(logMessage);
1458
- }
1459
- }
1460
- getNetwork() {
1461
- return this.network;
1462
- }
1463
- getLogger() {
1464
- return this.logger;
1465
- }
1466
- /**
1467
- * Public method to get the operator account ID configured for this client instance.
1468
- * @returns The operator account ID string, or null if not set.
1469
- */
1470
- getOperatorAccountId() {
1471
- return this.client.operatorAccountId?.toString() ?? null;
1472
- }
1473
- /**
1474
- * Creates a scheduled transaction from a transaction object
1475
- * @param transaction The transaction to schedule
1476
- * @param memo Optional memo to include with the scheduled transaction
1477
- * @param expirationTime Optional expiration time in seconds from now
1478
- * @returns Object with schedule ID and transaction ID
1479
- */
1480
- async createScheduledTransaction(transaction, memo, expirationTime, schedulePayerAccountId) {
1481
- this.logger.info("Creating scheduled transaction");
1482
- const scheduleTransaction = new ScheduleCreateTransaction().setScheduledTransaction(transaction).setPayerAccountId(
1483
- schedulePayerAccountId ? AccountId.fromString(schedulePayerAccountId) : this.client.operatorAccountId
1484
- );
1485
- if (memo) {
1486
- scheduleTransaction.setScheduleMemo(memo);
1487
- }
1488
- if (expirationTime) {
1489
- const expirationDate = addSeconds(/* @__PURE__ */ new Date(), expirationTime);
1490
- const timestamp = Timestamp.fromDate(expirationDate);
1491
- scheduleTransaction.setExpirationTime(timestamp);
1492
- }
1493
- const scheduleResponse = await scheduleTransaction.execute(this.client);
1494
- const scheduleReceipt = await scheduleResponse.getReceipt(this.client);
1495
- if (!scheduleReceipt.scheduleId) {
1496
- this.logger.error(
1497
- "Failed to create scheduled transaction: scheduleId is null"
1498
- );
1499
- throw new Error(
1500
- "Failed to create scheduled transaction: scheduleId is null"
1501
- );
1502
- }
1503
- const scheduleId = scheduleReceipt.scheduleId.toString();
1504
- const transactionId = scheduleResponse.transactionId.toString();
1505
- this.logger.info(
1506
- `Scheduled transaction created successfully: ${scheduleId}`
1507
- );
1508
- return {
1509
- scheduleId,
1510
- transactionId
1511
- };
1512
- }
1513
- /**
1514
- * Sends a transaction operation on a connection topic
1515
- * @param connectionTopicId Connection topic ID
1516
- * @param scheduleId Schedule ID of the scheduled transaction
1517
- * @param data Human-readable description of the transaction, can also be a JSON string or HRL
1518
- * @param submitKey Optional submit key
1519
- * @param options Optional parameters including memo (timestamp is no longer used here)
1520
- * @returns Transaction receipt
1521
- */
1522
- async sendTransactionOperation(connectionTopicId, scheduleId, data, submitKey, options) {
1523
- const submissionCheck = await this.canSubmitToTopic(
1524
- connectionTopicId,
1525
- this.client.operatorAccountId?.toString() || ""
1526
- );
1527
- const operatorId = await this.getOperatorId();
1528
- const payload = {
1529
- p: "hcs-10",
1530
- op: "transaction",
1531
- operator_id: operatorId,
1532
- schedule_id: scheduleId,
1533
- data,
1534
- m: options?.memo
1535
- };
1536
- this.logger.info(
1537
- "Submitting transaction operation to connection topic",
1538
- payload
1539
- );
1540
- return await this.submitPayload(
1541
- connectionTopicId,
1542
- payload,
1543
- submitKey,
1544
- submissionCheck.requiresFee
1545
- );
1546
- }
1547
- /**
1548
- * Creates and sends a transaction operation in one call
1549
- * @param connectionTopicId Connection topic ID for sending the transaction operation
1550
- * @param transaction The transaction to schedule
1551
- * @param data Human-readable description of the transaction, can also be a JSON string or HRL
1552
- * @param options Optional parameters for schedule creation and operation memo
1553
- * @returns Object with schedule details (including scheduleId and its transactionId) and HCS-10 operation receipt
1554
- */
1555
- async sendTransaction(connectionTopicId, transaction, data, options) {
1556
- this.logger.info(
1557
- "Creating scheduled transaction and sending transaction operation"
1558
- );
1559
- const { scheduleId, transactionId } = await this.createScheduledTransaction(
1560
- transaction,
1561
- options?.scheduleMemo,
1562
- options?.expirationTime,
1563
- options?.schedulePayerAccountId
1564
- );
1565
- const receipt = await this.sendTransactionOperation(
1566
- connectionTopicId,
1567
- scheduleId,
1568
- data,
1569
- options?.submitKey,
1570
- {
1571
- memo: options?.operationMemo
1572
- }
1573
- );
1574
- return {
1575
- scheduleId,
1576
- transactionId,
1577
- receipt
1578
- };
1579
- }
1580
- /**
1581
- * Creates communication topics (inbound and outbound) for a profile.
1582
- * Helper method used by the create method.
1583
- */
1584
- async createCommunicationTopics(accountId, options, progressReporter) {
1585
- let state = options?.existingState || {
1586
- currentStage: "init",
1587
- completedPercentage: 0,
1588
- createdResources: []
1589
- };
1590
- if (progressReporter) {
1591
- progressReporter.preparing("Starting communication topic creation", 0, {
1592
- state
1593
- });
1594
- }
1595
- if (!state.outboundTopicId) {
1596
- state.currentStage = "topics";
1597
- if (progressReporter) {
1598
- progressReporter.preparing("Creating outbound topic", 5, {
1599
- state
1600
- });
1601
- }
1602
- const operatorPublicKey = this.client.operatorPublicKey || this.operatorCtx.operatorKey.publicKey;
1603
- const outboundTopicTx = buildHcs10CreateOutboundTopicTx({
1604
- ttl: options?.ttl ?? 60,
1605
- adminKey: true,
1606
- submitKey: true,
1607
- operatorPublicKey
1608
- });
1609
- const { topicId: outboundTopicId } = await this.executeTopicCreateTransaction({
1610
- transaction: outboundTopicTx
1611
- });
1612
- state.outboundTopicId = outboundTopicId;
1613
- if (state.createdResources)
1614
- state.createdResources.push(`outbound:${state.outboundTopicId}`);
1615
- }
1616
- if (!state.inboundTopicId) {
1617
- state.currentStage = "topics";
1618
- if (progressReporter) {
1619
- progressReporter.preparing("Creating inbound topic", 10, {
1620
- state
1621
- });
1622
- }
1623
- const operatorPublicKey = this.client.operatorPublicKey || this.operatorCtx.operatorKey.publicKey;
1624
- const inboundTopicTx = buildHcs10CreateInboundTopicTx({
1625
- accountId,
1626
- ttl: options?.ttl ?? 60,
1627
- adminKey: true,
1628
- submitKey: false,
1629
- operatorPublicKey
1630
- });
1631
- const { topicId: inboundTopicId } = await this.executeTopicCreateTransaction({
1632
- transaction: inboundTopicTx
1633
- });
1634
- state.inboundTopicId = inboundTopicId;
1635
- if (state.createdResources)
1636
- state.createdResources.push(`inbound:${state.inboundTopicId}`);
1637
- }
1638
- return {
1639
- inboundTopicId: state.inboundTopicId,
1640
- outboundTopicId: state.outboundTopicId,
1641
- state
1642
- };
1643
- }
1644
- /**
1645
- * Handles profile picture creation by inscribing it.
1646
- * Helper method used by the create method.
1647
- */
1648
- async handleProfilePictureCreation(pfpBuffer, pfpFileName, state, progressReporter) {
1649
- state.currentStage = "pfp";
1650
- progressReporter.preparing("Creating profile picture", 30, {
1651
- state
1652
- });
1653
- progressReporter.createSubProgress({
1654
- minPercent: 30,
1655
- maxPercent: 50,
1656
- logPrefix: "PFP"
1657
- });
1658
- const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName);
1659
- if (!pfpResult.success) {
1660
- let errorMessage = "Failed to inscribe profile picture";
1661
- if (pfpResult.error) {
1662
- errorMessage = pfpResult.error;
1663
- }
1664
- throw new Error(errorMessage);
1665
- }
1666
- const pfpTopicId = pfpResult.pfpTopicId;
1667
- state.pfpTopicId = pfpTopicId;
1668
- if (state.createdResources) {
1669
- state.createdResources.push(`pfp:${state.pfpTopicId}`);
1670
- }
1671
- progressReporter.preparing("Profile picture created", 50, { state });
1672
- return pfpTopicId;
1673
- }
1674
- /**
1675
- * Creates and inscribes the HCS-11 profile.
1676
- * Helper method used by the create method.
1677
- */
1678
- async createAndInscribeProfile(isAgentBuilder, builder, pfpTopicId, state, inboundTopicId, outboundTopicId, options, progressReporter) {
1679
- this.logger.info("Creating and inscribing profile");
1680
- if (!state.profileTopicId) {
1681
- if (progressReporter) {
1682
- progressReporter.preparing(
1683
- `Storing HCS-11 ${isAgentBuilder ? "agent" : "person"} profile`,
1684
- 80
1685
- );
1686
- }
1687
- progressReporter?.createSubProgress({
1688
- minPercent: 80,
1689
- maxPercent: 95,
1690
- logPrefix: "StoreProfile"
403
+ const profileProgress = progressReporter?.createSubProgress({
404
+ minPercent: 80,
405
+ maxPercent: 95,
406
+ logPrefix: "StoreProfile"
1691
407
  });
1692
408
  let hcs11Profile;
1693
409
  if (isAgentBuilder) {
@@ -1732,7 +448,13 @@ class HCS10Client extends HCS10BaseClient {
1732
448
  }
1733
449
  const profileResult = await this.hcs11Client.createAndInscribeProfile(
1734
450
  hcs11Profile,
1735
- options?.updateAccountMemo ?? true
451
+ options?.updateAccountMemo ?? true,
452
+ {
453
+ progressCallback: (data) => profileProgress?.report({
454
+ ...data,
455
+ progressPercent: data.progressPercent ?? 0
456
+ })
457
+ }
1736
458
  );
1737
459
  if (!profileResult.success) {
1738
460
  if (progressReporter) {
@@ -1766,502 +488,249 @@ class HCS10Client extends HCS10BaseClient {
1766
488
  );
1767
489
  }
1768
490
  }
1769
- /**
1770
- * Creates a new MCP server with inbound and outbound topics.
1771
- *
1772
- * This method creates communication topics and profiles required for an MCP server,
1773
- * registers the profile with the server's account, and handles profile picture
1774
- * inscriptions if provided.
1775
- *
1776
- * @param builder The MCP server builder object
1777
- * @param ttl Optional Time-To-Live for the topic memos, defaults to 60
1778
- * @param existingState Optional existing state to resume from
1779
- * @returns Object with topic IDs
1780
- */
1781
- async createMCPServer(builder, ttl = 60, existingState, progressCallback) {
1782
- await this.ensureInitialized();
1783
- const config = builder.build();
1784
- const accountId = this.client.operatorAccountId?.toString();
1785
- if (!accountId) {
1786
- throw new Error("Failed to retrieve operator account ID");
491
+ initializeRegistrationState(inboundTopicId, existingState) {
492
+ const state = existingState || {
493
+ inboundTopicId,
494
+ currentStage: "registration",
495
+ completedPercentage: 0,
496
+ createdResources: []
497
+ };
498
+ if (state.currentStage !== "registration" && state.currentStage !== "complete") {
499
+ state.currentStage = "registration";
1787
500
  }
1788
- const result = await this._createEntityTopics(
1789
- ttl,
1790
- {
1791
- outboundTopicId: existingState?.outboundTopicId || "",
1792
- inboundTopicId: existingState?.inboundTopicId || "",
1793
- pfpTopicId: existingState?.pfpTopicId || config.existingPfpTopicId || "",
1794
- profileTopicId: existingState?.profileTopicId || ""
1795
- },
1796
- accountId,
1797
- InboundTopicType.PUBLIC,
1798
- void 0,
1799
- config.pfpBuffer,
1800
- config.pfpFileName,
1801
- progressCallback
1802
- );
1803
- if (!result.profileTopicId) {
1804
- this.logger.info("Creating and storing HCS-11 MCP server profile");
1805
- if (progressCallback) {
1806
- progressCallback({
1807
- stage: "preparing",
1808
- message: "Creating MCP server profile",
1809
- progressPercent: 60,
1810
- details: {
1811
- outboundTopicId: result.outboundTopicId,
1812
- inboundTopicId: result.inboundTopicId,
1813
- pfpTopicId: result.pfpTopicId,
1814
- state: {
1815
- currentStage: "profile",
1816
- completedPercentage: 60
1817
- }
1818
- }
1819
- });
1820
- }
1821
- await this.hcs11Client.initializeOperator();
1822
- const profile = this.hcs11Client.createMCPServerProfile(
1823
- config.name,
1824
- config.mcpServer,
1825
- {
1826
- alias: config.alias,
1827
- bio: config.bio,
1828
- socials: config.socials || [],
1829
- inboundTopicId: result.inboundTopicId,
1830
- outboundTopicId: result.outboundTopicId,
1831
- profileImage: result.pfpTopicId ? `hcs://1/${result.pfpTopicId}` : void 0
1832
- }
1833
- );
1834
- const profileResult = await this.hcs11Client.inscribeProfile(profile);
1835
- if (!profileResult.success) {
1836
- this.logger.error(
1837
- `Failed to inscribe MCP server profile: ${profileResult.error}`
1838
- );
1839
- throw new Error(
1840
- profileResult.error || "Failed to inscribe MCP server profile"
1841
- );
1842
- }
1843
- result.profileTopicId = profileResult.profileTopicId;
1844
- this.logger.info(
1845
- `MCP server profile stored with topic ID: ${result.profileTopicId}`
1846
- );
1847
- const memoResult = await this.hcs11Client.updateAccountMemoWithProfile(
1848
- accountId,
1849
- result.profileTopicId
1850
- );
1851
- if (!memoResult.success) {
1852
- this.logger.warn(
1853
- `Failed to update account memo: ${memoResult.error}, but continuing with MCP server creation`
1854
- );
501
+ return state;
502
+ }
503
+ updateStateForCompletedRegistration(state, inboundTopicId) {
504
+ state.currentStage = "complete";
505
+ state.completedPercentage = 100;
506
+ if (state.createdResources) {
507
+ state.createdResources.push(`registration:${inboundTopicId}`);
508
+ }
509
+ }
510
+ async registerAgentWithGuardedRegistry(accountId, network = this.network, options) {
511
+ try {
512
+ this.logger.info("Registering agent with guarded registry");
513
+ let inboundTopicId;
514
+ if (options?.existingState?.inboundTopicId) {
515
+ this.logger.info("Using inboundTopicId from existing state");
516
+ inboundTopicId = options.existingState.inboundTopicId;
1855
517
  } else {
1856
- this.logger.info(`Updated account memo with profile reference`);
1857
- }
1858
- if (progressCallback) {
1859
- progressCallback({
1860
- stage: "preparing",
1861
- message: "MCP server profile created",
1862
- progressPercent: 70,
1863
- details: {
1864
- outboundTopicId: result.outboundTopicId,
1865
- inboundTopicId: result.inboundTopicId,
1866
- pfpTopicId: result.pfpTopicId,
1867
- profileTopicId: result.profileTopicId,
518
+ const profileResponse = await this.retrieveProfile(accountId, false, {
519
+ maxRetries: 5,
520
+ retryDelay: 3e3
521
+ });
522
+ if (!profileResponse.success || !profileResponse.profile || !profileResponse.topicInfo) {
523
+ const errorMessage = profileResponse.error || `Failed to retrieve profile for account ${accountId}. Make sure the agent profile is created and memo is updated before registration.`;
524
+ this.logger.error(errorMessage);
525
+ return {
526
+ error: errorMessage,
527
+ success: false,
1868
528
  state: {
1869
- currentStage: "profile",
1870
- completedPercentage: 70
529
+ currentStage: "registration",
530
+ completedPercentage: 0,
531
+ error: errorMessage
1871
532
  }
1872
- }
1873
- });
533
+ };
534
+ }
535
+ inboundTopicId = profileResponse.topicInfo.inboundTopic;
1874
536
  }
1875
- } else {
1876
- this.logger.info(
1877
- `Using existing profile topic ID: ${result.profileTopicId}`
537
+ const state = this.initializeRegistrationState(
538
+ inboundTopicId,
539
+ options?.existingState
1878
540
  );
1879
- }
1880
- return result;
1881
- }
1882
- /**
1883
- * Creates the base topic structure for an entity (agent or MCP server).
1884
- *
1885
- * @param ttl Time-To-Live for topic memos
1886
- * @param existingTopics Object containing any existing topic IDs to reuse
1887
- * @param accountId The account ID associated with the entity
1888
- * @param inboundTopicType Type of inbound topic
1889
- * @param feeConfig Optional fee configuration for fee-based topics
1890
- * @param pfpBuffer Optional profile picture buffer
1891
- * @param pfpFileName Optional profile picture filename
1892
- * @param progressCallback Optional callback for reporting progress
1893
- * @returns Object with created topic IDs
1894
- */
1895
- async _createEntityTopics(ttl, existingTopics, accountId, inboundTopicType, feeConfig, pfpBuffer, pfpFileName, progressCallback) {
1896
- let { outboundTopicId, inboundTopicId, pfpTopicId, profileTopicId } = existingTopics;
1897
- if (!outboundTopicId) {
1898
- const operatorPublicKey = this.client.operatorPublicKey || this.operatorCtx.operatorKey.publicKey;
1899
- const outboundTransaction = buildHcs10CreateOutboundTopicTx({
1900
- ttl,
1901
- adminKey: true,
1902
- submitKey: true,
1903
- operatorPublicKey
541
+ const progressReporter = new ProgressReporter({
542
+ module: "AgentRegistration",
543
+ logger: this.logger,
544
+ callback: options?.progressCallback
1904
545
  });
1905
- const { topicId } = await this.executeTopicCreateTransaction({
1906
- transaction: outboundTransaction
546
+ progressReporter.preparing("Preparing agent registration", 10, {
547
+ inboundTopicId,
548
+ accountId
1907
549
  });
1908
- outboundTopicId = topicId;
1909
- this.logger.info(`Created new outbound topic ID: ${outboundTopicId}`);
1910
- if (progressCallback) {
1911
- progressCallback({
1912
- stage: "preparing",
1913
- message: "Created outbound topic",
1914
- progressPercent: 30,
1915
- details: {
1916
- outboundTopicId,
1917
- state: {
1918
- currentStage: "topics",
1919
- completedPercentage: 30
1920
- }
1921
- }
1922
- });
1923
- }
1924
- } else {
1925
- this.logger.info(`Using existing outbound topic ID: ${outboundTopicId}`);
1926
- }
1927
- if (!inboundTopicId) {
1928
- inboundTopicId = await this.createInboundTopic(
550
+ const registrationResult = await this.executeRegistration(
1929
551
  accountId,
1930
- inboundTopicType,
1931
- ttl,
1932
- inboundTopicType === InboundTopicType.FEE_BASED ? feeConfig : void 0
552
+ network,
553
+ this.guardedRegistryBaseUrl,
554
+ this.logger
1933
555
  );
1934
- this.logger.info(`Created new inbound topic ID: ${inboundTopicId}`);
1935
- if (progressCallback) {
1936
- progressCallback({
1937
- stage: "preparing",
1938
- message: "Created inbound topic",
1939
- progressPercent: 40,
1940
- details: {
1941
- outboundTopicId,
1942
- inboundTopicId,
1943
- state: {
1944
- currentStage: "topics",
1945
- completedPercentage: 40
1946
- }
1947
- }
1948
- });
1949
- }
1950
- } else {
1951
- this.logger.info(`Using existing inbound topic ID: ${inboundTopicId}`);
1952
- }
1953
- if (!pfpTopicId && pfpBuffer && pfpBuffer.length > 0 && pfpFileName) {
1954
- this.logger.info("Inscribing new profile picture");
1955
- if (progressCallback) {
1956
- progressCallback({
1957
- stage: "preparing",
1958
- message: "Inscribing profile picture",
1959
- progressPercent: 50,
1960
- details: {
1961
- outboundTopicId,
1962
- inboundTopicId,
1963
- state: {
1964
- currentStage: "pfp",
1965
- completedPercentage: 50
1966
- }
1967
- }
1968
- });
556
+ if (!registrationResult.success) {
557
+ return {
558
+ ...registrationResult,
559
+ state
560
+ };
1969
561
  }
1970
- const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName);
1971
- pfpTopicId = pfpResult.pfpTopicId;
1972
- this.logger.info(
1973
- `Profile picture inscribed with topic ID: ${pfpTopicId}`
1974
- );
1975
- if (progressCallback) {
1976
- progressCallback({
1977
- stage: "preparing",
1978
- message: "Profile picture inscribed",
1979
- progressPercent: 55,
1980
- details: {
1981
- outboundTopicId,
1982
- inboundTopicId,
1983
- pfpTopicId,
1984
- state: {
1985
- currentStage: "pfp",
1986
- completedPercentage: 55
1987
- }
1988
- }
1989
- });
562
+ progressReporter.submitting("Submitting registration to registry", 30, {
563
+ transactionId: registrationResult.transactionId
564
+ });
565
+ if (registrationResult.transaction) {
566
+ const transaction = Transaction.fromBytes(
567
+ Buffer.from(registrationResult.transaction, "base64")
568
+ );
569
+ this.logger.info(`Processing registration transaction`);
570
+ const txResult = await this.hwc.executeTransactionWithErrorHandling(
571
+ transaction,
572
+ true
573
+ );
574
+ if (txResult.error) {
575
+ return {
576
+ ...registrationResult,
577
+ error: txResult.error,
578
+ success: false,
579
+ state
580
+ };
581
+ }
582
+ this.logger.info(`Successfully processed registration transaction`);
1990
583
  }
1991
- } else if (pfpTopicId) {
1992
- this.logger.info(
1993
- `Using existing profile picture with topic ID: ${pfpTopicId}`
584
+ progressReporter.confirming("Confirming registration transaction", 60, {
585
+ accountId,
586
+ inboundTopicId,
587
+ transactionId: registrationResult.transactionId
588
+ });
589
+ const maxAttempts = options?.maxAttempts ?? 60;
590
+ const delayMs = options?.delayMs ?? 2e3;
591
+ const confirmed = await this.waitForRegistrationConfirmation(
592
+ registrationResult.transactionId,
593
+ network,
594
+ this.guardedRegistryBaseUrl,
595
+ maxAttempts,
596
+ delayMs,
597
+ this.logger
1994
598
  );
599
+ this.updateStateForCompletedRegistration(state, inboundTopicId);
600
+ progressReporter.completed("Agent registration complete", {
601
+ transactionId: registrationResult.transactionId,
602
+ inboundTopicId,
603
+ state,
604
+ confirmed
605
+ });
606
+ return {
607
+ ...registrationResult,
608
+ confirmed,
609
+ state
610
+ };
611
+ } catch (error) {
612
+ this.logger.error(`Registration error: ${error.message}`);
613
+ return {
614
+ error: `Error during registration: ${error.message}`,
615
+ success: false,
616
+ state: {
617
+ currentStage: "registration",
618
+ completedPercentage: 0,
619
+ error: error.message
620
+ }
621
+ };
1995
622
  }
1996
- return {
1997
- inboundTopicId,
1998
- outboundTopicId,
1999
- pfpTopicId,
2000
- profileTopicId
2001
- };
2002
623
  }
2003
- /**
2004
- * Creates and registers an MCP server with a Guarded registry.
2005
- *
2006
- * This function creates a new account if needed, initializes an HCS10 client,
2007
- * creates an MCP server with inbound and outbound topics, and registers
2008
- * it with the Hashgraph Online Guarded Registry.
2009
- *
2010
- * @param builder The MCP server builder object with configuration
2011
- * @param options Optional settings for registration process
2012
- * @returns Registration result with success status and metadata
2013
- */
2014
- async createAndRegisterMCPServer(builder, options) {
624
+ async createAndRegisterAgent(builder, options) {
2015
625
  try {
2016
- const config = builder.build();
626
+ const agentConfig = builder.build();
2017
627
  const progressCallback = options?.progressCallback;
2018
- const baseUrl = options?.baseUrl || this.guardedRegistryBaseUrl;
628
+ const progressReporter = new ProgressReporter({
629
+ module: "AgentCreateRegister",
630
+ logger: this.logger,
631
+ callback: progressCallback
632
+ });
2019
633
  let state = options?.existingState || {
2020
634
  currentStage: "init",
2021
635
  completedPercentage: 0,
2022
636
  createdResources: []
2023
637
  };
2024
- state.serverMetadata = {
2025
- name: config.name,
2026
- description: config.mcpServer.description,
2027
- services: config.mcpServer.services
2028
- };
2029
- if (progressCallback) {
2030
- progressCallback({
2031
- stage: "preparing",
2032
- message: "Starting MCP server creation process",
2033
- progressPercent: 0,
2034
- details: { state }
2035
- });
2036
- }
2037
- let account = config.existingAccount;
2038
- let serverClient;
2039
- if (!state.inboundTopicId || !state.outboundTopicId || !state.profileTopicId) {
2040
- if (!account) {
2041
- if (state.createdResources && state.createdResources.some((r) => r.startsWith("account:"))) {
2042
- const accountResource = state.createdResources.find(
2043
- (r) => r.startsWith("account:")
2044
- );
2045
- const existingAccountId = accountResource?.split(":")[1];
2046
- if (existingAccountId && config.existingAccount) {
2047
- account = config.existingAccount;
2048
- this.logger.info(
2049
- `Resuming with existing account: ${existingAccountId}`
2050
- );
2051
- } else {
2052
- account = await this.createAccount(options?.initialBalance);
2053
- state.createdResources = state.createdResources || [];
2054
- state.createdResources.push(`account:${account.accountId}`);
2055
- }
2056
- } else {
2057
- account = await this.createAccount(options?.initialBalance);
2058
- state.createdResources = state.createdResources || [];
2059
- state.createdResources.push(`account:${account.accountId}`);
2060
- }
2061
- }
2062
- if (progressCallback) {
2063
- progressCallback({
2064
- stage: "preparing",
2065
- message: "Created account or using existing account",
2066
- progressPercent: 20,
2067
- details: { state, account }
2068
- });
2069
- }
2070
- const resolver = new NodeOperatorResolver({
2071
- mirrorNode: this.mirrorNode,
2072
- logger: this.logger
2073
- });
2074
- const keyInfo = await resolver.resolveOperatorKey(
2075
- account.accountId,
2076
- account.privateKey
2077
- );
2078
- builder.setExistingAccount(account.accountId, account.privateKey);
2079
- const privateKey = keyInfo.keyType === "ed25519" ? PrivateKey.fromStringED25519(account.privateKey) : PrivateKey.fromStringECDSA(account.privateKey);
2080
- const publicKey = privateKey.publicKey.toString();
2081
- serverClient = new HCS10Client({
2082
- network: config.network,
2083
- operatorId: account.accountId,
2084
- operatorPrivateKey: account.privateKey,
2085
- operatorPublicKey: publicKey,
2086
- logLevel: "info",
2087
- guardedRegistryBaseUrl: baseUrl
2088
- });
2089
- if (progressCallback) {
2090
- progressCallback({
2091
- stage: "preparing",
2092
- message: "Initialized MCP server client",
2093
- progressPercent: 25,
2094
- details: { state }
2095
- });
2096
- }
2097
- let outboundTopicId = state.outboundTopicId;
2098
- let inboundTopicId = state.inboundTopicId;
2099
- let pfpTopicId = state.pfpTopicId;
2100
- let profileTopicId = state.profileTopicId;
2101
- if (!outboundTopicId || !inboundTopicId || !profileTopicId) {
2102
- if (pfpTopicId) {
2103
- builder.setExistingProfilePicture(pfpTopicId);
2104
- }
2105
- const createResult = await serverClient.createMCPServer(
2106
- builder,
2107
- 60,
2108
- state,
2109
- (data) => {
2110
- if (progressCallback) {
2111
- progressCallback({
2112
- stage: data.stage,
2113
- message: data.message,
2114
- progressPercent: data.progressPercent || 0,
2115
- details: {
2116
- ...data.details,
2117
- state: {
2118
- ...state,
2119
- ...data.details?.state
2120
- }
2121
- }
2122
- });
2123
- }
2124
- }
2125
- );
2126
- outboundTopicId = createResult.outboundTopicId;
2127
- inboundTopicId = createResult.inboundTopicId;
2128
- pfpTopicId = createResult.pfpTopicId;
2129
- profileTopicId = createResult.profileTopicId;
2130
- state.outboundTopicId = outboundTopicId;
2131
- state.inboundTopicId = inboundTopicId;
2132
- state.pfpTopicId = pfpTopicId;
2133
- state.profileTopicId = profileTopicId;
2134
- if (!state.createdResources) {
2135
- state.createdResources = [];
2136
- }
2137
- if (pfpTopicId && !state.createdResources.includes(`pfp:${pfpTopicId}`)) {
2138
- state.createdResources.push(`pfp:${pfpTopicId}`);
2139
- }
2140
- if (!state.createdResources.includes(`inbound:${inboundTopicId}`)) {
2141
- state.createdResources.push(`inbound:${inboundTopicId}`);
2142
- }
2143
- if (!state.createdResources.includes(`outbound:${outboundTopicId}`)) {
2144
- state.createdResources.push(`outbound:${outboundTopicId}`);
2145
- }
2146
- if (!state.createdResources.includes(`profile:${profileTopicId}`)) {
2147
- state.createdResources.push(`profile:${profileTopicId}`);
2148
- }
2149
- }
2150
- state.currentStage = "profile";
2151
- state.completedPercentage = 60;
2152
- if (progressCallback) {
2153
- progressCallback({
2154
- stage: "submitting",
2155
- message: "Created MCP server with topics and profile",
2156
- progressPercent: 60,
2157
- details: {
2158
- state,
2159
- outboundTopicId,
2160
- inboundTopicId,
2161
- pfpTopicId,
2162
- profileTopicId
2163
- }
2164
- });
638
+ state.agentMetadata = agentConfig.metadata;
639
+ progressReporter.preparing("Starting agent creation process", 0, {
640
+ state
641
+ });
642
+ if (state.currentStage !== "complete" || !state.inboundTopicId || !state.outboundTopicId || !state.profileTopicId) {
643
+ const createResult = await this.create(builder, {
644
+ progressCallback: (progress) => {
645
+ const adjustedPercent = (progress.progressPercent || 0) * 0.3;
646
+ progressReporter.report({
647
+ ...progress,
648
+ progressPercent: adjustedPercent,
649
+ details: {
650
+ ...progress.details,
651
+ state: progress.details?.state || state
652
+ }
653
+ });
654
+ },
655
+ existingState: state,
656
+ updateAccountMemo: true
657
+ });
658
+ if (!("state" in createResult)) {
659
+ throw new Error("Create method did not return expected agent state.");
2165
660
  }
2166
- } else {
2167
- account = account || config.existingAccount;
2168
- if (!account) {
661
+ if (!createResult.success) {
2169
662
  throw new Error(
2170
- "Cannot resume registration without account information"
663
+ createResult.error || "Failed to create agent resources"
2171
664
  );
2172
665
  }
2173
- const keyType = detectKeyTypeFromString(account.privateKey);
2174
- const privateKey = keyType.detectedType === "ed25519" ? PrivateKey.fromStringED25519(account.privateKey) : PrivateKey.fromStringECDSA(account.privateKey);
2175
- const publicKey = privateKey.publicKey.toString();
2176
- serverClient = new HCS10Client({
2177
- network: config.network,
2178
- operatorId: account.accountId,
2179
- operatorPrivateKey: account.privateKey,
2180
- operatorPublicKey: publicKey,
2181
- keyType: keyType.detectedType,
2182
- logLevel: "info",
2183
- guardedRegistryBaseUrl: baseUrl
2184
- });
2185
- this.logger.info("Resuming registration with existing state", {
2186
- inboundTopicId: state.inboundTopicId,
2187
- outboundTopicId: state.outboundTopicId,
2188
- profileTopicId: state.profileTopicId,
2189
- pfpTopicId: state.pfpTopicId
2190
- });
666
+ state = createResult.state;
667
+ state.agentMetadata = agentConfig.metadata;
668
+ this.logger.info("Waiting for account memo update to propagate...");
669
+ await new Promise((resolve) => setTimeout(resolve, 5e3));
2191
670
  }
2192
- const operatorId = `${state.inboundTopicId}@${account.accountId}`;
671
+ progressReporter.preparing(
672
+ `Agent creation status: ${state.currentStage}, ${state.completedPercentage}%`,
673
+ 30,
674
+ { state }
675
+ );
676
+ const { accountId } = this.getAccountAndSigner();
2193
677
  if (state.currentStage !== "complete" || !state.createdResources?.includes(
2194
678
  `registration:${state.inboundTopicId}`
2195
679
  )) {
2196
- const registrationResult = await serverClient.registerAgentWithGuardedRegistry(
2197
- account.accountId,
2198
- config.network,
680
+ if (options?.baseUrl) {
681
+ this.guardedRegistryBaseUrl = options.baseUrl;
682
+ }
683
+ const registrationResult = await this.registerAgentWithGuardedRegistry(
684
+ accountId,
685
+ agentConfig.network,
2199
686
  {
2200
- progressCallback: (data) => {
2201
- const adjustedPercent = 60 + (data.progressPercent || 0) * 0.4;
2202
- if (progressCallback) {
2203
- progressCallback({
2204
- stage: data.stage,
2205
- message: data.message,
2206
- progressPercent: adjustedPercent,
2207
- details: {
2208
- ...data.details,
2209
- outboundTopicId: state.outboundTopicId,
2210
- inboundTopicId: state.inboundTopicId,
2211
- pfpTopicId: state.pfpTopicId,
2212
- profileTopicId: state.profileTopicId,
2213
- operatorId,
2214
- state: data.details?.state || state
2215
- }
2216
- });
2217
- }
687
+ progressCallback: (progress) => {
688
+ const adjustedPercent = 30 + (progress.progressPercent || 0) * 0.7;
689
+ progressReporter.report({
690
+ ...progress,
691
+ progressPercent: adjustedPercent,
692
+ details: {
693
+ ...progress.details,
694
+ state: progress.details?.state || state
695
+ }
696
+ });
2218
697
  },
698
+ maxAttempts: options?.maxAttempts,
699
+ delayMs: options?.delayMs,
2219
700
  existingState: state
2220
701
  }
2221
702
  );
2222
703
  if (!registrationResult.success) {
2223
- return {
2224
- ...registrationResult,
2225
- state
2226
- };
704
+ throw new Error(
705
+ registrationResult.error || "Failed to register agent with registry"
706
+ );
2227
707
  }
2228
- state = registrationResult.state || state;
2229
- }
2230
- if (progressCallback) {
2231
- progressCallback({
2232
- stage: "completed",
2233
- message: "MCP server creation and registration complete",
2234
- progressPercent: 100,
2235
- details: {
2236
- outboundTopicId: state.outboundTopicId,
2237
- inboundTopicId: state.inboundTopicId,
2238
- pfpTopicId: state.pfpTopicId,
2239
- profileTopicId: state.profileTopicId,
2240
- operatorId,
2241
- state
2242
- }
2243
- });
708
+ state = registrationResult.state;
2244
709
  }
710
+ progressReporter.completed("Agent creation and registration complete", {
711
+ state
712
+ });
2245
713
  return {
2246
714
  success: true,
2247
715
  state,
2248
716
  metadata: {
2249
- accountId: account.accountId,
2250
- privateKey: account.privateKey,
2251
- operatorId,
717
+ accountId,
718
+ operatorId: `${state.inboundTopicId}@${accountId}`,
2252
719
  inboundTopicId: state.inboundTopicId,
2253
720
  outboundTopicId: state.outboundTopicId,
2254
721
  profileTopicId: state.profileTopicId,
2255
- pfpTopicId: state.pfpTopicId
722
+ pfpTopicId: state.pfpTopicId,
723
+ privateKey: null,
724
+ ...state.agentMetadata
2256
725
  }
2257
726
  };
2258
- } catch (e) {
2259
- const error = e;
2260
- const logMessage = `Failed to create and register MCP server: ${error.message}`;
2261
- this.logger.error(logMessage);
727
+ } catch (error) {
728
+ this.logger.error(
729
+ `Failed to create and register agent: ${error.message}`
730
+ );
2262
731
  return {
2263
- error: error.message,
2264
732
  success: false,
733
+ error: `Failed to create and register agent: ${error.message}`,
2265
734
  state: options?.existingState || {
2266
735
  currentStage: "init",
2267
736
  completedPercentage: 0,
@@ -2270,137 +739,419 @@ class HCS10Client extends HCS10BaseClient {
2270
739
  };
2271
740
  }
2272
741
  }
2273
- /**
2274
- * Creates a new HCS-10 registry topic with optional metadata stored via HCS-1.
2275
- *
2276
- * Registry topics serve as directories for AI agent discovery and follow the
2277
- * HCS-10 memo format: hcs-10:0:{ttl}:3:[metadataTopicId]
2278
- *
2279
- * @param options Configuration options for registry creation
2280
- * @returns Promise resolving to registry creation result
2281
- */
2282
- async createRegistryTopic(options = {}) {
2283
- const {
2284
- ttl = 86400,
2285
- metadata,
2286
- adminKey = false,
2287
- submitKey = false,
2288
- waitForConfirmation = true,
2289
- waitMaxAttempts = 30,
2290
- waitIntervalMs = 4e3,
2291
- progressCallback
2292
- } = options;
742
+ async storeHCS11Profile(agentName, agentBio, inboundTopicId, outboundTopicId, capabilities = [], metadata = {}, pfpBuffer, pfpFileName, existingPfpTopicId, options) {
2293
743
  try {
2294
- await this.ensureInitialized();
2295
- if (progressCallback) {
2296
- progressCallback({
2297
- stage: "preparing",
2298
- message: "Preparing registry topic creation",
2299
- progressPercent: 10,
2300
- details: { metadata: !!metadata }
744
+ const progressCallback = options?.progressCallback;
745
+ const progressReporter = new ProgressReporter({
746
+ module: "StoreHCS11Profile",
747
+ logger: this.logger,
748
+ callback: progressCallback
749
+ });
750
+ progressReporter.preparing("Preparing agent profile data", 0);
751
+ let pfpTopicId = existingPfpTopicId;
752
+ if (!pfpTopicId && pfpBuffer && pfpFileName) {
753
+ const pfpProgress = progressReporter.createSubProgress({
754
+ minPercent: 0,
755
+ maxPercent: 60,
756
+ logPrefix: "PFP"
2301
757
  });
2302
- }
2303
- let metadataTopicId;
2304
- if (metadata) {
2305
- this.logger.info("Creating metadata inscription for registry");
2306
- if (progressCallback) {
2307
- progressCallback({
2308
- stage: "submitting",
2309
- message: "Creating registry metadata inscription",
2310
- progressPercent: 30,
2311
- details: { metadataName: metadata.name }
2312
- });
2313
- }
2314
- const metadataBuffer = Buffer.from(JSON.stringify(metadata, null, 2));
2315
- const inscriptionOptions = {
2316
- mode: "file",
2317
- waitForConfirmation,
2318
- waitMaxAttempts,
2319
- waitIntervalMs,
2320
- logging: {
2321
- level: this.logger.getLevel ? this.logger.getLevel() : "info"
758
+ const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName, {
759
+ progressCallback: (data) => {
760
+ pfpProgress.report({
761
+ stage: data.stage,
762
+ message: data.message,
763
+ progressPercent: data.progressPercent || 0,
764
+ details: data.details
765
+ });
2322
766
  }
2323
- };
2324
- const inscription = await inscribe(
2325
- {
2326
- type: "buffer",
2327
- buffer: metadataBuffer,
2328
- fileName: `registry-metadata-${Date.now()}.json`,
2329
- mimeType: "application/json"
2330
- },
2331
- {
2332
- accountId: this.client.operatorAccountId.toString(),
2333
- privateKey: this.operatorCtx.operatorKey,
2334
- network: this.network
2335
- },
2336
- inscriptionOptions
2337
- );
2338
- if (!inscription.confirmed || !inscription.inscription) {
2339
- throw new Error("Metadata inscription was not confirmed");
767
+ });
768
+ if (!pfpResult.success) {
769
+ progressReporter.failed(
770
+ "Failed to inscribe profile picture, continuing without PFP"
771
+ );
772
+ } else {
773
+ pfpTopicId = pfpResult.pfpTopicId;
2340
774
  }
2341
- metadataTopicId = getTopicId(inscription.inscription);
2342
- this.logger.info(`Metadata inscribed to topic: ${metadataTopicId}`);
775
+ } else if (existingPfpTopicId) {
776
+ progressReporter.preparing(
777
+ `Using existing profile picture: ${existingPfpTopicId}`,
778
+ 30
779
+ );
780
+ } else {
781
+ progressReporter.preparing("No profile picture provided", 30);
2343
782
  }
2344
- if (progressCallback) {
2345
- progressCallback({
2346
- stage: "submitting",
2347
- message: "Creating registry topic",
2348
- progressPercent: 60,
2349
- details: { metadataTopicId }
2350
- });
783
+ if (!this.hcs11Client) {
784
+ progressReporter.failed(
785
+ "HCS11Client is not available in this environment"
786
+ );
787
+ return {
788
+ profileTopicId: "",
789
+ success: false,
790
+ error: "HCS11Client is not available in this environment",
791
+ transactionId: ""
792
+ };
2351
793
  }
2352
- const operatorKey = this.operatorCtx.operatorKey;
2353
- const operatorPublicKey = this.client.operatorPublicKey || operatorKey.publicKey;
2354
- const transaction = buildHcs10CreateRegistryTopicTx({
2355
- ttl,
2356
- metadataTopicId,
2357
- adminKey,
2358
- submitKey,
2359
- operatorPublicKey
794
+ const agentType = this.hcs11Client.getAgentTypeFromMetadata({
795
+ type: metadata.type || "autonomous"
2360
796
  });
2361
- const { topicId, response: txResponse } = await this.executeTopicCreateTransaction({
2362
- transaction
797
+ progressReporter.preparing("Building agent profile", 65);
798
+ const formattedSocials = metadata.socials ? Object.entries(metadata.socials).filter(([_, handle]) => handle).map(([platform, handle]) => ({
799
+ platform,
800
+ handle
801
+ })) : void 0;
802
+ const profile = this.hcs11Client.createAIAgentProfile(
803
+ agentName,
804
+ agentType,
805
+ capabilities,
806
+ metadata.model || "unknown",
807
+ {
808
+ alias: agentName.toLowerCase().replace(/\s+/g, "_"),
809
+ bio: agentBio,
810
+ profileImage: pfpTopicId ? `hcs://1/${pfpTopicId}` : void 0,
811
+ socials: formattedSocials,
812
+ properties: {
813
+ version: metadata.version || "1.0.0",
814
+ creator: metadata.creator || "Unknown",
815
+ supported_languages: metadata.supported_languages || ["en"],
816
+ permissions: metadata.permissions || [],
817
+ model_details: metadata.model_details,
818
+ training: metadata.training,
819
+ capabilities_description: metadata.capabilities_description,
820
+ ...metadata
821
+ },
822
+ inboundTopicId,
823
+ outboundTopicId,
824
+ creator: metadata.creator
825
+ }
826
+ );
827
+ const profileProgress = progressReporter.createSubProgress({
828
+ minPercent: 65,
829
+ maxPercent: 100,
830
+ logPrefix: "Profile"
2363
831
  });
2364
- if (progressCallback) {
2365
- progressCallback({
2366
- stage: "completed",
2367
- message: "Registry topic created successfully",
2368
- progressPercent: 100,
2369
- details: {
2370
- topicId,
2371
- metadataTopicId,
2372
- transactionId: txResponse.transactionId.toString()
832
+ const profileResult = await this.hcs11Client.createAndInscribeProfile(
833
+ profile,
834
+ options?.updateAccountMemo ?? true,
835
+ {
836
+ progressCallback: (profileData) => {
837
+ profileProgress.report({
838
+ stage: profileData.stage,
839
+ message: profileData.message,
840
+ progressPercent: profileData.progressPercent || 0,
841
+ details: profileData.details
842
+ });
2373
843
  }
2374
- });
844
+ }
845
+ );
846
+ if (!profileResult.success) {
847
+ progressReporter.failed("Failed to inscribe profile");
848
+ return {
849
+ profileTopicId: "",
850
+ success: false,
851
+ error: profileResult.error || "Failed to inscribe profile",
852
+ transactionId: profileResult.transactionId || ""
853
+ };
2375
854
  }
2376
- this.logger.info(`Registry topic created successfully: ${topicId}`);
855
+ progressReporter.completed("Profile stored successfully", {
856
+ profileTopicId: profileResult.profileTopicId
857
+ });
2377
858
  return {
859
+ profileTopicId: profileResult.profileTopicId,
860
+ pfpTopicId,
2378
861
  success: true,
2379
- topicId,
2380
- transactionId: txResponse.transactionId.toString(),
2381
- metadataTopicId
862
+ transactionId: profileResult.transactionId || ""
2382
863
  };
2383
864
  } catch (error) {
2384
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
2385
- if (progressCallback) {
2386
- progressCallback({
2387
- stage: "failed",
2388
- message: `Registry creation failed: ${errorMessage}`,
2389
- progressPercent: 0,
2390
- details: { error: errorMessage }
865
+ this.logger.error(`Error storing HCS11 profile: ${error.message}`);
866
+ return {
867
+ profileTopicId: "",
868
+ success: false,
869
+ error: error.message,
870
+ transactionId: ""
871
+ };
872
+ }
873
+ }
874
+ async createTopic(memo, adminKey, submitKey) {
875
+ this.logger.info("Creating topic");
876
+ const { accountId, signer } = this.getAccountAndSigner();
877
+ const transaction = new TopicCreateTransaction().setTopicMemo(memo);
878
+ const publicKey = await this.mirrorNode.getPublicKey(accountId);
879
+ if (adminKey && publicKey) {
880
+ transaction.setAdminKey(publicKey);
881
+ transaction.setAutoRenewAccountId(accountId);
882
+ }
883
+ if (submitKey && publicKey) {
884
+ transaction.setSubmitKey(publicKey);
885
+ }
886
+ const transactionResponse = await this.hwc.executeTransactionWithErrorHandling(
887
+ transaction,
888
+ false
889
+ );
890
+ const error = transactionResponse.error;
891
+ if (error) {
892
+ this.logger.error(error);
893
+ return {
894
+ success: false,
895
+ error
896
+ };
897
+ }
898
+ const resultReceipt = transactionResponse.result;
899
+ if (!resultReceipt?.topicId) {
900
+ this.logger.error("Failed to create topic: topicId is null");
901
+ return {
902
+ success: false,
903
+ error: "Failed to create topic: topicId is null"
904
+ };
905
+ }
906
+ return {
907
+ success: true,
908
+ topicId: resultReceipt.topicId.toString()
909
+ };
910
+ }
911
+ async submitPayload(topicId, payload, submitKey, requiresFee) {
912
+ this.logger.debug(`Submitting payload to topic ${topicId}`);
913
+ let message;
914
+ if (typeof payload === "string") {
915
+ message = payload;
916
+ } else {
917
+ message = JSON.stringify(payload);
918
+ }
919
+ const transaction = new TopicMessageSubmitTransaction().setTopicId(topicId).setMessage(message);
920
+ const transactionMemo = this.getHcs10TransactionMemo(payload);
921
+ if (transactionMemo) {
922
+ transaction.setTransactionMemo(transactionMemo);
923
+ }
924
+ let transactionResponse;
925
+ if (requiresFee) {
926
+ this.logger.info(
927
+ "Topic requires fee payment, setting max transaction fee"
928
+ );
929
+ transaction.setMaxTransactionFee(new Hbar(this.feeAmount));
930
+ }
931
+ if (submitKey) {
932
+ const { signer } = this.getAccountAndSigner();
933
+ transaction.freezeWithSigner(signer);
934
+ const signedTransaction = await transaction.sign(submitKey);
935
+ transactionResponse = await this.hwc.executeTransactionWithErrorHandling(
936
+ signedTransaction,
937
+ true
938
+ );
939
+ } else {
940
+ transactionResponse = await this.hwc.executeTransactionWithErrorHandling(
941
+ transaction,
942
+ false
943
+ );
944
+ }
945
+ if (transactionResponse?.error) {
946
+ this.logger.error(
947
+ `Failed to submit payload: ${transactionResponse.error}`
948
+ );
949
+ throw new Error(`Failed to submit payload: ${transactionResponse.error}`);
950
+ }
951
+ if (!transactionResponse?.result) {
952
+ this.logger.error(
953
+ "Failed to submit message: receipt is null or undefined"
954
+ );
955
+ throw new Error("Failed to submit message: receipt is null or undefined");
956
+ }
957
+ this.logger.debug("Payload submitted successfully via HWC");
958
+ return transactionResponse.result;
959
+ }
960
+ async inscribeFile(buffer, fileName, options) {
961
+ const { accountId, signer } = this.getAccountAndSigner();
962
+ const mimeType = mime.lookup(fileName) || "application/octet-stream";
963
+ const sdk = await InscriptionSDK.createWithAuth({
964
+ type: "client",
965
+ accountId,
966
+ signer,
967
+ network: this.network
968
+ });
969
+ const inscriptionOptions = {
970
+ mode: "file",
971
+ waitForConfirmation: true,
972
+ waitMaxAttempts: options?.waitMaxAttempts || 30,
973
+ waitIntervalMs: options?.waitIntervalMs || 4e3,
974
+ progressCallback: options?.progressCallback,
975
+ logging: {
976
+ level: this.logger.getLevel ? this.logger.getLevel() : "info"
977
+ }
978
+ };
979
+ const response = await inscribeWithSigner(
980
+ {
981
+ type: "buffer",
982
+ buffer,
983
+ fileName,
984
+ mimeType
985
+ },
986
+ signer,
987
+ {
988
+ ...inscriptionOptions,
989
+ network: this.network
990
+ },
991
+ sdk
992
+ );
993
+ if (!response.confirmed || !response.inscription) {
994
+ throw new Error("Inscription was not confirmed");
995
+ }
996
+ return response.inscription;
997
+ }
998
+ getAccountAndSigner() {
999
+ const accountInfo = this?.hwc?.getAccountInfo();
1000
+ const accountId = accountInfo?.accountId?.toString();
1001
+ const signer = this?.hwc?.dAppConnector?.signers?.find((s) => {
1002
+ return s.getAccountId().toString() === accountId;
1003
+ });
1004
+ if (!signer) {
1005
+ this.logger.error("Failed to find signer", {
1006
+ accountId,
1007
+ signers: this?.hwc?.dAppConnector?.signers,
1008
+ accountInfo
1009
+ });
1010
+ throw new Error("Failed to find signer");
1011
+ }
1012
+ return { accountId, signer };
1013
+ }
1014
+ /**
1015
+ * Inscribes a profile picture (PFP) on HCS-11.
1016
+ *
1017
+ * @param buffer - The buffer containing the PFP image.
1018
+ * @param fileName - The name of the file containing the PFP image.
1019
+ * @param options - Optional configuration options.
1020
+ * @returns A promise that resolves to the topic ID of the inscribed PFP.
1021
+ */
1022
+ async inscribePfp(buffer, fileName, options) {
1023
+ try {
1024
+ const progressCallback = options?.progressCallback;
1025
+ const progressReporter = new ProgressReporter({
1026
+ module: "PFP-Inscription",
1027
+ logger: this.logger,
1028
+ callback: progressCallback
1029
+ });
1030
+ if (!this.hcs11Client) {
1031
+ progressReporter.failed(
1032
+ "HCS11Client is not available in this environment"
1033
+ );
1034
+ return {
1035
+ pfpTopicId: "",
1036
+ success: false,
1037
+ error: "HCS11Client is not available in this environment",
1038
+ transactionId: ""
1039
+ };
1040
+ }
1041
+ progressReporter.preparing("Preparing to inscribe profile picture", 10);
1042
+ this.logger.info("Inscribing profile picture using HCS-11 client");
1043
+ const wrappedProgressCallback = (data) => {
1044
+ progressReporter.report({
1045
+ stage: data.stage || "confirming",
1046
+ message: data.message || "Processing PFP inscription",
1047
+ progressPercent: data.progressPercent || 50,
1048
+ details: data.details
2391
1049
  });
1050
+ };
1051
+ const imageResult = await this.hcs11Client.inscribeImage(
1052
+ buffer,
1053
+ fileName,
1054
+ { progressCallback: wrappedProgressCallback }
1055
+ );
1056
+ if (!imageResult.success) {
1057
+ let errorMessage = "Failed to inscribe profile picture";
1058
+ if (imageResult.error) {
1059
+ errorMessage = imageResult.error;
1060
+ }
1061
+ let txId = "";
1062
+ if (imageResult.transactionId) {
1063
+ txId = imageResult.transactionId;
1064
+ }
1065
+ return {
1066
+ pfpTopicId: "",
1067
+ success: false,
1068
+ error: errorMessage,
1069
+ transactionId: txId
1070
+ };
2392
1071
  }
2393
- this.logger.error("Failed to create registry topic", {
2394
- error: errorMessage
1072
+ progressReporter.completed("Successfully inscribed profile picture", {
1073
+ pfpTopicId: imageResult.imageTopicId
2395
1074
  });
1075
+ this.logger.info(
1076
+ `Successfully inscribed profile picture with topic ID: ${imageResult.imageTopicId}`
1077
+ );
1078
+ return {
1079
+ pfpTopicId: imageResult.imageTopicId,
1080
+ success: true,
1081
+ transactionId: imageResult.transactionId || ""
1082
+ };
1083
+ } catch (error) {
1084
+ this.logger.error(`Error inscribing profile picture: ${error.message}`);
2396
1085
  return {
1086
+ pfpTopicId: "",
2397
1087
  success: false,
2398
- error: errorMessage
1088
+ error: error.message,
1089
+ transactionId: ""
2399
1090
  };
2400
1091
  }
2401
1092
  }
1093
+ async createCommunicationTopics(options, progressReporter) {
1094
+ let state = options?.existingState || {
1095
+ currentStage: "init",
1096
+ completedPercentage: 0,
1097
+ createdResources: []
1098
+ };
1099
+ if (progressReporter) {
1100
+ progressReporter.preparing("Starting communication topic creation", 0, {
1101
+ state
1102
+ });
1103
+ }
1104
+ const { accountId } = this.getAccountAndSigner();
1105
+ if (!state.outboundTopicId) {
1106
+ state.currentStage = "topics";
1107
+ if (progressReporter) {
1108
+ progressReporter.preparing("Creating outbound topic", 5, {
1109
+ state
1110
+ });
1111
+ }
1112
+ const outboundMemo = this._generateHcs10Memo(Hcs10MemoType.OUTBOUND, {
1113
+ ttl: options?.ttl,
1114
+ accountId
1115
+ });
1116
+ const outboundResult = await this.createTopic(outboundMemo, true, true);
1117
+ if (!outboundResult.success || !outboundResult.topicId) {
1118
+ throw new Error(
1119
+ outboundResult.error || "Failed to create outbound topic"
1120
+ );
1121
+ }
1122
+ state.outboundTopicId = outboundResult.topicId;
1123
+ if (state.createdResources)
1124
+ state.createdResources.push(`outbound:${state.outboundTopicId}`);
1125
+ }
1126
+ if (!state.inboundTopicId) {
1127
+ state.currentStage = "topics";
1128
+ if (progressReporter) {
1129
+ progressReporter.preparing("Creating inbound topic", 10, {
1130
+ state
1131
+ });
1132
+ }
1133
+ const inboundMemo = this._generateHcs10Memo(Hcs10MemoType.INBOUND, {
1134
+ ttl: options?.ttl,
1135
+ accountId
1136
+ });
1137
+ const inboundResult = await this.createTopic(inboundMemo, true, false);
1138
+ if (!inboundResult.success || !inboundResult.topicId) {
1139
+ throw new Error(
1140
+ inboundResult.error || "Failed to create inbound topic"
1141
+ );
1142
+ }
1143
+ state.inboundTopicId = inboundResult.topicId;
1144
+ if (state.createdResources)
1145
+ state.createdResources.push(`inbound:${state.inboundTopicId}`);
1146
+ }
1147
+ return {
1148
+ inboundTopicId: state.inboundTopicId,
1149
+ outboundTopicId: state.outboundTopicId,
1150
+ state
1151
+ };
1152
+ }
2402
1153
  }
2403
1154
  export {
2404
- HCS10Client
1155
+ BrowserHCSClient
2405
1156
  };
2406
1157
  //# sourceMappingURL=standards-sdk.es19.js.map