@hashgraphonline/standards-sdk 0.0.64 → 0.0.66

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 (294) hide show
  1. package/dist/es/fees/fee-config-builder.d.ts.map +1 -0
  2. package/dist/es/fees/index.d.ts +3 -0
  3. package/dist/es/fees/index.d.ts.map +1 -0
  4. package/dist/es/fees/types.d.ts +24 -0
  5. package/dist/es/fees/types.d.ts.map +1 -0
  6. package/dist/es/hcs-10/base-client.d.ts +1 -1
  7. package/dist/es/hcs-10/base-client.d.ts.map +1 -1
  8. package/dist/es/hcs-10/browser.d.ts +20 -35
  9. package/dist/es/hcs-10/browser.d.ts.map +1 -1
  10. package/dist/es/hcs-10/index.d.ts +4 -6
  11. package/dist/es/hcs-10/index.d.ts.map +1 -1
  12. package/dist/es/hcs-10/registrations.d.ts.map +1 -1
  13. package/dist/es/hcs-10/sdk.d.ts +16 -8
  14. package/dist/es/hcs-10/sdk.d.ts.map +1 -1
  15. package/dist/es/hcs-10/types.d.ts +2 -62
  16. package/dist/es/hcs-10/types.d.ts.map +1 -1
  17. package/dist/es/hcs-11/agent-builder.d.ts +53 -0
  18. package/dist/es/hcs-11/agent-builder.d.ts.map +1 -0
  19. package/dist/es/hcs-11/client.d.ts +82 -0
  20. package/dist/es/hcs-11/client.d.ts.map +1 -0
  21. package/dist/es/hcs-11/index.d.ts +4 -190
  22. package/dist/es/hcs-11/index.d.ts.map +1 -1
  23. package/dist/es/hcs-11/person-builder.d.ts +29 -0
  24. package/dist/es/hcs-11/person-builder.d.ts.map +1 -0
  25. package/dist/es/hcs-11/types.d.ts +165 -0
  26. package/dist/es/hcs-11/types.d.ts.map +1 -0
  27. package/dist/es/index.d.ts +1 -0
  28. package/dist/es/index.d.ts.map +1 -1
  29. package/dist/es/services/mirror-node.d.ts +2 -1
  30. package/dist/es/services/mirror-node.d.ts.map +1 -1
  31. package/dist/es/services/types.d.ts +0 -1
  32. package/dist/es/services/types.d.ts.map +1 -1
  33. package/dist/es/standards-sdk.es.js +9 -7
  34. package/dist/es/standards-sdk.es.js.map +1 -1
  35. package/dist/es/standards-sdk.es10.js +114 -1046
  36. package/dist/es/standards-sdk.es10.js.map +1 -1
  37. package/dist/es/standards-sdk.es100.js +3 -792
  38. package/dist/es/standards-sdk.es100.js.map +1 -1
  39. package/dist/es/standards-sdk.es101.js +2282 -174
  40. package/dist/es/standards-sdk.es101.js.map +1 -1
  41. package/dist/es/standards-sdk.es102.js +14 -141
  42. package/dist/es/standards-sdk.es102.js.map +1 -1
  43. package/dist/es/standards-sdk.es103.js +5 -3
  44. package/dist/es/standards-sdk.es103.js.map +1 -1
  45. package/dist/es/standards-sdk.es104.js +39 -2
  46. package/dist/es/standards-sdk.es104.js.map +1 -1
  47. package/dist/es/standards-sdk.es105.js +40 -2
  48. package/dist/es/standards-sdk.es105.js.map +1 -1
  49. package/dist/es/standards-sdk.es106.js +37 -34
  50. package/dist/es/standards-sdk.es106.js.map +1 -1
  51. package/dist/es/standards-sdk.es107.js +74 -29
  52. package/dist/es/standards-sdk.es107.js.map +1 -1
  53. package/dist/es/standards-sdk.es108.js +3 -9
  54. package/dist/es/standards-sdk.es108.js.map +1 -1
  55. package/dist/es/standards-sdk.es109.js +2 -34
  56. package/dist/es/standards-sdk.es109.js.map +1 -1
  57. package/dist/es/standards-sdk.es11.js +80 -71
  58. package/dist/es/standards-sdk.es11.js.map +1 -1
  59. package/dist/es/standards-sdk.es110.js +2 -21
  60. package/dist/es/standards-sdk.es110.js.map +1 -1
  61. package/dist/es/standards-sdk.es111.js +33 -26
  62. package/dist/es/standards-sdk.es111.js.map +1 -1
  63. package/dist/es/standards-sdk.es112.js +32 -25
  64. package/dist/es/standards-sdk.es112.js.map +1 -1
  65. package/dist/es/standards-sdk.es113.js +9 -38
  66. package/dist/es/standards-sdk.es113.js.map +1 -1
  67. package/dist/es/standards-sdk.es114.js +37 -0
  68. package/dist/es/standards-sdk.es114.js.map +1 -0
  69. package/dist/es/standards-sdk.es12.js +650 -7
  70. package/dist/es/standards-sdk.es12.js.map +1 -1
  71. package/dist/es/standards-sdk.es13.js +10 -664
  72. package/dist/es/standards-sdk.es13.js.map +1 -1
  73. package/dist/es/standards-sdk.es14.js +3 -0
  74. package/dist/es/standards-sdk.es14.js.map +1 -1
  75. package/dist/es/standards-sdk.es17.js +2 -2
  76. package/dist/es/standards-sdk.es18.js +3 -3
  77. package/dist/es/standards-sdk.es18.js.map +1 -1
  78. package/dist/es/standards-sdk.es19.js +82 -1754
  79. package/dist/es/standards-sdk.es19.js.map +1 -1
  80. package/dist/es/standards-sdk.es20.js +1767 -3
  81. package/dist/es/standards-sdk.es20.js.map +1 -1
  82. package/dist/es/standards-sdk.es21.js +36 -4167
  83. package/dist/es/standards-sdk.es21.js.map +1 -1
  84. package/dist/es/standards-sdk.es22.js +21 -6600
  85. package/dist/es/standards-sdk.es22.js.map +1 -1
  86. package/dist/es/standards-sdk.es23.js +6627 -36
  87. package/dist/es/standards-sdk.es23.js.map +1 -1
  88. package/dist/es/standards-sdk.es24.js +3 -48
  89. package/dist/es/standards-sdk.es24.js.map +1 -1
  90. package/dist/es/standards-sdk.es26.js +10 -10
  91. package/dist/es/standards-sdk.es27.js +2 -2
  92. package/dist/es/standards-sdk.es28.js +4147 -81
  93. package/dist/es/standards-sdk.es28.js.map +1 -1
  94. package/dist/es/standards-sdk.es29.js +419 -2
  95. package/dist/es/standards-sdk.es29.js.map +1 -1
  96. package/dist/es/standards-sdk.es30.js +2 -16
  97. package/dist/es/standards-sdk.es30.js.map +1 -1
  98. package/dist/es/standards-sdk.es31.js +106 -395
  99. package/dist/es/standards-sdk.es31.js.map +1 -1
  100. package/dist/es/standards-sdk.es32.js +2 -2282
  101. package/dist/es/standards-sdk.es32.js.map +1 -1
  102. package/dist/es/standards-sdk.es33.js +68 -148
  103. package/dist/es/standards-sdk.es33.js.map +1 -1
  104. package/dist/es/standards-sdk.es34.js +23 -3
  105. package/dist/es/standards-sdk.es34.js.map +1 -1
  106. package/dist/es/standards-sdk.es35.js +131 -402
  107. package/dist/es/standards-sdk.es35.js.map +1 -1
  108. package/dist/es/standards-sdk.es36.js +91 -2
  109. package/dist/es/standards-sdk.es36.js.map +1 -1
  110. package/dist/es/standards-sdk.es37.js +190 -115
  111. package/dist/es/standards-sdk.es37.js.map +1 -1
  112. package/dist/es/standards-sdk.es38.js +437 -3
  113. package/dist/es/standards-sdk.es38.js.map +1 -1
  114. package/dist/es/standards-sdk.es39.js +19 -358
  115. package/dist/es/standards-sdk.es39.js.map +1 -1
  116. package/dist/es/standards-sdk.es40.js +138 -5
  117. package/dist/es/standards-sdk.es40.js.map +1 -1
  118. package/dist/es/standards-sdk.es41.js +13 -174
  119. package/dist/es/standards-sdk.es41.js.map +1 -1
  120. package/dist/es/standards-sdk.es42.js +23 -75
  121. package/dist/es/standards-sdk.es42.js.map +1 -1
  122. package/dist/es/standards-sdk.es43.js +26 -111
  123. package/dist/es/standards-sdk.es43.js.map +1 -1
  124. package/dist/es/standards-sdk.es44.js +16 -47
  125. package/dist/es/standards-sdk.es44.js.map +1 -1
  126. package/dist/es/standards-sdk.es45.js +43 -9
  127. package/dist/es/standards-sdk.es45.js.map +1 -1
  128. package/dist/es/standards-sdk.es46.js +13 -92
  129. package/dist/es/standards-sdk.es46.js.map +1 -1
  130. package/dist/es/standards-sdk.es47.js +60 -3
  131. package/dist/es/standards-sdk.es47.js.map +1 -1
  132. package/dist/es/standards-sdk.es48.js +1289 -2
  133. package/dist/es/standards-sdk.es48.js.map +1 -1
  134. package/dist/es/standards-sdk.es49.js +27 -108
  135. package/dist/es/standards-sdk.es49.js.map +1 -1
  136. package/dist/es/standards-sdk.es5.js +393 -891
  137. package/dist/es/standards-sdk.es5.js.map +1 -1
  138. package/dist/es/standards-sdk.es50.js +5 -73
  139. package/dist/es/standards-sdk.es50.js.map +1 -1
  140. package/dist/es/standards-sdk.es51.js +158 -5
  141. package/dist/es/standards-sdk.es51.js.map +1 -1
  142. package/dist/es/standards-sdk.es52.js +792 -4
  143. package/dist/es/standards-sdk.es52.js.map +1 -1
  144. package/dist/es/standards-sdk.es53.js +162 -209
  145. package/dist/es/standards-sdk.es53.js.map +1 -1
  146. package/dist/es/standards-sdk.es54.js +137 -52
  147. package/dist/es/standards-sdk.es54.js.map +1 -1
  148. package/dist/es/standards-sdk.es55.js +4 -69
  149. package/dist/es/standards-sdk.es55.js.map +1 -1
  150. package/dist/es/standards-sdk.es56.js +357 -25
  151. package/dist/es/standards-sdk.es56.js.map +1 -1
  152. package/dist/es/standards-sdk.es57.js +5 -62
  153. package/dist/es/standards-sdk.es57.js.map +1 -1
  154. package/dist/es/standards-sdk.es58.js +173 -44
  155. package/dist/es/standards-sdk.es58.js.map +1 -1
  156. package/dist/es/standards-sdk.es59.js +80 -9
  157. package/dist/es/standards-sdk.es59.js.map +1 -1
  158. package/dist/es/standards-sdk.es60.js +106 -57
  159. package/dist/es/standards-sdk.es60.js.map +1 -1
  160. package/dist/es/standards-sdk.es61.js +52 -6
  161. package/dist/es/standards-sdk.es61.js.map +1 -1
  162. package/dist/es/standards-sdk.es62.js +9 -14
  163. package/dist/es/standards-sdk.es62.js.map +1 -1
  164. package/dist/es/standards-sdk.es63.js +97 -7
  165. package/dist/es/standards-sdk.es63.js.map +1 -1
  166. package/dist/es/standards-sdk.es64.js +4 -45
  167. package/dist/es/standards-sdk.es64.js.map +1 -1
  168. package/dist/es/standards-sdk.es65.js +2 -2
  169. package/dist/es/standards-sdk.es65.js.map +1 -1
  170. package/dist/es/standards-sdk.es66.js +105 -128
  171. package/dist/es/standards-sdk.es66.js.map +1 -1
  172. package/dist/es/standards-sdk.es67.js +70 -168
  173. package/dist/es/standards-sdk.es67.js.map +1 -1
  174. package/dist/es/standards-sdk.es68.js +6 -2
  175. package/dist/es/standards-sdk.es68.js.map +1 -1
  176. package/dist/es/standards-sdk.es69.js +5 -13
  177. package/dist/es/standards-sdk.es69.js.map +1 -1
  178. package/dist/es/standards-sdk.es7.js +959 -94
  179. package/dist/es/standards-sdk.es7.js.map +1 -1
  180. package/dist/es/standards-sdk.es70.js +221 -13
  181. package/dist/es/standards-sdk.es70.js.map +1 -1
  182. package/dist/es/standards-sdk.es71.js +56 -30
  183. package/dist/es/standards-sdk.es71.js.map +1 -1
  184. package/dist/es/standards-sdk.es72.js +69 -15
  185. package/dist/es/standards-sdk.es72.js.map +1 -1
  186. package/dist/es/standards-sdk.es73.js +20 -3
  187. package/dist/es/standards-sdk.es73.js.map +1 -1
  188. package/dist/es/standards-sdk.es74.js +26 -3
  189. package/dist/es/standards-sdk.es74.js.map +1 -1
  190. package/dist/es/standards-sdk.es75.js +24 -14
  191. package/dist/es/standards-sdk.es75.js.map +1 -1
  192. package/dist/es/standards-sdk.es76.js +37 -4
  193. package/dist/es/standards-sdk.es76.js.map +1 -1
  194. package/dist/es/standards-sdk.es77.js +3 -39
  195. package/dist/es/standards-sdk.es77.js.map +1 -1
  196. package/dist/es/standards-sdk.es78.js +158 -34
  197. package/dist/es/standards-sdk.es78.js.map +1 -1
  198. package/dist/es/standards-sdk.es79.js +30 -35
  199. package/dist/es/standards-sdk.es79.js.map +1 -1
  200. package/dist/es/standards-sdk.es8.js +1049 -393
  201. package/dist/es/standards-sdk.es8.js.map +1 -1
  202. package/dist/es/standards-sdk.es80.js +57 -72
  203. package/dist/es/standards-sdk.es80.js.map +1 -1
  204. package/dist/es/standards-sdk.es81.js +46 -191
  205. package/dist/es/standards-sdk.es81.js.map +1 -1
  206. package/dist/es/standards-sdk.es82.js +8 -436
  207. package/dist/es/standards-sdk.es82.js.map +1 -1
  208. package/dist/es/standards-sdk.es83.js +60 -20
  209. package/dist/es/standards-sdk.es83.js.map +1 -1
  210. package/dist/es/standards-sdk.es84.js +6 -139
  211. package/dist/es/standards-sdk.es84.js.map +1 -1
  212. package/dist/es/standards-sdk.es85.js +14 -17
  213. package/dist/es/standards-sdk.es85.js.map +1 -1
  214. package/dist/es/standards-sdk.es86.js +7 -29
  215. package/dist/es/standards-sdk.es86.js.map +1 -1
  216. package/dist/es/standards-sdk.es87.js +44 -28
  217. package/dist/es/standards-sdk.es87.js.map +1 -1
  218. package/dist/es/standards-sdk.es88.js +2 -21
  219. package/dist/es/standards-sdk.es88.js.map +1 -1
  220. package/dist/es/standards-sdk.es89.js +135 -43
  221. package/dist/es/standards-sdk.es89.js.map +1 -1
  222. package/dist/es/standards-sdk.es9.js +1 -1
  223. package/dist/es/standards-sdk.es9.js.map +1 -1
  224. package/dist/es/standards-sdk.es90.js +168 -14
  225. package/dist/es/standards-sdk.es90.js.map +1 -1
  226. package/dist/es/standards-sdk.es91.js +95 -55
  227. package/dist/es/standards-sdk.es91.js.map +1 -1
  228. package/dist/es/standards-sdk.es92.js +2 -1289
  229. package/dist/es/standards-sdk.es92.js.map +1 -1
  230. package/dist/es/standards-sdk.es93.js +15 -147
  231. package/dist/es/standards-sdk.es93.js.map +1 -1
  232. package/dist/es/standards-sdk.es94.js +403 -85
  233. package/dist/es/standards-sdk.es94.js.map +1 -1
  234. package/dist/es/standards-sdk.es95.js +13 -84
  235. package/dist/es/standards-sdk.es95.js.map +1 -1
  236. package/dist/es/standards-sdk.es96.js +13 -32
  237. package/dist/es/standards-sdk.es96.js.map +1 -1
  238. package/dist/es/standards-sdk.es97.js +31 -5
  239. package/dist/es/standards-sdk.es97.js.map +1 -1
  240. package/dist/es/standards-sdk.es98.js +13 -157
  241. package/dist/es/standards-sdk.es98.js.map +1 -1
  242. package/dist/es/standards-sdk.es99.js +3 -22
  243. package/dist/es/standards-sdk.es99.js.map +1 -1
  244. package/dist/es/utils/logger.d.ts +1 -0
  245. package/dist/es/utils/logger.d.ts.map +1 -1
  246. package/dist/es/utils/types.d.ts +2 -0
  247. package/dist/es/utils/types.d.ts.map +1 -0
  248. package/dist/umd/fees/fee-config-builder.d.ts.map +1 -0
  249. package/dist/umd/fees/index.d.ts +3 -0
  250. package/dist/umd/fees/index.d.ts.map +1 -0
  251. package/dist/umd/fees/types.d.ts +24 -0
  252. package/dist/umd/fees/types.d.ts.map +1 -0
  253. package/dist/umd/hcs-10/base-client.d.ts +1 -1
  254. package/dist/umd/hcs-10/base-client.d.ts.map +1 -1
  255. package/dist/umd/hcs-10/browser.d.ts +20 -35
  256. package/dist/umd/hcs-10/browser.d.ts.map +1 -1
  257. package/dist/umd/hcs-10/index.d.ts +4 -6
  258. package/dist/umd/hcs-10/index.d.ts.map +1 -1
  259. package/dist/umd/hcs-10/registrations.d.ts.map +1 -1
  260. package/dist/umd/hcs-10/sdk.d.ts +16 -8
  261. package/dist/umd/hcs-10/sdk.d.ts.map +1 -1
  262. package/dist/umd/hcs-10/types.d.ts +2 -62
  263. package/dist/umd/hcs-10/types.d.ts.map +1 -1
  264. package/dist/umd/hcs-11/agent-builder.d.ts +53 -0
  265. package/dist/umd/hcs-11/agent-builder.d.ts.map +1 -0
  266. package/dist/umd/hcs-11/client.d.ts +82 -0
  267. package/dist/umd/hcs-11/client.d.ts.map +1 -0
  268. package/dist/umd/hcs-11/index.d.ts +4 -190
  269. package/dist/umd/hcs-11/index.d.ts.map +1 -1
  270. package/dist/umd/hcs-11/person-builder.d.ts +29 -0
  271. package/dist/umd/hcs-11/person-builder.d.ts.map +1 -0
  272. package/dist/umd/hcs-11/types.d.ts +165 -0
  273. package/dist/umd/hcs-11/types.d.ts.map +1 -0
  274. package/dist/umd/index.d.ts +1 -0
  275. package/dist/umd/index.d.ts.map +1 -1
  276. package/dist/umd/services/mirror-node.d.ts +2 -1
  277. package/dist/umd/services/mirror-node.d.ts.map +1 -1
  278. package/dist/umd/services/types.d.ts +0 -1
  279. package/dist/umd/services/types.d.ts.map +1 -1
  280. package/dist/umd/standards-sdk.umd.js +7 -7
  281. package/dist/umd/standards-sdk.umd.js.map +1 -1
  282. package/dist/umd/utils/logger.d.ts +1 -0
  283. package/dist/umd/utils/logger.d.ts.map +1 -1
  284. package/dist/umd/utils/types.d.ts +2 -0
  285. package/dist/umd/utils/types.d.ts.map +1 -0
  286. package/package.json +3 -4
  287. package/dist/es/hcs-10/agent-builder.d.ts +0 -45
  288. package/dist/es/hcs-10/agent-builder.d.ts.map +0 -1
  289. package/dist/es/hcs-10/fee-config-builder.d.ts.map +0 -1
  290. package/dist/umd/hcs-10/agent-builder.d.ts +0 -45
  291. package/dist/umd/hcs-10/agent-builder.d.ts.map +0 -1
  292. package/dist/umd/hcs-10/fee-config-builder.d.ts.map +0 -1
  293. /package/dist/es/{hcs-10 → fees}/fee-config-builder.d.ts +0 -0
  294. /package/dist/umd/{hcs-10 → fees}/fee-config-builder.d.ts +0 -0
