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

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