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