@@ -1,489 +1,1145 @@
1
- import Buffer from "./standards-sdk.es19.js";
2
- import { HederaMirrorNode } from "./standards-sdk.es18.js";
1
+ import Buffer from "./standards-sdk.es20.js";
2
+ import { KeyList, TopicCreateTransaction, Transaction, TopicMessageSubmitTransaction, Hbar } from "@hashgraph/sdk";
3
3
  import { Logger } from "./standards-sdk.es14.js";
4
- import { Registration } from "./standards-sdk.es9.js";
5
- import { HCS11Client } from "./standards-sdk.es13.js";
6
- import { PublicKey } from "@hashgraph/sdk";
7
- import "./standards-sdk.es23.js";
8
- import axios from "./standards-sdk.es24.js";
9
- var Hcs10MemoType = /* @__PURE__ */ ((Hcs10MemoType2) => {
10
- Hcs10MemoType2["INBOUND"] = "inbound";
11
- Hcs10MemoType2["OUTBOUND"] = "outbound";
12
- Hcs10MemoType2["CONNECTION"] = "connection";
13
- return Hcs10MemoType2;
14
- })(Hcs10MemoType || {});
15
- class HCS10BaseClient extends Registration {
4
+ import { InscriptionSDK } from "./standards-sdk.es23.js";
5
+ import { HCS10BaseClient, Hcs10MemoType } from "./standards-sdk.es5.js";
6
+ import { m as mimeTypesExports } from "./standards-sdk.es24.js";
7
+ import { AgentBuilder } from "./standards-sdk.es10.js";
8
+ import { HCS11Client } from "./standards-sdk.es12.js";
9
+ import { ProgressReporter } from "./standards-sdk.es16.js";
10
+ import { inscribeWithSigner } from "./standards-sdk.es17.js";
11
+ const isBrowser = typeof window !== "undefined";
12
+ class BrowserHCSClient extends HCS10BaseClient {
16
13
  constructor(config) {
17
- super();
18
- this.network = config.network;
14
+ super({
15
+ network: config.network,
16
+ logLevel: config.logLevel,
17
+ prettyPrint: config.prettyPrint,
18
+ feeAmount: config.feeAmount
19
+ });
20
+ this.hcs11Client = null;
21
+ this.hwc = config.hwc;
22
+ if (!config.guardedRegistryBaseUrl) {
23
+ this.guardedRegistryBaseUrl = "https://moonscape.tech";
24
+ } else {
25
+ this.guardedRegistryBaseUrl = config.guardedRegistryBaseUrl;
26
+ }
27
+ let logLevel;
28
+ if (config.logLevel) {
29
+ logLevel = config.logLevel;
30
+ } else {
31
+ logLevel = "info";
32
+ }
19
33
  this.logger = Logger.getInstance({
20
- level: config.logLevel || "info",
21
- module: "HCS10-BaseClient",
34
+ level: logLevel,
35
+ module: "HCS-Browser",
22
36
  prettyPrint: config.prettyPrint
23
37
  });
24
- this.mirrorNode = new HederaMirrorNode(
25
- config.network,
26
- this.logger
27
- );
28
- this.feeAmount = config.feeAmount || 1e-3;
38
+ if (isBrowser) {
39
+ try {
40
+ const { accountId, signer } = this.getAccountAndSigner();
41
+ this.hcs11Client = new HCS11Client({
42
+ network: config.network,
43
+ auth: {
44
+ operatorId: accountId,
45
+ signer
46
+ },
47
+ logLevel: config.logLevel
48
+ });
49
+ } catch (err) {
50
+ this.logger.warn(`Failed to initialize HCS11Client: ${err}`);
51
+ }
52
+ } else {
53
+ this.logger.error(
54
+ "BrowserHCSClient initialized in server environment - browser-specific features will not be available. Use HCS10Client instead."
55
+ );
56
+ }
29
57
  }
30
- /**
31
- * Get a stream of messages from a connection topic
32
- * @param topicId The connection topic ID to get messages from
33
- * @returns A stream of filtered messages valid for connection topics
34
- */
35
- async getMessageStream(topicId) {
36
- try {
37
- const messages = await this.mirrorNode.getTopicMessages(topicId);
38
- const validOps = ["message", "close_connection"];
39
- const filteredMessages = messages.filter((msg) => {
40
- if (msg.p !== "hcs-10" || !validOps.includes(msg.op)) {
41
- return false;
42
- }
43
- if (msg.op === "message") {
44
- if (!msg.data) {
45
- return false;
46
- }
47
- if (!msg.operator_id) {
48
- return false;
49
- }
50
- if (!this.isValidOperatorId(msg.operator_id)) {
51
- return false;
52
- }
53
- }
54
- if (msg.op === "close_connection") {
55
- if (!msg.operator_id) {
56
- return false;
57
- }
58
- if (!this.isValidOperatorId(msg.operator_id)) {
59
- return false;
58
+ async sendMessage(connectionTopicId, data, memo, submitKey, options) {
59
+ this.logger.info("Sending message");
60
+ const operatorId = await this.getOperatorId();
61
+ const payload = {
62
+ p: "hcs-10",
63
+ op: "message",
64
+ operator_id: operatorId,
65
+ data,
66
+ m: memo
67
+ };
68
+ const submissionCheck = await this.canSubmitToTopic(
69
+ connectionTopicId,
70
+ this.hwc.getAccountInfo().accountId
71
+ );
72
+ const payloadString = JSON.stringify(payload);
73
+ const isLargePayload = Buffer.from(payloadString).length > 1e3;
74
+ if (isLargePayload) {
75
+ this.logger.info(
76
+ "Message payload exceeds 1000 bytes, storing via inscription"
77
+ );
78
+ try {
79
+ const contentBuffer = Buffer.from(data);
80
+ const fileName = `message-${Date.now()}.json`;
81
+ const inscriptionResult = await this.inscribeFile(
82
+ contentBuffer,
83
+ fileName,
84
+ {
85
+ progressCallback: options?.progressCallback,
86
+ waitMaxAttempts: options?.waitMaxAttempts,
87
+ waitIntervalMs: options?.waitIntervalMs
60
88
  }
89
+ );
90
+ if (inscriptionResult?.topic_id) {
91
+ payload.data = `hcs://1/${inscriptionResult.topic_id}`;
92
+ this.logger.info(
93
+ `Large message inscribed with topic ID: ${inscriptionResult.topic_id}`
94
+ );
95
+ } else {
96
+ throw new Error("Failed to inscribe large message content");
61
97
  }
62
- return true;
63
- });
64
- return {
65
- messages: filteredMessages
66
- };
67
- } catch (error) {
68
- if (this.logger) {
69
- this.logger.error(`Error fetching messages: ${error.message}`);
98
+ } catch (error) {
99
+ this.logger.error("Error inscribing large message:", error);
100
+ throw new Error(
101
+ `Failed to handle large message: ${error instanceof Error ? error.message : "Unknown error"}`
102
+ );
70
103
  }
71
- return { messages: [] };
72
104
  }
105
+ return await this.submitPayload(
106
+ connectionTopicId,
107
+ payload,
108
+ submitKey,
109
+ submissionCheck.requiresFee
110
+ );
73
111
  }
74
- /**
75
- * Checks if a user can submit to a topic and determines if a fee is required
76
- * @param topicId The topic ID to check
77
- * @param userAccountId The account ID of the user attempting to submit
78
- * @returns Object with canSubmit, requiresFee, and optional reason
79
- */
80
- async canSubmitToTopic(topicId, userAccountId) {
112
+ async submitConnectionRequest(inboundTopicId, memo) {
113
+ this.logger.info("Submitting connection request");
114
+ const accountResponse = this.getAccountAndSigner();
115
+ if (!accountResponse.accountId) {
116
+ throw new Error("Failed to retrieve user account ID");
117
+ }
118
+ const operatorId = await this.getOperatorId();
119
+ const accountId = accountResponse.accountId;
120
+ const connectionRequestMessage = {
121
+ p: "hcs-10",
122
+ op: "connection_request",
123
+ operator_id: operatorId,
124
+ m: memo
125
+ };
126
+ const response = await this.submitPayload(
127
+ inboundTopicId,
128
+ connectionRequestMessage
129
+ );
130
+ this.logger.info(
131
+ `Submitted connection request to topic ID: ${inboundTopicId}`
132
+ );
133
+ const outboundTopic = await this.retrieveOutboundConnectTopic(accountId);
134
+ if (!outboundTopic?.outboundTopic) {
135
+ this.logger.error(
136
+ `Failed to retrieve outbound topic for account ID: ${accountId}`
137
+ );
138
+ throw new Error(
139
+ `Failed to retrieve outbound topic for account ID: ${accountId}`
140
+ );
141
+ }
142
+ this.logger.info(
143
+ `Retrieved outbound topic ID: ${outboundTopic.outboundTopic} for account ID: ${accountId}`
144
+ );
145
+ const responseSequenceNumber = response?.topicSequenceNumber?.toNumber();
146
+ if (!responseSequenceNumber) {
147
+ throw new Error("Failed to get response sequence number");
148
+ }
149
+ await this.submitPayload(outboundTopic.outboundTopic, {
150
+ ...connectionRequestMessage,
151
+ outbound_topic_id: inboundTopicId,
152
+ connection_request_id: responseSequenceNumber
153
+ });
154
+ return response;
155
+ }
156
+ async getPublicKey(accountId) {
157
+ return await this.mirrorNode.getPublicKey(accountId);
158
+ }
159
+ async handleConnectionRequest(inboundTopicId, requestingAccountId, connectionId, connectionMemo = "Connection accepted. Looking forward to collaborating!", ttl = 60) {
160
+ this.logger.info("Handling connection request");
161
+ const userAccountId = this.hwc.getAccountInfo().accountId;
162
+ if (!userAccountId) {
163
+ throw new Error("Failed to retrieve user account ID");
164
+ }
165
+ const requesterKey = await this.mirrorNode.getPublicKey(
166
+ requestingAccountId
167
+ );
168
+ const accountKey = await this.mirrorNode.getPublicKey(userAccountId);
169
+ if (!accountKey) {
170
+ throw new Error("Failed to retrieve public key");
171
+ }
172
+ const thresholdKey = new KeyList([accountKey, requesterKey], 1);
173
+ const memo = this._generateHcs10Memo(Hcs10MemoType.CONNECTION, {
174
+ ttl,
175
+ inboundTopicId,
176
+ connectionId
177
+ });
178
+ const transaction = new TopicCreateTransaction().setTopicMemo(memo).setAdminKey(thresholdKey).setSubmitKey(thresholdKey);
179
+ this.logger.debug("Executing topic creation transaction");
180
+ const txResponse = await this.hwc.executeTransactionWithErrorHandling(
181
+ transaction,
182
+ false
183
+ );
184
+ if (txResponse.error) {
185
+ this.logger.error(txResponse.error);
186
+ throw new Error(txResponse.error);
187
+ }
188
+ const resultReceipt = txResponse.result;
189
+ if (!resultReceipt?.topicId) {
190
+ this.logger.error("Failed to create topic: topicId is null");
191
+ throw new Error("Failed to create topic: topicId is null");
192
+ }
193
+ const connectionTopicId = resultReceipt.topicId.toString();
194
+ const operatorId = `${inboundTopicId}@${userAccountId}`;
195
+ const confirmedConnectionSequenceNumber = await this.confirmConnection(
196
+ inboundTopicId,
197
+ connectionTopicId,
198
+ requestingAccountId,
199
+ connectionId,
200
+ operatorId,
201
+ connectionMemo
202
+ );
203
+ return {
204
+ connectionTopicId,
205
+ confirmedConnectionSequenceNumber,
206
+ operatorId
207
+ };
208
+ }
209
+ async confirmConnection(inboundTopicId, connectionTopicId, connectedAccountId, connectionId, operatorId, memo) {
210
+ this.logger.info("Confirming connection");
211
+ const payload = {
212
+ p: "hcs-10",
213
+ op: "connection_created",
214
+ connection_topic_id: connectionTopicId,
215
+ connected_account_id: connectedAccountId,
216
+ operator_id: operatorId,
217
+ connection_id: connectionId,
218
+ m: memo
219
+ };
220
+ const transactionResponse = await this.submitPayload(
221
+ inboundTopicId,
222
+ payload
223
+ );
224
+ if (!transactionResponse?.topicSequenceNumber) {
225
+ this.logger.error(
226
+ "Failed to confirm connection: sequence number is null"
227
+ );
228
+ throw new Error("Failed to confirm connection: sequence number is null");
229
+ }
230
+ return transactionResponse.topicSequenceNumber.toNumber();
231
+ }
232
+ async create(builder, options) {
233
+ const progressCallback = options?.progressCallback;
234
+ const progressReporter = new ProgressReporter({
235
+ module: "ProfileCreate",
236
+ logger: this.logger,
237
+ callback: progressCallback
238
+ });
81
239
  try {
82
- const topicInfo = await this.mirrorNode.getTopicInfo(topicId);
83
- if (!topicInfo) {
84
- return {
85
- canSubmit: false,
86
- requiresFee: false,
87
- reason: "Topic does not exist"
240
+ const isAgentBuilder = builder instanceof AgentBuilder;
241
+ let state;
242
+ if (options?.existingState) {
243
+ state = options.existingState;
244
+ } else {
245
+ state = {
246
+ currentStage: "init",
247
+ completedPercentage: 0,
248
+ createdResources: []
88
249
  };
89
250
  }
90
- if (!topicInfo.submit_key?.key) {
91
- return { canSubmit: true, requiresFee: false };
251
+ if (isAgentBuilder) {
252
+ this.logger.info("Creating Agent Profile and HCS-10 Topics");
253
+ const agentConfig = builder.build();
254
+ state.agentMetadata = agentConfig.metadata;
255
+ } else {
256
+ this.logger.info("Creating Person HCS-11 Profile");
92
257
  }
93
- try {
94
- const userPublicKey = await this.mirrorNode.getPublicKey(userAccountId);
95
- if (topicInfo.submit_key._type === "ProtobufEncoded") {
96
- const keyBytes = Buffer.from(topicInfo.submit_key.key, "hex");
97
- const hasAccess = await this.mirrorNode.checkKeyListAccess(
98
- keyBytes,
99
- userPublicKey
100
- );
101
- if (hasAccess) {
102
- return { canSubmit: true, requiresFee: false };
103
- }
104
- } else {
105
- const topicSubmitKey = PublicKey.fromString(topicInfo.submit_key.key);
106
- if (userPublicKey.toString() === topicSubmitKey.toString()) {
107
- return { canSubmit: true, requiresFee: false };
108
- }
258
+ progressReporter.preparing(
259
+ `Starting ${isAgentBuilder ? "agent" : "person"} resource creation`,
260
+ 0,
261
+ {
262
+ state
109
263
  }
110
- } catch (error) {
111
- this.logger.error(
112
- `Key validation error: ${error instanceof Error ? error.message : String(error)}`
264
+ );
265
+ const {
266
+ inboundTopicId,
267
+ outboundTopicId,
268
+ state: updatedState
269
+ } = await this.createCommunicationTopics(options, progressReporter);
270
+ state = updatedState;
271
+ if (!isAgentBuilder) {
272
+ builder.setInboundTopicId(inboundTopicId);
273
+ builder.setOutboundTopicId(outboundTopicId);
274
+ }
275
+ let pfpTopicId;
276
+ let hasPfpBuffer;
277
+ let pfpFileName;
278
+ if (isAgentBuilder) {
279
+ const agentProfile = builder.build();
280
+ pfpTopicId = agentProfile.existingPfpTopicId || state.pfpTopicId;
281
+ hasPfpBuffer = agentProfile.pfpBuffer;
282
+ pfpFileName = agentProfile.pfpFileName || "pfp.png";
283
+ } else {
284
+ const personProfile = builder.build();
285
+ pfpTopicId = state.pfpTopicId;
286
+ hasPfpBuffer = personProfile.pfpBuffer;
287
+ pfpFileName = personProfile.pfpFileName;
288
+ }
289
+ if (!pfpTopicId && hasPfpBuffer && pfpFileName) {
290
+ pfpTopicId = await this.handleProfilePictureCreation(
291
+ hasPfpBuffer,
292
+ pfpFileName,
293
+ state,
294
+ progressReporter
295
+ );
296
+ } else if (pfpTopicId) {
297
+ progressReporter.preparing(
298
+ `Using existing profile picture: ${pfpTopicId}`,
299
+ 50,
300
+ { state }
113
301
  );
302
+ state.pfpTopicId = pfpTopicId;
114
303
  }
115
- if (topicInfo.fee_schedule_key?.key && topicInfo.custom_fees?.fixed_fees?.length > 0) {
116
- return {
117
- canSubmit: true,
118
- requiresFee: true,
119
- reason: "Requires fee payment via HIP-991"
120
- };
304
+ await this.createAndInscribeProfile(
305
+ isAgentBuilder,
306
+ builder,
307
+ pfpTopicId,
308
+ state,
309
+ inboundTopicId,
310
+ outboundTopicId,
311
+ options,
312
+ progressReporter
313
+ );
314
+ state.currentStage = "complete";
315
+ state.completedPercentage = 100;
316
+ progressReporter.completed(
317
+ `${isAgentBuilder ? "Agent" : "Person"} profile created successfully`,
318
+ {
319
+ profileTopicId: state.profileTopicId,
320
+ inboundTopicId,
321
+ outboundTopicId,
322
+ pfpTopicId,
323
+ state
324
+ }
325
+ );
326
+ let outTopicId = "";
327
+ if (state.outboundTopicId) {
328
+ outTopicId = state.outboundTopicId;
329
+ }
330
+ let inTopicId = "";
331
+ if (state.inboundTopicId) {
332
+ inTopicId = state.inboundTopicId;
333
+ }
334
+ let profilePicTopicId = "";
335
+ if (state.pfpTopicId) {
336
+ profilePicTopicId = state.pfpTopicId;
337
+ }
338
+ let profTopicId = "";
339
+ if (state.profileTopicId) {
340
+ profTopicId = state.profileTopicId;
121
341
  }
122
342
  return {
123
- canSubmit: false,
124
- requiresFee: false,
125
- reason: "User does not have submit permission for this topic"
343
+ outboundTopicId: outTopicId,
344
+ inboundTopicId: inTopicId,
345
+ pfpTopicId: profilePicTopicId,
346
+ profileTopicId: profTopicId,
347
+ success: true,
348
+ state
126
349
  };
127
350
  } catch (error) {
128
- const errorMessage = error instanceof Error ? error.message : String(error);
129
- this.logger.error(`Topic submission validation error: ${errorMessage}`);
351
+ progressReporter.failed("Error during profile creation", {
352
+ error: error.message
353
+ });
130
354
  return {
131
- canSubmit: false,
132
- requiresFee: false,
133
- reason: `Error: ${errorMessage}`
355
+ outboundTopicId: "",
356
+ inboundTopicId: "",
357
+ pfpTopicId: "",
358
+ profileTopicId: "",
359
+ success: false,
360
+ error: error.message,
361
+ state: {
362
+ currentStage: "init",
363
+ completedPercentage: 0,
364
+ error: error.message
365
+ }
134
366
  };
135
367
  }
136
368
  }
137
- /**
138
- * Get all messages from a topic
139
- * @param topicId The topic ID to get messages from
140
- * @returns All messages from the topic
141
- */
142
- async getMessages(topicId) {
143
- try {
144
- const messages = await this.mirrorNode.getTopicMessages(topicId);
145
- const validatedMessages = messages.filter((msg) => {
146
- if (msg.p !== "hcs-10") {
147
- return false;
148
- }
149
- if (msg.op === "message") {
150
- if (!msg.data) {
151
- return false;
369
+ async handleProfilePictureCreation(pfpBuffer, pfpFileName, state, progressReporter) {
370
+ state.currentStage = "pfp";
371
+ progressReporter.preparing("Creating profile picture", 30, {
372
+ state
373
+ });
374
+ const pfpProgress = progressReporter.createSubProgress({
375
+ minPercent: 30,
376
+ maxPercent: 50,
377
+ logPrefix: "PFP"
378
+ });
379
+ const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName, {
380
+ progressCallback: (data) => pfpProgress.report({
381
+ ...data,
382
+ progressPercent: data.progressPercent ?? 0,
383
+ details: { ...data.details, state }
384
+ })
385
+ });
386
+ if (!pfpResult.success) {
387
+ let errorMessage = "Failed to inscribe profile picture";
388
+ if (pfpResult.error) {
389
+ errorMessage = pfpResult.error;
390
+ }
391
+ throw new Error(errorMessage);
392
+ }
393
+ const pfpTopicId = pfpResult.pfpTopicId;
394
+ state.pfpTopicId = pfpTopicId;
395
+ if (state.createdResources) {
396
+ state.createdResources.push(`pfp:${state.pfpTopicId}`);
397
+ }
398
+ progressReporter.preparing("Profile picture created", 50, { state });
399
+ return pfpTopicId;
400
+ }
401
+ async createAndInscribeProfile(isAgentBuilder, builder, pfpTopicId, state, inboundTopicId, outboundTopicId, options, progressReporter) {
402
+ if (!this.hcs11Client) {
403
+ if (progressReporter) {
404
+ progressReporter.failed("HCS11Client is not available");
405
+ }
406
+ throw new Error("HCS11Client is not available");
407
+ }
408
+ this.logger.info("Creating and inscribing profile");
409
+ if (!state.profileTopicId) {
410
+ if (progressReporter) {
411
+ progressReporter.preparing(
412
+ `Storing HCS-11 ${isAgentBuilder ? "agent" : "person"} profile`,
413
+ 80
414
+ );
415
+ }
416
+ const profileProgress = progressReporter?.createSubProgress({
417
+ minPercent: 80,
418
+ maxPercent: 95,
419
+ logPrefix: "StoreProfile"
420
+ });
421
+ let hcs11Profile;
422
+ if (isAgentBuilder) {
423
+ const agentProfile = builder.build();
424
+ const socialLinks = agentProfile.metadata?.socials ? Object.entries(agentProfile.metadata.socials).map(
425
+ ([platform, handle]) => ({
426
+ platform,
427
+ handle
428
+ })
429
+ ) : [];
430
+ hcs11Profile = this.hcs11Client.createAIAgentProfile(
431
+ agentProfile.name,
432
+ agentProfile.metadata?.type === "manual" ? 0 : 1,
433
+ agentProfile.capabilities || [],
434
+ agentProfile.metadata?.model || "unknown",
435
+ {
436
+ alias: agentProfile.name.toLowerCase().replace(/\s+/g, "_"),
437
+ bio: agentProfile.bio,
438
+ profileImage: pfpTopicId ? `hcs://1/${pfpTopicId}` : void 0,
439
+ socials: socialLinks,
440
+ properties: agentProfile.metadata?.properties || {},
441
+ inboundTopicId,
442
+ outboundTopicId,
443
+ creator: agentProfile.metadata?.creator
152
444
  }
153
- if (msg.operator_id) {
154
- if (!this.isValidOperatorId(msg.operator_id)) {
155
- return false;
156
- }
445
+ );
446
+ } else {
447
+ const personProfile = builder.build();
448
+ const { pfpBuffer, pfpFileName, ...cleanProfile } = personProfile;
449
+ hcs11Profile = this.hcs11Client.createPersonalProfile(
450
+ personProfile.display_name,
451
+ {
452
+ alias: personProfile.alias,
453
+ bio: personProfile.bio,
454
+ socials: personProfile.socials,
455
+ profileImage: pfpTopicId ? `hcs://1/${pfpTopicId}` : personProfile.profileImage,
456
+ properties: personProfile.properties,
457
+ inboundTopicId,
458
+ outboundTopicId
157
459
  }
460
+ );
461
+ }
462
+ const profileResult = await this.hcs11Client.createAndInscribeProfile(
463
+ hcs11Profile,
464
+ options?.updateAccountMemo ?? true,
465
+ {
466
+ progressCallback: (data) => profileProgress?.report({
467
+ ...data,
468
+ progressPercent: data.progressPercent ?? 0
469
+ })
158
470
  }
159
- return true;
160
- });
161
- return {
162
- messages: validatedMessages
163
- };
164
- } catch (error) {
165
- if (this.logger) {
166
- this.logger.error(`Error fetching messages: ${error.message}`);
471
+ );
472
+ if (!profileResult.success) {
473
+ if (progressReporter) {
474
+ progressReporter.failed(
475
+ `Failed to inscribe ${isAgentBuilder ? "agent" : "person"} profile`,
476
+ {
477
+ error: profileResult.error
478
+ }
479
+ );
480
+ }
481
+ let errorMessage = `Failed to inscribe ${isAgentBuilder ? "agent" : "person"} profile`;
482
+ if (profileResult.error) {
483
+ errorMessage = profileResult.error;
484
+ }
485
+ throw new Error(errorMessage);
486
+ }
487
+ state.profileTopicId = profileResult.profileTopicId;
488
+ if (state.createdResources) {
489
+ state.createdResources.push(`profile:${profileResult.profileTopicId}`);
167
490
  }
168
- return { messages: [] };
491
+ if (progressReporter) {
492
+ progressReporter.preparing("HCS-11 Profile stored", 95, { state });
493
+ }
494
+ } else if (progressReporter) {
495
+ progressReporter.preparing(
496
+ `Using existing ${isAgentBuilder ? "agent" : "person"} profile`,
497
+ 95,
498
+ {
499
+ state
500
+ }
501
+ );
169
502
  }
170
503
  }
171
- async requestAccount(account) {
172
- try {
173
- return await this.mirrorNode.requestAccount(account);
174
- } catch (e) {
175
- this.logger.error("Failed to fetch account", e);
176
- throw e;
504
+ initializeRegistrationState(inboundTopicId, existingState) {
505
+ const state = existingState || {
506
+ inboundTopicId,
507
+ currentStage: "registration",
508
+ completedPercentage: 0,
509
+ createdResources: []
510
+ };
511
+ if (state.currentStage !== "registration" && state.currentStage !== "complete") {
512
+ state.currentStage = "registration";
177
513
  }
514
+ return state;
178
515
  }
179
- async getAccountMemo(accountId) {
180
- return await this.mirrorNode.getAccountMemo(accountId);
516
+ updateStateForCompletedRegistration(state, inboundTopicId) {
517
+ state.currentStage = "complete";
518
+ state.completedPercentage = 100;
519
+ if (state.createdResources) {
520
+ state.createdResources.push(`registration:${inboundTopicId}`);
521
+ }
181
522
  }
182
- async retrieveProfile(accountId) {
183
- this.logger.info(`Retrieving profile for account: ${accountId}`);
523
+ async registerAgentWithGuardedRegistry(accountId, network = this.network, options) {
184
524
  try {
185
- const hcs11Client = new HCS11Client({
186
- network: this.network,
187
- auth: {
188
- operatorId: "0.0.0"
189
- // Read-only operations only
190
- },
191
- logLevel: "info"
525
+ this.logger.info("Registering agent with guarded registry");
526
+ const agentProfile = await this.retrieveProfile(accountId);
527
+ const inboundTopicId = agentProfile.topicInfo.inboundTopic;
528
+ const state = this.initializeRegistrationState(
529
+ inboundTopicId,
530
+ options?.existingState
531
+ );
532
+ const progressReporter = new ProgressReporter({
533
+ module: "AgentRegistration",
534
+ logger: this.logger,
535
+ callback: options?.progressCallback
536
+ });
537
+ progressReporter.preparing("Preparing agent registration", 10, {
538
+ inboundTopicId,
539
+ accountId
192
540
  });
193
- const profileResult = await hcs11Client.fetchProfileByAccountId(
541
+ const registrationResult = await this.executeRegistration(
194
542
  accountId,
195
- this.network
543
+ network,
544
+ this.guardedRegistryBaseUrl,
545
+ this.logger
196
546
  );
197
- if (!profileResult?.success) {
198
- this.logger.error(
199
- `Failed to retrieve profile for account ID: ${accountId}`,
200
- profileResult?.error
201
- );
547
+ if (!registrationResult.success) {
202
548
  return {
203
- profile: null,
204
- success: false,
205
- error: profileResult?.error || `Failed to retrieve profile for account ID: ${accountId}`
549
+ ...registrationResult,
550
+ state
206
551
  };
207
552
  }
208
- const profile = profileResult.profile;
209
- let topicInfo = null;
210
- if (profileResult.topicInfo?.inboundTopic && profileResult.topicInfo?.outboundTopic && profileResult.topicInfo?.profileTopicId) {
211
- topicInfo = {
212
- inboundTopic: profileResult.topicInfo.inboundTopic,
213
- outboundTopic: profileResult.topicInfo.outboundTopic,
214
- profileTopicId: profileResult.topicInfo.profileTopicId
215
- };
216
- const cacheKey = `${accountId}-${this.network}`;
217
- HCS10Cache.getInstance().set(cacheKey, topicInfo);
553
+ progressReporter.submitting("Submitting registration to registry", 30, {
554
+ transactionId: registrationResult.transactionId
555
+ });
556
+ if (registrationResult.transaction) {
557
+ const transaction = Transaction.fromBytes(
558
+ Buffer.from(registrationResult.transaction, "base64")
559
+ );
560
+ this.logger.info(`Processing registration transaction`);
561
+ const txResult = await this.hwc.executeTransactionWithErrorHandling(
562
+ transaction,
563
+ true
564
+ );
565
+ if (txResult.error) {
566
+ return {
567
+ ...registrationResult,
568
+ error: txResult.error,
569
+ success: false,
570
+ state
571
+ };
572
+ }
573
+ this.logger.info(`Successfully processed registration transaction`);
218
574
  }
575
+ progressReporter.confirming("Confirming registration transaction", 60, {
576
+ accountId,
577
+ inboundTopicId,
578
+ transactionId: registrationResult.transactionId
579
+ });
580
+ const maxAttempts = options?.maxAttempts ?? 60;
581
+ const delayMs = options?.delayMs ?? 2e3;
582
+ const confirmed = await this.waitForRegistrationConfirmation(
583
+ registrationResult.transactionId,
584
+ network,
585
+ this.guardedRegistryBaseUrl,
586
+ maxAttempts,
587
+ delayMs,
588
+ this.logger
589
+ );
590
+ this.updateStateForCompletedRegistration(state, inboundTopicId);
591
+ progressReporter.completed("Agent registration complete", {
592
+ transactionId: registrationResult.transactionId,
593
+ inboundTopicId,
594
+ state,
595
+ confirmed
596
+ });
219
597
  return {
220
- profile,
221
- topicInfo,
222
- success: true
598
+ ...registrationResult,
599
+ confirmed,
600
+ state
223
601
  };
224
602
  } catch (error) {
225
- this.logger.error("Failed to retrieve profile:", error);
603
+ this.logger.error(`Registration error: ${error.message}`);
226
604
  return {
227
- profile: null,
605
+ error: `Error during registration: ${error.message}`,
228
606
  success: false,
229
- error: error instanceof Error ? error.message : String(error)
607
+ state: {
608
+ currentStage: "registration",
609
+ completedPercentage: 0,
610
+ error: error.message
611
+ }
230
612
  };
231
613
  }
232
614
  }
233
- async retrieveOutboundConnectTopic(accountId) {
234
- this.logger.info(`Retrieving topics for account: ${accountId}`);
615
+ async createAndRegisterAgent(builder, options) {
235
616
  try {
236
- const profileResponse = await this.retrieveProfile(accountId);
237
- if (!profileResponse?.success) {
238
- throw new Error(profileResponse.error || "Failed to retrieve profile");
617
+ const agentConfig = builder.build();
618
+ const progressCallback = options?.progressCallback;
619
+ const progressReporter = new ProgressReporter({
620
+ module: "AgentCreateRegister",
621
+ logger: this.logger,
622
+ callback: progressCallback
623
+ });
624
+ let state = options?.existingState || {
625
+ currentStage: "init",
626
+ completedPercentage: 0,
627
+ createdResources: []
628
+ };
629
+ state.agentMetadata = agentConfig.metadata;
630
+ progressReporter.preparing("Starting agent creation process", 0, {
631
+ state
632
+ });
633
+ if (state.currentStage !== "complete" || !state.inboundTopicId || !state.outboundTopicId || !state.profileTopicId) {
634
+ const createResult = await this.create(builder, {
635
+ progressCallback: (progress) => {
636
+ const adjustedPercent = (progress.progressPercent || 0) * 0.3;
637
+ progressReporter.report({
638
+ ...progress,
639
+ progressPercent: adjustedPercent,
640
+ details: {
641
+ ...progress.details,
642
+ state: progress.details?.state || state
643
+ }
644
+ });
645
+ },
646
+ existingState: state,
647
+ updateAccountMemo: false
648
+ });
649
+ if (!("state" in createResult)) {
650
+ throw new Error("Create method did not return expected agent state.");
651
+ }
652
+ if (!createResult.success) {
653
+ throw new Error(
654
+ createResult.error || "Failed to create agent resources"
655
+ );
656
+ }
657
+ state = createResult.state;
658
+ state.agentMetadata = agentConfig.metadata;
239
659
  }
240
- const profile = profileResponse.profile;
241
- if (!profile.inboundTopicId || !profile.outboundTopicId) {
242
- throw new Error(
243
- `Invalid HCS-11 profile for HCS-10 agent: missing inboundTopicId or outboundTopicId`
660
+ progressReporter.preparing(
661
+ `Agent creation status: ${state.currentStage}, ${state.completedPercentage}%`,
662
+ 30,
663
+ { state }
664
+ );
665
+ const { accountId } = this.getAccountAndSigner();
666
+ if (state.currentStage !== "complete" || !state.createdResources?.includes(
667
+ `registration:${state.inboundTopicId}`
668
+ )) {
669
+ if (options?.baseUrl) {
670
+ this.guardedRegistryBaseUrl = options.baseUrl;
671
+ }
672
+ const registrationResult = await this.registerAgentWithGuardedRegistry(
673
+ accountId,
674
+ agentConfig.network,
675
+ {
676
+ progressCallback: (progress) => {
677
+ const adjustedPercent = 30 + (progress.progressPercent || 0) * 0.7;
678
+ progressReporter.report({
679
+ ...progress,
680
+ progressPercent: adjustedPercent,
681
+ details: {
682
+ ...progress.details,
683
+ state: progress.details?.state || state
684
+ }
685
+ });
686
+ },
687
+ maxAttempts: options?.maxAttempts,
688
+ delayMs: options?.delayMs,
689
+ existingState: state
690
+ }
244
691
  );
692
+ if (!registrationResult.success) {
693
+ throw new Error(
694
+ registrationResult.error || "Failed to register agent with registry"
695
+ );
696
+ }
697
+ state = registrationResult.state;
698
+ if (state.profileTopicId) {
699
+ await this.hcs11Client?.updateAccountMemoWithProfile(
700
+ accountId,
701
+ state.profileTopicId
702
+ );
703
+ }
245
704
  }
246
- const topicInfo = {
247
- inboundTopic: profile.inboundTopicId,
248
- outboundTopic: profile.outboundTopicId,
249
- profileTopicId: profile.profileTopicId
705
+ progressReporter.completed("Agent creation and registration complete", {
706
+ state
707
+ });
708
+ return {
709
+ success: true,
710
+ state,
711
+ metadata: {
712
+ accountId,
713
+ operatorId: `${state.inboundTopicId}@${accountId}`,
714
+ inboundTopicId: state.inboundTopicId,
715
+ outboundTopicId: state.outboundTopicId,
716
+ profileTopicId: state.profileTopicId,
717
+ pfpTopicId: state.pfpTopicId,
718
+ privateKey: null,
719
+ ...state.agentMetadata
720
+ }
250
721
  };
251
- const cacheKey = `${accountId}-${this.network}`;
252
- HCS10Cache.getInstance().set(cacheKey, topicInfo);
253
- return topicInfo;
254
722
  } catch (error) {
255
- this.logger.error("Failed to retrieve topic info:", error);
256
- throw error;
723
+ this.logger.error(
724
+ `Failed to create and register agent: ${error.message}`
725
+ );
726
+ return {
727
+ success: false,
728
+ error: `Failed to create and register agent: ${error.message}`,
729
+ state: options?.existingState || {
730
+ currentStage: "init",
731
+ completedPercentage: 0,
732
+ error: error.message
733
+ }
734
+ };
257
735
  }
258
736
  }
259
- async retrieveOutboundMessages(agentAccountId) {
737
+ async storeHCS11Profile(agentName, agentBio, inboundTopicId, outboundTopicId, capabilities = [], metadata = {}, pfpBuffer, pfpFileName, existingPfpTopicId, options) {
260
738
  try {
261
- const topicInfo = await this.retrieveOutboundConnectTopic(agentAccountId);
262
- if (!topicInfo) {
263
- this.logger.warn(
264
- `No outbound connect topic found for agentAccountId: ${agentAccountId}`
739
+ const progressCallback = options?.progressCallback;
740
+ const progressReporter = new ProgressReporter({
741
+ module: "StoreHCS11Profile",
742
+ logger: this.logger,
743
+ callback: progressCallback
744
+ });
745
+ progressReporter.preparing("Preparing agent profile data", 0);
746
+ let pfpTopicId = existingPfpTopicId;
747
+ if (!pfpTopicId && pfpBuffer && pfpFileName) {
748
+ const pfpProgress = progressReporter.createSubProgress({
749
+ minPercent: 0,
750
+ maxPercent: 60,
751
+ logPrefix: "PFP"
752
+ });
753
+ const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName, {
754
+ progressCallback: (data) => {
755
+ pfpProgress.report({
756
+ stage: data.stage,
757
+ message: data.message,
758
+ progressPercent: data.progressPercent || 0,
759
+ details: data.details
760
+ });
761
+ }
762
+ });
763
+ if (!pfpResult.success) {
764
+ progressReporter.failed(
765
+ "Failed to inscribe profile picture, continuing without PFP"
766
+ );
767
+ } else {
768
+ pfpTopicId = pfpResult.pfpTopicId;
769
+ }
770
+ } else if (existingPfpTopicId) {
771
+ progressReporter.preparing(
772
+ `Using existing profile picture: ${existingPfpTopicId}`,
773
+ 30
265
774
  );
266
- return [];
775
+ } else {
776
+ progressReporter.preparing("No profile picture provided", 30);
267
777
  }
268
- const response = await this.getMessages(topicInfo.outboundTopic);
269
- return response.messages.filter(
270
- (msg) => msg.p === "hcs-10" && (msg.op === "connection_request" || msg.op === "connection_created" || msg.op === "message")
778
+ if (!this.hcs11Client) {
779
+ progressReporter.failed(
780
+ "HCS11Client is not available in this environment"
781
+ );
782
+ return {
783
+ profileTopicId: "",
784
+ success: false,
785
+ error: "HCS11Client is not available in this environment",
786
+ transactionId: ""
787
+ };
788
+ }
789
+ const agentType = this.hcs11Client.getAgentTypeFromMetadata({
790
+ type: metadata.type || "autonomous"
791
+ });
792
+ progressReporter.preparing("Building agent profile", 65);
793
+ const formattedSocials = metadata.socials ? Object.entries(metadata.socials).filter(([_, handle]) => handle).map(([platform, handle]) => ({
794
+ platform,
795
+ handle
796
+ })) : void 0;
797
+ const profile = this.hcs11Client.createAIAgentProfile(
798
+ agentName,
799
+ agentType,
800
+ capabilities,
801
+ metadata.model || "unknown",
802
+ {
803
+ alias: agentName.toLowerCase().replace(/\s+/g, "_"),
804
+ bio: agentBio,
805
+ profileImage: pfpTopicId ? `hcs://1/${pfpTopicId}` : void 0,
806
+ socials: formattedSocials,
807
+ properties: {
808
+ version: metadata.version || "1.0.0",
809
+ creator: metadata.creator || "Unknown",
810
+ supported_languages: metadata.supported_languages || ["en"],
811
+ permissions: metadata.permissions || [],
812
+ model_details: metadata.model_details,
813
+ training: metadata.training,
814
+ capabilities_description: metadata.capabilities_description,
815
+ ...metadata
816
+ },
817
+ inboundTopicId,
818
+ outboundTopicId,
819
+ creator: metadata.creator
820
+ }
271
821
  );
822
+ const profileProgress = progressReporter.createSubProgress({
823
+ minPercent: 65,
824
+ maxPercent: 100,
825
+ logPrefix: "Profile"
826
+ });
827
+ const profileResult = await this.hcs11Client.createAndInscribeProfile(
828
+ profile,
829
+ true,
830
+ {
831
+ progressCallback: (profileData) => {
832
+ profileProgress.report({
833
+ stage: profileData.stage,
834
+ message: profileData.message,
835
+ progressPercent: profileData.progressPercent || 0,
836
+ details: profileData.details
837
+ });
838
+ }
839
+ }
840
+ );
841
+ if (!profileResult.success) {
842
+ progressReporter.failed("Failed to inscribe profile");
843
+ return {
844
+ profileTopicId: "",
845
+ success: false,
846
+ error: profileResult.error || "Failed to inscribe profile",
847
+ transactionId: profileResult.transactionId || ""
848
+ };
849
+ }
850
+ progressReporter.completed("Profile stored successfully", {
851
+ profileTopicId: profileResult.profileTopicId
852
+ });
853
+ return {
854
+ profileTopicId: profileResult.profileTopicId,
855
+ pfpTopicId,
856
+ success: true,
857
+ transactionId: profileResult.transactionId || ""
858
+ };
272
859
  } catch (error) {
273
- this.logger.error("Failed to retrieve outbound messages:", error);
274
- return [];
860
+ this.logger.error(`Error storing HCS11 profile: ${error.message}`);
861
+ return {
862
+ profileTopicId: "",
863
+ success: false,
864
+ error: error.message,
865
+ transactionId: ""
866
+ };
275
867
  }
276
868
  }
277
- async hasConnectionCreated(agentAccountId, connectionId) {
278
- try {
279
- const outBoundTopic = await this.retrieveOutboundConnectTopic(
280
- agentAccountId
869
+ async createTopic(memo, adminKey, submitKey) {
870
+ this.logger.info("Creating topic");
871
+ const { accountId, signer } = this.getAccountAndSigner();
872
+ const transaction = new TopicCreateTransaction().setTopicMemo(memo);
873
+ const publicKey = await this.mirrorNode.getPublicKey(accountId);
874
+ if (adminKey && publicKey) {
875
+ transaction.setAdminKey(publicKey);
876
+ transaction.setAutoRenewAccountId(accountId);
877
+ }
878
+ if (submitKey && publicKey) {
879
+ transaction.setSubmitKey(publicKey);
880
+ }
881
+ const transactionResponse = await this.hwc.executeTransactionWithErrorHandling(
882
+ transaction,
883
+ false
884
+ );
885
+ const error = transactionResponse.error;
886
+ if (error) {
887
+ this.logger.error(error);
888
+ return {
889
+ success: false,
890
+ error
891
+ };
892
+ }
893
+ const resultReceipt = transactionResponse.result;
894
+ if (!resultReceipt?.topicId) {
895
+ this.logger.error("Failed to create topic: topicId is null");
896
+ return {
897
+ success: false,
898
+ error: "Failed to create topic: topicId is null"
899
+ };
900
+ }
901
+ return {
902
+ success: true,
903
+ topicId: resultReceipt.topicId.toString()
904
+ };
905
+ }
906
+ async submitPayload(topicId, payload, submitKey, requiresFee) {
907
+ this.logger.debug(`Submitting payload to topic ${topicId}`);
908
+ let message;
909
+ if (typeof payload === "string") {
910
+ message = payload;
911
+ } else {
912
+ message = JSON.stringify(payload);
913
+ }
914
+ const transaction = new TopicMessageSubmitTransaction().setTopicId(topicId).setMessage(message);
915
+ let transactionResponse;
916
+ if (requiresFee) {
917
+ this.logger.info(
918
+ "Topic requires fee payment, setting max transaction fee"
281
919
  );
282
- const messages = await this.retrieveOutboundMessages(
283
- outBoundTopic.outboundTopic
920
+ transaction.setMaxTransactionFee(new Hbar(this.feeAmount));
921
+ transaction.setTransactionMemo("HIP-991 Fee Payment");
922
+ }
923
+ if (submitKey) {
924
+ const { accountId, signer } = this.getAccountAndSigner();
925
+ transaction.freezeWithSigner(signer);
926
+ const signedTransaction = await transaction.sign(submitKey);
927
+ transactionResponse = await this.hwc.executeTransactionWithErrorHandling(
928
+ signedTransaction,
929
+ true
284
930
  );
285
- return messages.some(
286
- (msg) => msg.op === "connection_created" && msg.connection_id === connectionId
931
+ } else {
932
+ transactionResponse = await this.hwc.executeTransactionWithErrorHandling(
933
+ transaction,
934
+ false
287
935
  );
288
- } catch (error) {
289
- this.logger.error("Failed to check connection created:", error);
290
- return false;
291
936
  }
292
- }
293
- /**
294
- * Gets message content, resolving any HRL references if needed
295
- * @param data The message data which might be an HRL reference
296
- * @returns The resolved content
297
- */
298
- async getMessageContent(data) {
299
- const hrlPattern = /^hcs:\/\/(\d+)\/([0-9.]+)$/;
300
- const match = data.match(hrlPattern);
301
- if (!match) {
302
- return data;
303
- }
304
- const [_, standard, topicId] = match;
305
- this.logger.info(
306
- `Resolving HRL reference: standard=${standard}, topicId=${topicId}`
307
- );
308
- try {
309
- const cdnUrl = `https://kiloscribe.com/api/inscription-cdn/${topicId}?network=${this.network}`;
310
- const response = await axios.get(cdnUrl);
311
- if (!response.data) {
312
- throw new Error(`Failed to fetch content from topic: ${topicId}`);
313
- }
314
- return response.data.content || response.data.text || JSON.stringify(response.data);
315
- } catch (error) {
937
+ if (transactionResponse?.error) {
316
938
  this.logger.error(
317
- `Error resolving HRL reference: ${error instanceof Error ? error.message : "Unknown error"}`
939
+ `Failed to submit payload: ${transactionResponse.error}`
318
940
  );
319
- throw new Error(
320
- `Failed to resolve HRL reference: ${error instanceof Error ? error.message : "Unknown error"}`
941
+ throw new Error(`Failed to submit payload: ${transactionResponse.error}`);
942
+ }
943
+ if (!transactionResponse?.result) {
944
+ this.logger.error(
945
+ "Failed to submit message: receipt is null or undefined"
321
946
  );
947
+ throw new Error("Failed to submit message: receipt is null or undefined");
322
948
  }
949
+ this.logger.debug("Payload submitted successfully via HWC");
950
+ return transactionResponse.result;
323
951
  }
324
- /**
325
- * Records an outbound connection confirmation
326
- * @param outboundTopicId The ID of the outbound topic
327
- * @param connectionRequestId The ID of the connection request
328
- * @param confirmedRequestId The ID of the confirmed request
329
- * @param connectionTopicId The ID of the connection topic
330
- * @param operatorId The operator ID of the message sender
331
- * @param memo An optional memo for the message
332
- */
333
- async recordOutboundConnectionConfirmation({
334
- outboundTopicId,
335
- connectionRequestId,
336
- confirmedRequestId,
337
- connectionTopicId,
338
- operatorId,
339
- memo
340
- }) {
341
- const payload = {
342
- p: "hcs-10",
343
- op: "connection_created",
344
- connection_topic_id: connectionTopicId,
345
- outbound_topic_id: outboundTopicId,
346
- confirmed_request_id: confirmedRequestId,
347
- connection_request_id: connectionRequestId,
348
- operator_id: operatorId,
349
- m: memo
952
+ async inscribeFile(buffer, fileName, options) {
953
+ const { accountId, signer } = this.getAccountAndSigner();
954
+ const mimeType = mimeTypesExports.lookup(fileName) || "application/octet-stream";
955
+ const sdk = await InscriptionSDK.createWithAuth({
956
+ type: "client",
957
+ accountId,
958
+ signer,
959
+ network: this.network
960
+ });
961
+ const inscriptionOptions = {
962
+ mode: "file",
963
+ waitForConfirmation: true,
964
+ waitMaxAttempts: options?.waitMaxAttempts || 30,
965
+ waitIntervalMs: options?.waitIntervalMs || 4e3,
966
+ progressCallback: options?.progressCallback,
967
+ logging: {
968
+ level: this.logger.getLevel ? this.logger.getLevel() : "info"
969
+ }
350
970
  };
351
- return await this.submitPayload(outboundTopicId, payload);
352
- }
353
- async getOperatorId(disableCache) {
354
- if (this.operatorId && !disableCache) {
355
- return this.operatorId;
356
- }
357
- const accountResponse = this.getAccountAndSigner();
358
- if (!accountResponse.accountId) {
359
- throw new Error("Operator ID not found");
360
- }
361
- const profile = await this.retrieveProfile(accountResponse.accountId);
362
- if (!profile.success) {
363
- throw new Error("Failed to retrieve profile");
971
+ const response = await inscribeWithSigner(
972
+ {
973
+ type: "buffer",
974
+ buffer,
975
+ fileName,
976
+ mimeType
977
+ },
978
+ signer,
979
+ {
980
+ ...inscriptionOptions,
981
+ network: this.network
982
+ },
983
+ sdk
984
+ );
985
+ if (!response.confirmed || !response.inscription) {
986
+ throw new Error("Inscription was not confirmed");
364
987
  }
365
- const operatorId = `${profile.topicInfo?.inboundTopic}@${accountResponse.accountId}`;
366
- this.operatorId = operatorId;
367
- return operatorId;
988
+ return response.inscription;
368
989
  }
369
- clearCache() {
370
- HCS10Cache.getInstance().clear();
990
+ getAccountAndSigner() {
991
+ const accountInfo = this.hwc.getAccountInfo();
992
+ const accountId = accountInfo.accountId.toString();
993
+ const signer = this.hwc.dAppConnector.signers.find((s) => {
994
+ return s.getAccountId().toString() === accountId;
995
+ });
996
+ if (!signer) {
997
+ this.logger.error("Failed to find signer");
998
+ throw new Error("Failed to find signer");
999
+ }
1000
+ return { accountId, signer };
371
1001
  }
372
1002
  /**
373
- * Generates a standard HCS-10 memo string.
374
- * @param type The type of topic memo ('inbound', 'outbound', 'connection').
375
- * @param options Configuration options for the memo.
376
- * @returns The formatted memo string.
377
- * @protected
1003
+ * Inscribes a profile picture (PFP) on HCS-11.
1004
+ *
1005
+ * @param buffer - The buffer containing the PFP image.
1006
+ * @param fileName - The name of the file containing the PFP image.
1007
+ * @param options - Optional configuration options.
1008
+ * @returns A promise that resolves to the topic ID of the inscribed PFP.
378
1009
  */
379
- _generateHcs10Memo(type, options) {
380
- const ttl = options.ttl ?? 60;
381
- switch (type) {
382
- case "inbound":
383
- if (!options.accountId) {
384
- throw new Error("accountId is required for inbound memo");
385
- }
386
- return `hcs-10:0:${ttl}:0:${options.accountId}`;
387
- case "outbound":
388
- return `hcs-10:0:${ttl}:1`;
389
- case "connection":
390
- if (!options.inboundTopicId || options.connectionId === void 0) {
391
- throw new Error(
392
- "inboundTopicId and connectionId are required for connection memo"
393
- );
394
- }
395
- return `hcs-10:1:${ttl}:2:${options.inboundTopicId}:${options.connectionId}`;
396
- default:
397
- throw new Error(`Invalid HCS-10 memo type: ${type}`);
398
- }
399
- }
400
- async checkRegistrationStatus(transactionId, network, baseUrl) {
1010
+ async inscribePfp(buffer, fileName, options) {
401
1011
  try {
402
- const response = await fetch(`${baseUrl}/api/request-confirm`, {
403
- method: "POST",
404
- headers: {
405
- "Content-Type": "application/json",
406
- "X-Network": network
407
- },
408
- body: JSON.stringify({ transaction_id: transactionId })
1012
+ const progressCallback = options?.progressCallback;
1013
+ const progressReporter = new ProgressReporter({
1014
+ module: "PFP-Inscription",
1015
+ logger: this.logger,
1016
+ callback: progressCallback
409
1017
  });
410
- if (!response.ok) {
411
- throw new Error(
412
- `Failed to confirm registration: ${response.statusText}`
1018
+ if (!this.hcs11Client) {
1019
+ progressReporter.failed(
1020
+ "HCS11Client is not available in this environment"
413
1021
  );
1022
+ return {
1023
+ pfpTopicId: "",
1024
+ success: false,
1025
+ error: "HCS11Client is not available in this environment",
1026
+ transactionId: ""
1027
+ };
1028
+ }
1029
+ progressReporter.preparing("Preparing to inscribe profile picture", 10);
1030
+ this.logger.info("Inscribing profile picture using HCS-11 client");
1031
+ const wrappedProgressCallback = (data) => {
1032
+ progressReporter.report({
1033
+ stage: data.stage || "confirming",
1034
+ message: data.message || "Processing PFP inscription",
1035
+ progressPercent: data.progressPercent || 50,
1036
+ details: data.details
1037
+ });
1038
+ };
1039
+ const imageResult = await this.hcs11Client.inscribeImage(
1040
+ buffer,
1041
+ fileName,
1042
+ { progressCallback: wrappedProgressCallback }
1043
+ );
1044
+ if (!imageResult.success) {
1045
+ let errorMessage = "Failed to inscribe profile picture";
1046
+ if (imageResult.error) {
1047
+ errorMessage = imageResult.error;
1048
+ }
1049
+ let txId = "";
1050
+ if (imageResult.transactionId) {
1051
+ txId = imageResult.transactionId;
1052
+ }
1053
+ return {
1054
+ pfpTopicId: "",
1055
+ success: false,
1056
+ error: errorMessage,
1057
+ transactionId: txId
1058
+ };
414
1059
  }
415
- return await response.json();
1060
+ progressReporter.completed("Successfully inscribed profile picture", {
1061
+ pfpTopicId: imageResult.imageTopicId
1062
+ });
1063
+ this.logger.info(
1064
+ `Successfully inscribed profile picture with topic ID: ${imageResult.imageTopicId}`
1065
+ );
1066
+ return {
1067
+ pfpTopicId: imageResult.imageTopicId,
1068
+ success: true,
1069
+ transactionId: imageResult.transactionId || ""
1070
+ };
416
1071
  } catch (error) {
417
- this.logger.error(`Error checking registration status: ${error}`);
418
- throw error;
419
- }
420
- }
421
- /**
422
- * Validates if an operator_id follows the correct format (agentTopicId@accountId)
423
- * @param operatorId The operator ID to validate
424
- * @returns True if the format is valid, false otherwise
425
- */
426
- isValidOperatorId(operatorId) {
427
- if (!operatorId) {
428
- return false;
429
- }
430
- const parts = operatorId.split("@");
431
- if (parts.length !== 2) {
432
- return false;
433
- }
434
- const agentTopicId = parts[0];
435
- const accountId = parts[1];
436
- if (!agentTopicId) {
437
- return false;
438
- }
439
- if (!accountId) {
440
- return false;
441
- }
442
- const hederaIdPattern = /^[0-9]+\.[0-9]+\.[0-9]+$/;
443
- if (!hederaIdPattern.test(accountId)) {
444
- return false;
445
- }
446
- if (!hederaIdPattern.test(agentTopicId)) {
447
- return false;
1072
+ this.logger.error(`Error inscribing profile picture: ${error.message}`);
1073
+ return {
1074
+ pfpTopicId: "",
1075
+ success: false,
1076
+ error: error.message,
1077
+ transactionId: ""
1078
+ };
448
1079
  }
449
- return true;
450
- }
451
- }
452
- class HCS10Cache {
453
- constructor() {
454
- this.CACHE_TTL = 36e5;
455
- this.cache = /* @__PURE__ */ new Map();
456
- this.cacheExpiry = /* @__PURE__ */ new Map();
457
1080
  }
458
- static getInstance() {
459
- if (!HCS10Cache.instance) {
460
- HCS10Cache.instance = new HCS10Cache();
1081
+ async createCommunicationTopics(options, progressReporter) {
1082
+ let state = options?.existingState || {
1083
+ currentStage: "init",
1084
+ completedPercentage: 0,
1085
+ createdResources: []
1086
+ };
1087
+ if (progressReporter) {
1088
+ progressReporter.preparing("Starting communication topic creation", 0, {
1089
+ state
1090
+ });
461
1091
  }
462
- return HCS10Cache.instance;
463
- }
464
- set(key, value) {
465
- this.cache.set(key, value);
466
- this.cacheExpiry.set(key, Date.now() + this.CACHE_TTL);
467
- }
468
- get(key) {
469
- const expiry = this.cacheExpiry.get(key);
470
- if (expiry && expiry > Date.now()) {
471
- return this.cache.get(key);
1092
+ const { accountId } = this.getAccountAndSigner();
1093
+ if (!state.outboundTopicId) {
1094
+ state.currentStage = "topics";
1095
+ if (progressReporter) {
1096
+ progressReporter.preparing("Creating outbound topic", 5, {
1097
+ state
1098
+ });
1099
+ }
1100
+ const outboundMemo = this._generateHcs10Memo(Hcs10MemoType.OUTBOUND, {
1101
+ ttl: options?.ttl,
1102
+ accountId
1103
+ });
1104
+ const outboundResult = await this.createTopic(outboundMemo, true, true);
1105
+ if (!outboundResult.success || !outboundResult.topicId) {
1106
+ throw new Error(
1107
+ outboundResult.error || "Failed to create outbound topic"
1108
+ );
1109
+ }
1110
+ state.outboundTopicId = outboundResult.topicId;
1111
+ if (state.createdResources)
1112
+ state.createdResources.push(`outbound:${state.outboundTopicId}`);
472
1113
  }
473
- if (expiry) {
474
- this.cache.delete(key);
475
- this.cacheExpiry.delete(key);
1114
+ if (!state.inboundTopicId) {
1115
+ state.currentStage = "topics";
1116
+ if (progressReporter) {
1117
+ progressReporter.preparing("Creating inbound topic", 10, {
1118
+ state
1119
+ });
1120
+ }
1121
+ const inboundMemo = this._generateHcs10Memo(Hcs10MemoType.INBOUND, {
1122
+ ttl: options?.ttl,
1123
+ accountId
1124
+ });
1125
+ const inboundResult = await this.createTopic(inboundMemo, true, false);
1126
+ if (!inboundResult.success || !inboundResult.topicId) {
1127
+ throw new Error(
1128
+ inboundResult.error || "Failed to create inbound topic"
1129
+ );
1130
+ }
1131
+ state.inboundTopicId = inboundResult.topicId;
1132
+ if (state.createdResources)
1133
+ state.createdResources.push(`inbound:${state.inboundTopicId}`);
476
1134
  }
477
- return void 0;
478
- }
479
- clear() {
480
- this.cache.clear();
481
- this.cacheExpiry.clear();
1135
+ return {
1136
+ inboundTopicId: state.inboundTopicId,
1137
+ outboundTopicId: state.outboundTopicId,
1138
+ state
1139
+ };
482
1140
  }
483
1141
  }
484
1142
  export {
485
- HCS10BaseClient,
486
- HCS10Cache,
487
- Hcs10MemoType
1143
+ BrowserHCSClient
488
1144
  };
489
1145
  //# sourceMappingURL=standards-sdk.es8.js.map