@hashgraphonline/standards-sdk 0.0.63 → 0.0.65

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 (295) 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 +13 -36
  38. package/dist/es/standards-sdk.es100.js.map +1 -1
  39. package/dist/es/standards-sdk.es101.js +36 -10
  40. package/dist/es/standards-sdk.es101.js.map +1 -1
  41. package/dist/es/standards-sdk.es102.js +10 -53
  42. package/dist/es/standards-sdk.es102.js.map +1 -1
  43. package/dist/es/standards-sdk.es103.js +47 -1275
  44. package/dist/es/standards-sdk.es103.js.map +1 -1
  45. package/dist/es/standards-sdk.es104.js +1282 -25
  46. package/dist/es/standards-sdk.es104.js.map +1 -1
  47. package/dist/es/standards-sdk.es105.js +31 -5
  48. package/dist/es/standards-sdk.es105.js.map +1 -1
  49. package/dist/es/standards-sdk.es106.js +5 -158
  50. package/dist/es/standards-sdk.es106.js.map +1 -1
  51. package/dist/es/standards-sdk.es107.js +147 -781
  52. package/dist/es/standards-sdk.es107.js.map +1 -1
  53. package/dist/es/standards-sdk.es108.js +785 -166
  54. package/dist/es/standards-sdk.es108.js.map +1 -1
  55. package/dist/es/standards-sdk.es109.js +2 -2
  56. package/dist/es/standards-sdk.es11.js +80 -71
  57. package/dist/es/standards-sdk.es11.js.map +1 -1
  58. package/dist/es/standards-sdk.es110.js +169 -16
  59. package/dist/es/standards-sdk.es110.js.map +1 -1
  60. package/dist/es/standards-sdk.es111.js +19 -25
  61. package/dist/es/standards-sdk.es111.js.map +1 -1
  62. package/dist/es/standards-sdk.es112.js +24 -23
  63. package/dist/es/standards-sdk.es112.js.map +1 -1
  64. package/dist/es/standards-sdk.es113.js +23 -35
  65. package/dist/es/standards-sdk.es113.js.map +1 -1
  66. package/dist/es/standards-sdk.es114.js +41 -0
  67. package/dist/es/standards-sdk.es114.js.map +1 -0
  68. package/dist/es/standards-sdk.es12.js +650 -7
  69. package/dist/es/standards-sdk.es12.js.map +1 -1
  70. package/dist/es/standards-sdk.es13.js +10 -664
  71. package/dist/es/standards-sdk.es13.js.map +1 -1
  72. package/dist/es/standards-sdk.es14.js +4 -1
  73. package/dist/es/standards-sdk.es14.js.map +1 -1
  74. package/dist/es/standards-sdk.es17.js +1 -1
  75. package/dist/es/standards-sdk.es18.js +3 -3
  76. package/dist/es/standards-sdk.es18.js.map +1 -1
  77. package/dist/es/standards-sdk.es19.js +82 -1754
  78. package/dist/es/standards-sdk.es19.js.map +1 -1
  79. package/dist/es/standards-sdk.es20.js +5 -3
  80. package/dist/es/standards-sdk.es20.js.map +1 -1
  81. package/dist/es/standards-sdk.es21.js +1703 -4103
  82. package/dist/es/standards-sdk.es21.js.map +1 -1
  83. package/dist/es/standards-sdk.es22.js +3 -36
  84. package/dist/es/standards-sdk.es22.js.map +1 -1
  85. package/dist/es/standards-sdk.es23.js +4167 -48
  86. package/dist/es/standards-sdk.es23.js.map +1 -1
  87. package/dist/es/standards-sdk.es24.js +2 -2
  88. package/dist/es/standards-sdk.es25.js +36 -2
  89. package/dist/es/standards-sdk.es25.js.map +1 -1
  90. package/dist/es/standards-sdk.es26.js +46 -1039
  91. package/dist/es/standards-sdk.es26.js.map +1 -1
  92. package/dist/es/standards-sdk.es27.js +2 -5
  93. package/dist/es/standards-sdk.es27.js.map +1 -1
  94. package/dist/es/standards-sdk.es28.js +1034 -94
  95. package/dist/es/standards-sdk.es28.js.map +1 -1
  96. package/dist/es/standards-sdk.es29.js +419 -2
  97. package/dist/es/standards-sdk.es29.js.map +1 -1
  98. package/dist/es/standards-sdk.es30.js +2 -16
  99. package/dist/es/standards-sdk.es30.js.map +1 -1
  100. package/dist/es/standards-sdk.es31.js +106 -395
  101. package/dist/es/standards-sdk.es31.js.map +1 -1
  102. package/dist/es/standards-sdk.es32.js +3 -2282
  103. package/dist/es/standards-sdk.es32.js.map +1 -1
  104. package/dist/es/standards-sdk.es34.js +3 -363
  105. package/dist/es/standards-sdk.es34.js.map +1 -1
  106. package/dist/es/standards-sdk.es35.js +100 -5
  107. package/dist/es/standards-sdk.es35.js.map +1 -1
  108. package/dist/es/standards-sdk.es36.js +2 -179
  109. package/dist/es/standards-sdk.es36.js.map +1 -1
  110. package/dist/es/standards-sdk.es37.js +15 -80
  111. package/dist/es/standards-sdk.es37.js.map +1 -1
  112. package/dist/es/standards-sdk.es38.js +400 -105
  113. package/dist/es/standards-sdk.es38.js.map +1 -1
  114. package/dist/es/standards-sdk.es39.js +2282 -52
  115. package/dist/es/standards-sdk.es39.js.map +1 -1
  116. package/dist/es/standards-sdk.es4.js +1 -1
  117. package/dist/es/standards-sdk.es40.js +364 -10
  118. package/dist/es/standards-sdk.es40.js.map +1 -1
  119. package/dist/es/standards-sdk.es41.js +5 -96
  120. package/dist/es/standards-sdk.es41.js.map +1 -1
  121. package/dist/es/standards-sdk.es42.js +178 -3
  122. package/dist/es/standards-sdk.es42.js.map +1 -1
  123. package/dist/es/standards-sdk.es43.js +81 -2
  124. package/dist/es/standards-sdk.es43.js.map +1 -1
  125. package/dist/es/standards-sdk.es44.js +104 -103
  126. package/dist/es/standards-sdk.es44.js.map +1 -1
  127. package/dist/es/standards-sdk.es45.js +49 -71
  128. package/dist/es/standards-sdk.es45.js.map +1 -1
  129. package/dist/es/standards-sdk.es46.js +9 -5
  130. package/dist/es/standards-sdk.es46.js.map +1 -1
  131. package/dist/es/standards-sdk.es47.js +96 -4
  132. package/dist/es/standards-sdk.es47.js.map +1 -1
  133. package/dist/es/standards-sdk.es48.js +3 -220
  134. package/dist/es/standards-sdk.es48.js.map +1 -1
  135. package/dist/es/standards-sdk.es49.js +2 -58
  136. package/dist/es/standards-sdk.es49.js.map +1 -1
  137. package/dist/es/standards-sdk.es5.js +393 -891
  138. package/dist/es/standards-sdk.es5.js.map +1 -1
  139. package/dist/es/standards-sdk.es50.js +112 -68
  140. package/dist/es/standards-sdk.es50.js.map +1 -1
  141. package/dist/es/standards-sdk.es51.js +74 -3
  142. package/dist/es/standards-sdk.es51.js.map +1 -1
  143. package/dist/es/standards-sdk.es52.js +5 -31
  144. package/dist/es/standards-sdk.es52.js.map +1 -1
  145. package/dist/es/standards-sdk.es53.js +4 -62
  146. package/dist/es/standards-sdk.es53.js.map +1 -1
  147. package/dist/es/standards-sdk.es54.js +217 -46
  148. package/dist/es/standards-sdk.es54.js.map +1 -1
  149. package/dist/es/standards-sdk.es55.js +57 -9
  150. package/dist/es/standards-sdk.es55.js.map +1 -1
  151. package/dist/es/standards-sdk.es56.js +68 -64
  152. package/dist/es/standards-sdk.es56.js.map +1 -1
  153. package/dist/es/standards-sdk.es57.js +32 -6
  154. package/dist/es/standards-sdk.es57.js.map +1 -1
  155. package/dist/es/standards-sdk.es58.js +61 -13
  156. package/dist/es/standards-sdk.es58.js.map +1 -1
  157. package/dist/es/standards-sdk.es59.js +50 -7
  158. package/dist/es/standards-sdk.es59.js.map +1 -1
  159. package/dist/es/standards-sdk.es60.js +10 -45
  160. package/dist/es/standards-sdk.es60.js.map +1 -1
  161. package/dist/es/standards-sdk.es61.js +65 -2
  162. package/dist/es/standards-sdk.es61.js.map +1 -1
  163. package/dist/es/standards-sdk.es62.js +5 -135
  164. package/dist/es/standards-sdk.es62.js.map +1 -1
  165. package/dist/es/standards-sdk.es63.js +13 -170
  166. package/dist/es/standards-sdk.es63.js.map +1 -1
  167. package/dist/es/standards-sdk.es64.js +4 -10
  168. package/dist/es/standards-sdk.es64.js.map +1 -1
  169. package/dist/es/standards-sdk.es65.js +45 -13
  170. package/dist/es/standards-sdk.es65.js.map +1 -1
  171. package/dist/es/standards-sdk.es66.js +2 -4
  172. package/dist/es/standards-sdk.es66.js.map +1 -1
  173. package/dist/es/standards-sdk.es67.js +134 -30
  174. package/dist/es/standards-sdk.es67.js.map +1 -1
  175. package/dist/es/standards-sdk.es68.js +171 -14
  176. package/dist/es/standards-sdk.es68.js.map +1 -1
  177. package/dist/es/standards-sdk.es69.js +13 -4
  178. package/dist/es/standards-sdk.es69.js.map +1 -1
  179. package/dist/es/standards-sdk.es7.js +959 -94
  180. package/dist/es/standards-sdk.es7.js.map +1 -1
  181. package/dist/es/standards-sdk.es70.js +13 -4
  182. package/dist/es/standards-sdk.es70.js.map +1 -1
  183. package/dist/es/standards-sdk.es71.js +31 -15
  184. package/dist/es/standards-sdk.es71.js.map +1 -1
  185. package/dist/es/standards-sdk.es72.js +14 -4
  186. package/dist/es/standards-sdk.es72.js.map +1 -1
  187. package/dist/es/standards-sdk.es73.js +4 -39
  188. package/dist/es/standards-sdk.es73.js.map +1 -1
  189. package/dist/es/standards-sdk.es74.js +4 -40
  190. package/dist/es/standards-sdk.es74.js.map +1 -1
  191. package/dist/es/standards-sdk.es75.js +15 -36
  192. package/dist/es/standards-sdk.es75.js.map +1 -1
  193. package/dist/es/standards-sdk.es76.js +5 -78
  194. package/dist/es/standards-sdk.es76.js.map +1 -1
  195. package/dist/es/standards-sdk.es77.js +39 -3
  196. package/dist/es/standards-sdk.es77.js.map +1 -1
  197. package/dist/es/standards-sdk.es78.js +40 -2
  198. package/dist/es/standards-sdk.es78.js.map +1 -1
  199. package/dist/es/standards-sdk.es79.js +37 -2
  200. package/dist/es/standards-sdk.es79.js.map +1 -1
  201. package/dist/es/standards-sdk.es8.js +1049 -393
  202. package/dist/es/standards-sdk.es8.js.map +1 -1
  203. package/dist/es/standards-sdk.es80.js +67 -408
  204. package/dist/es/standards-sdk.es80.js.map +1 -1
  205. package/dist/es/standards-sdk.es81.js +3 -2
  206. package/dist/es/standards-sdk.es81.js.map +1 -1
  207. package/dist/es/standards-sdk.es82.js +2 -120
  208. package/dist/es/standards-sdk.es82.js.map +1 -1
  209. package/dist/es/standards-sdk.es83.js +2 -34
  210. package/dist/es/standards-sdk.es83.js.map +1 -1
  211. package/dist/es/standards-sdk.es84.js +30 -29
  212. package/dist/es/standards-sdk.es84.js.map +1 -1
  213. package/dist/es/standards-sdk.es85.js +33 -9
  214. package/dist/es/standards-sdk.es85.js.map +1 -1
  215. package/dist/es/standards-sdk.es86.js +9 -34
  216. package/dist/es/standards-sdk.es86.js.map +1 -1
  217. package/dist/es/standards-sdk.es87.js +34 -2
  218. package/dist/es/standards-sdk.es87.js.map +1 -1
  219. package/dist/es/standards-sdk.es88.js +2 -84
  220. package/dist/es/standards-sdk.es88.js.map +1 -1
  221. package/dist/es/standards-sdk.es89.js +82 -21
  222. package/dist/es/standards-sdk.es89.js.map +1 -1
  223. package/dist/es/standards-sdk.es9.js +2 -2
  224. package/dist/es/standards-sdk.es9.js.map +1 -1
  225. package/dist/es/standards-sdk.es90.js +21 -146
  226. package/dist/es/standards-sdk.es90.js.map +1 -1
  227. package/dist/es/standards-sdk.es91.js +130 -73
  228. package/dist/es/standards-sdk.es91.js.map +1 -1
  229. package/dist/es/standards-sdk.es92.js +81 -185
  230. package/dist/es/standards-sdk.es92.js.map +1 -1
  231. package/dist/es/standards-sdk.es93.js +163 -406
  232. package/dist/es/standards-sdk.es93.js.map +1 -1
  233. package/dist/es/standards-sdk.es94.js +432 -19
  234. package/dist/es/standards-sdk.es94.js.map +1 -1
  235. package/dist/es/standards-sdk.es95.js +16 -130
  236. package/dist/es/standards-sdk.es95.js.map +1 -1
  237. package/dist/es/standards-sdk.es96.js +131 -10
  238. package/dist/es/standards-sdk.es96.js.map +1 -1
  239. package/dist/es/standards-sdk.es97.js +11 -22
  240. package/dist/es/standards-sdk.es97.js.map +1 -1
  241. package/dist/es/standards-sdk.es98.js +22 -22
  242. package/dist/es/standards-sdk.es98.js.map +1 -1
  243. package/dist/es/standards-sdk.es99.js +21 -13
  244. package/dist/es/standards-sdk.es99.js.map +1 -1
  245. package/dist/es/utils/logger.d.ts +1 -0
  246. package/dist/es/utils/logger.d.ts.map +1 -1
  247. package/dist/es/utils/types.d.ts +2 -0
  248. package/dist/es/utils/types.d.ts.map +1 -0
  249. package/dist/umd/fees/fee-config-builder.d.ts.map +1 -0
  250. package/dist/umd/fees/index.d.ts +3 -0
  251. package/dist/umd/fees/index.d.ts.map +1 -0
  252. package/dist/umd/fees/types.d.ts +24 -0
  253. package/dist/umd/fees/types.d.ts.map +1 -0
  254. package/dist/umd/hcs-10/base-client.d.ts +1 -1
  255. package/dist/umd/hcs-10/base-client.d.ts.map +1 -1
  256. package/dist/umd/hcs-10/browser.d.ts +20 -35
  257. package/dist/umd/hcs-10/browser.d.ts.map +1 -1
  258. package/dist/umd/hcs-10/index.d.ts +4 -6
  259. package/dist/umd/hcs-10/index.d.ts.map +1 -1
  260. package/dist/umd/hcs-10/registrations.d.ts.map +1 -1
  261. package/dist/umd/hcs-10/sdk.d.ts +16 -8
  262. package/dist/umd/hcs-10/sdk.d.ts.map +1 -1
  263. package/dist/umd/hcs-10/types.d.ts +2 -62
  264. package/dist/umd/hcs-10/types.d.ts.map +1 -1
  265. package/dist/umd/hcs-11/agent-builder.d.ts +53 -0
  266. package/dist/umd/hcs-11/agent-builder.d.ts.map +1 -0
  267. package/dist/umd/hcs-11/client.d.ts +82 -0
  268. package/dist/umd/hcs-11/client.d.ts.map +1 -0
  269. package/dist/umd/hcs-11/index.d.ts +4 -190
  270. package/dist/umd/hcs-11/index.d.ts.map +1 -1
  271. package/dist/umd/hcs-11/person-builder.d.ts +29 -0
  272. package/dist/umd/hcs-11/person-builder.d.ts.map +1 -0
  273. package/dist/umd/hcs-11/types.d.ts +165 -0
  274. package/dist/umd/hcs-11/types.d.ts.map +1 -0
  275. package/dist/umd/index.d.ts +1 -0
  276. package/dist/umd/index.d.ts.map +1 -1
  277. package/dist/umd/services/mirror-node.d.ts +2 -1
  278. package/dist/umd/services/mirror-node.d.ts.map +1 -1
  279. package/dist/umd/services/types.d.ts +0 -1
  280. package/dist/umd/services/types.d.ts.map +1 -1
  281. package/dist/umd/standards-sdk.umd.js +7 -7
  282. package/dist/umd/standards-sdk.umd.js.map +1 -1
  283. package/dist/umd/utils/logger.d.ts +1 -0
  284. package/dist/umd/utils/logger.d.ts.map +1 -1
  285. package/dist/umd/utils/types.d.ts +2 -0
  286. package/dist/umd/utils/types.d.ts.map +1 -0
  287. package/package.json +6 -4
  288. package/dist/es/hcs-10/agent-builder.d.ts +0 -45
  289. package/dist/es/hcs-10/agent-builder.d.ts.map +0 -1
  290. package/dist/es/hcs-10/fee-config-builder.d.ts.map +0 -1
  291. package/dist/umd/hcs-10/agent-builder.d.ts +0 -45
  292. package/dist/umd/hcs-10/agent-builder.d.ts.map +0 -1
  293. package/dist/umd/hcs-10/fee-config-builder.d.ts.map +0 -1
  294. /package/dist/es/{hcs-10 → fees}/fee-config-builder.d.ts +0 -0
  295. /package/dist/umd/{hcs-10 → fees}/fee-config-builder.d.ts +0 -0
@@ -1,128 +1,993 @@
1
- import { InboundTopicType } from "./standards-sdk.es12.js";
1
+ import Buffer from "./standards-sdk.es21.js";
2
+ import { Client, PrivateKey, AccountCreateTransaction, Hbar, CustomFixedFee, AccountId, KeyList, TopicCreateTransaction, PublicKey, TopicMessageSubmitTransaction, TopicId, Transaction } from "@hashgraph/sdk";
3
+ import { AccountCreationError, TopicCreationError, ConnectionConfirmationError, PayloadSizeError } from "./standards-sdk.es6.js";
4
+ import { InscriptionSDK } from "./standards-sdk.es24.js";
2
5
  import { Logger } from "./standards-sdk.es14.js";
3
- class AgentBuilder {
4
- constructor() {
5
- this.config = {};
6
+ import { HCS10BaseClient, Hcs10MemoType } from "./standards-sdk.es5.js";
7
+ import { m as mimeTypesExports } from "./standards-sdk.es22.js";
8
+ import { InboundTopicType } from "./standards-sdk.es13.js";
9
+ import { HCS11Client } from "./standards-sdk.es12.js";
10
+ import { accountIdsToExemptKeys } from "./standards-sdk.es15.js";
11
+ import { inscribe } from "./standards-sdk.es17.js";
12
+ class HCS10Client extends HCS10BaseClient {
13
+ constructor(config) {
14
+ super({
15
+ network: config.network,
16
+ logLevel: config.logLevel,
17
+ prettyPrint: config.prettyPrint,
18
+ feeAmount: config.feeAmount
19
+ });
20
+ this.client = config.network === "mainnet" ? Client.forMainnet() : Client.forTestnet();
21
+ this.operatorPrivateKey = PrivateKey.fromString(config.operatorPrivateKey);
22
+ this.network = config.network;
23
+ this.client.setOperator(
24
+ config.operatorId,
25
+ this.operatorPrivateKey.toString()
26
+ );
6
27
  this.logger = Logger.getInstance({
7
- module: "AgentBuilder"
28
+ level: config.logLevel || "info",
29
+ module: "HCS-SDK"
30
+ });
31
+ this.guardedRegistryBaseUrl = config.guardedRegistryBaseUrl || "https://moonscape.tech";
32
+ this.hcs11Client = new HCS11Client({
33
+ network: config.network,
34
+ auth: {
35
+ operatorId: config.operatorId,
36
+ privateKey: config.operatorPrivateKey
37
+ },
38
+ logLevel: config.logLevel
8
39
  });
9
40
  }
10
- setName(name) {
11
- this.config.name = name;
12
- return this;
13
- }
14
- setDescription(description) {
15
- this.config.description = description;
16
- return this;
17
- }
18
- setCapabilities(capabilities) {
19
- this.config.capabilities = capabilities;
20
- return this;
41
+ getClient() {
42
+ return this.client;
21
43
  }
22
- setAgentType(type) {
23
- if (!this.config.metadata) {
24
- this.config.metadata = { type };
25
- } else {
26
- this.config.metadata.type = type;
44
+ /**
45
+ * Creates a new Hedera account
46
+ * @returns Object with account ID and private key
47
+ */
48
+ async createAccount() {
49
+ this.logger.info("Creating new account");
50
+ const newKey = PrivateKey.generate();
51
+ const accountTransaction = new AccountCreateTransaction().setKey(newKey.publicKey).setInitialBalance(new Hbar(10));
52
+ this.logger.debug("Executing account creation transaction");
53
+ const accountResponse = await accountTransaction.execute(this.client);
54
+ const accountReceipt = await accountResponse.getReceipt(this.client);
55
+ const newAccountId = accountReceipt.accountId;
56
+ if (!newAccountId) {
57
+ this.logger.error("Account creation failed: accountId is null");
58
+ throw new AccountCreationError(
59
+ "Failed to create account: accountId is null"
60
+ );
27
61
  }
28
- return this;
62
+ this.logger.info(
63
+ `Account created successfully: ${newAccountId.toString()}`
64
+ );
65
+ return {
66
+ accountId: newAccountId.toString(),
67
+ privateKey: newKey.toString()
68
+ };
29
69
  }
30
- setModel(model) {
31
- if (!this.config.metadata) {
32
- this.config.metadata = { type: "autonomous", model };
33
- } else {
34
- this.config.metadata.model = model;
70
+ /**
71
+ * Creates an inbound topic for an agent
72
+ * @param accountId The account ID associated with the inbound topic
73
+ * @param topicType Type of inbound topic (public, controlled, or fee-based)
74
+ * @param ttl Optional Time-To-Live for the topic memo, defaults to 60
75
+ * @param feeConfigBuilder Optional fee configuration builder for fee-based topics
76
+ * @returns The topic ID of the created inbound topic
77
+ */
78
+ async createInboundTopic(accountId, topicType, ttl = 60, feeConfigBuilder) {
79
+ const memo = this._generateHcs10Memo(Hcs10MemoType.INBOUND, {
80
+ accountId,
81
+ ttl
82
+ });
83
+ let submitKey;
84
+ let feeConfig;
85
+ switch (topicType) {
86
+ case InboundTopicType.PUBLIC:
87
+ submitKey = false;
88
+ break;
89
+ case InboundTopicType.CONTROLLED:
90
+ submitKey = true;
91
+ break;
92
+ case InboundTopicType.FEE_BASED:
93
+ submitKey = true;
94
+ if (!feeConfigBuilder) {
95
+ throw new Error(
96
+ "Fee configuration builder is required for fee-based topics"
97
+ );
98
+ }
99
+ feeConfig = feeConfigBuilder.build();
100
+ break;
101
+ default:
102
+ throw new Error(`Unsupported inbound topic type: ${topicType}`);
35
103
  }
36
- return this;
104
+ return this.createTopic(memo, true, submitKey, feeConfig);
37
105
  }
38
- setCreator(creator) {
39
- if (!this.config.metadata) {
40
- this.config.metadata = { type: "autonomous", creator };
41
- } else {
42
- this.config.metadata.creator = creator;
106
+ /**
107
+ * Creates a new agent with inbound and outbound topics
108
+ * @param builder The agent builder object
109
+ * @param ttl Optional Time-To-Live for the topic memos, defaults to 60
110
+ * @returns Object with topic IDs
111
+ */
112
+ async createAgent(builder, ttl = 60) {
113
+ const config = builder.build();
114
+ const outboundMemo = this._generateHcs10Memo(Hcs10MemoType.OUTBOUND, {
115
+ ttl
116
+ });
117
+ const outboundTopicId = await this.createTopic(outboundMemo, true, true);
118
+ this.logger.info(`Created new outbound topic ID: ${outboundTopicId}`);
119
+ const accountId = this.client.operatorAccountId?.toString();
120
+ if (!accountId) {
121
+ throw new Error("Failed to retrieve operator account ID");
43
122
  }
44
- return this;
45
- }
46
- addSocial(platform, handle) {
47
- if (!this.config.metadata) {
48
- this.config.metadata = { type: "autonomous", socials: {} };
49
- } else if (!this.config.metadata.socials) {
50
- this.config.metadata.socials = {};
123
+ const inboundTopicId = await this.createInboundTopic(
124
+ accountId,
125
+ config.inboundTopicType,
126
+ ttl,
127
+ config.inboundTopicType === InboundTopicType.FEE_BASED ? config.feeConfig : void 0
128
+ );
129
+ let pfpTopicId = config.existingPfpTopicId || "";
130
+ if (!pfpTopicId && config.pfpBuffer && config.pfpBuffer.length > 0) {
131
+ this.logger.info("Inscribing new profile picture");
132
+ const pfpResult = await this.inscribePfp(
133
+ config.pfpBuffer,
134
+ config.pfpFileName
135
+ );
136
+ pfpTopicId = pfpResult.pfpTopicId;
137
+ this.logger.info(
138
+ `Profile picture inscribed with topic ID: ${pfpTopicId}`
139
+ );
140
+ } else if (config.existingPfpTopicId) {
141
+ this.logger.info(
142
+ `Using existing profile picture with topic ID: ${config.existingPfpTopicId}`
143
+ );
51
144
  }
52
- this.config.metadata.socials[platform] = handle;
53
- return this;
145
+ const profileResult = await this.storeHCS11Profile(
146
+ config.name,
147
+ config.bio,
148
+ inboundTopicId,
149
+ outboundTopicId,
150
+ config.capabilities,
151
+ config.metadata,
152
+ config.pfpBuffer && config.pfpBuffer.length > 0 ? config.pfpBuffer : void 0,
153
+ config.pfpFileName,
154
+ config.existingPfpTopicId
155
+ );
156
+ const profileTopicId = profileResult.profileTopicId;
157
+ this.logger.info(`Profile stored with topic ID: ${profileTopicId}`);
158
+ return {
159
+ inboundTopicId,
160
+ outboundTopicId,
161
+ pfpTopicId,
162
+ profileTopicId
163
+ };
54
164
  }
55
- addProperty(key, value) {
56
- if (!this.config.metadata) {
57
- this.config.metadata = { type: "autonomous", properties: {} };
58
- } else if (!this.config.metadata.properties) {
59
- this.config.metadata.properties = {};
165
+ /**
166
+ * Inscribes a profile picture to Hedera
167
+ * @param buffer Profile picture buffer
168
+ * @param fileName Filename
169
+ * @returns Response with topic ID and transaction ID
170
+ */
171
+ async inscribePfp(buffer, fileName) {
172
+ try {
173
+ this.logger.info("Inscribing profile picture using HCS-11 client");
174
+ const imageResult = await this.hcs11Client.inscribeImage(
175
+ buffer,
176
+ fileName
177
+ );
178
+ if (!imageResult.success) {
179
+ this.logger.error(
180
+ `Failed to inscribe profile picture: ${imageResult.error}`
181
+ );
182
+ throw new Error(
183
+ imageResult?.error || "Failed to inscribe profile picture"
184
+ );
185
+ }
186
+ this.logger.info(
187
+ `Successfully inscribed profile picture with topic ID: ${imageResult.imageTopicId}`
188
+ );
189
+ return {
190
+ pfpTopicId: imageResult.imageTopicId,
191
+ transactionId: imageResult.transactionId,
192
+ success: true
193
+ };
194
+ } catch (error) {
195
+ this.logger.error(`Error inscribing profile picture: ${error.message}`);
196
+ return {
197
+ pfpTopicId: "",
198
+ transactionId: "",
199
+ success: false,
200
+ error: error.message
201
+ };
60
202
  }
61
- this.config.metadata.properties[key] = value;
62
- return this;
63
- }
64
- setMetadata(metadata) {
65
- this.config.metadata = metadata;
66
- return this;
67
203
  }
68
- setProfilePicture(pfpBuffer, pfpFileName) {
69
- this.config.pfpBuffer = pfpBuffer;
70
- this.config.pfpFileName = pfpFileName;
71
- return this;
204
+ /**
205
+ * Stores an HCS-11 profile for an agent
206
+ * @param agentName Agent name
207
+ * @param agentBio Agent description
208
+ * @param inboundTopicId Inbound topic ID
209
+ * @param outboundTopicId Outbound topic ID
210
+ * @param capabilities Agent capability tags
211
+ * @param metadata Additional metadata
212
+ * @param pfpBuffer Optional profile picture buffer
213
+ * @param pfpFileName Optional profile picture filename
214
+ * @returns Response with topic IDs and transaction ID
215
+ */
216
+ async storeHCS11Profile(agentName, agentBio, inboundTopicId, outboundTopicId, capabilities = [], metadata, pfpBuffer, pfpFileName, existingPfpTopicId) {
217
+ try {
218
+ let pfpTopicId = existingPfpTopicId || "";
219
+ if (!pfpTopicId && pfpBuffer && pfpFileName) {
220
+ this.logger.info("Inscribing profile picture for HCS-11 profile");
221
+ const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName);
222
+ if (!pfpResult.success) {
223
+ this.logger.warn(
224
+ `Failed to inscribe profile picture: ${pfpResult.error}, proceeding without pfp`
225
+ );
226
+ } else {
227
+ pfpTopicId = pfpResult.pfpTopicId;
228
+ }
229
+ } else if (existingPfpTopicId) {
230
+ this.logger.info(
231
+ `Using existing profile picture with topic ID: ${existingPfpTopicId} for HCS-11 profile`
232
+ );
233
+ pfpTopicId = existingPfpTopicId;
234
+ }
235
+ const agentType = this.hcs11Client.getAgentTypeFromMetadata({
236
+ type: metadata.type || "autonomous"
237
+ });
238
+ const formattedSocials = metadata.socials ? Object.entries(metadata.socials).filter(([_, handle]) => handle).map(([platform, handle]) => ({
239
+ platform,
240
+ handle
241
+ })) : void 0;
242
+ const profile = this.hcs11Client.createAIAgentProfile(
243
+ agentName,
244
+ agentType,
245
+ capabilities,
246
+ metadata.model || "unknown",
247
+ {
248
+ alias: agentName.toLowerCase().replace(/\s+/g, "_"),
249
+ bio: agentBio,
250
+ profileImage: pfpTopicId ? `hcs://1/${pfpTopicId}` : void 0,
251
+ socials: formattedSocials,
252
+ properties: metadata.properties,
253
+ inboundTopicId,
254
+ outboundTopicId,
255
+ creator: metadata.creator
256
+ }
257
+ );
258
+ const profileResult = await this.hcs11Client.createAndInscribeProfile(
259
+ profile,
260
+ true
261
+ );
262
+ if (!profileResult.success) {
263
+ this.logger.error(`Failed to inscribe profile: ${profileResult.error}`);
264
+ throw new Error(profileResult.error || "Failed to inscribe profile");
265
+ }
266
+ this.logger.info(
267
+ `Profile inscribed with topic ID: ${profileResult.profileTopicId}, transaction ID: ${profileResult.transactionId}`
268
+ );
269
+ return {
270
+ profileTopicId: profileResult.profileTopicId,
271
+ pfpTopicId,
272
+ transactionId: profileResult.transactionId,
273
+ success: true
274
+ };
275
+ } catch (error) {
276
+ this.logger.error(`Error storing HCS-11 profile: ${error.message}`);
277
+ return {
278
+ profileTopicId: "",
279
+ pfpTopicId: "",
280
+ transactionId: "",
281
+ success: false,
282
+ error: error.message
283
+ };
284
+ }
72
285
  }
73
- setExistingProfilePicture(pfpTopicId) {
74
- this.config.existingPfpTopicId = pfpTopicId;
75
- return this;
286
+ async setupFees(transaction, feeConfig, additionalExemptAccounts = []) {
287
+ if (!this.client.operatorPublicKey) {
288
+ return;
289
+ }
290
+ this.logger.info("Setting up topic with custom fees");
291
+ const customFee = new CustomFixedFee().setAmount(Number(feeConfig.feeAmount.amount)).setFeeCollectorAccountId(
292
+ AccountId.fromString(feeConfig.feeCollectorAccountId)
293
+ );
294
+ let exemptAccountIds = [
295
+ ...feeConfig.exemptAccounts || [],
296
+ ...additionalExemptAccounts
297
+ ];
298
+ console.log("exemptAccountIds", exemptAccountIds);
299
+ if (exemptAccountIds.length > 0) {
300
+ const uniqueExemptAccountIds = Array.from(new Set(exemptAccountIds));
301
+ const filteredExemptAccounts = uniqueExemptAccountIds.filter(
302
+ (account) => account !== this.client.operatorAccountId?.toString()
303
+ );
304
+ let exemptKeys = [];
305
+ if (filteredExemptAccounts.length > 0) {
306
+ try {
307
+ exemptKeys = await accountIdsToExemptKeys(
308
+ filteredExemptAccounts,
309
+ this.network,
310
+ this.logger
311
+ );
312
+ } catch (error) {
313
+ this.logger.warn(
314
+ `Error getting exempt keys: ${error}, continuing without exempt keys`
315
+ );
316
+ }
317
+ }
318
+ if (exemptKeys.length > 0) {
319
+ transaction.setFeeExemptKeys(exemptKeys);
320
+ }
321
+ }
322
+ transaction.setFeeScheduleKey(this.client.operatorPublicKey).setCustomFees([customFee]);
76
323
  }
77
- setNetwork(network) {
78
- this.config.network = network;
79
- return this;
324
+ /**
325
+ * Handles a connection request from another account
326
+ * @param inboundTopicId Inbound topic ID
327
+ * @param requestingAccountId Requesting account ID
328
+ * @param connectionRequestId Connection request ID
329
+ * @param connectionFeeConfig Optional fee configuration for the connection topic
330
+ * @param ttl Optional ttl parameter with default
331
+ * @returns Response with connection details
332
+ */
333
+ async handleConnectionRequest(inboundTopicId, requestingAccountId, connectionRequestId, connectionFeeConfig, ttl = 60) {
334
+ const memo = this._generateHcs10Memo(Hcs10MemoType.CONNECTION, {
335
+ ttl,
336
+ inboundTopicId,
337
+ connectionId: connectionRequestId
338
+ });
339
+ this.logger.info(
340
+ `Handling connection request ${connectionRequestId} from ${requestingAccountId}`
341
+ );
342
+ const accountId = this.getClient().operatorAccountId?.toString();
343
+ if (!accountId) {
344
+ throw new Error("Failed to retrieve operator account ID");
345
+ }
346
+ let requesterKey = await this.mirrorNode.getPublicKey(requestingAccountId);
347
+ const accountKey = await this.mirrorNode.getPublicKey(accountId);
348
+ if (!accountKey) {
349
+ throw new Error("Failed to retrieve public key");
350
+ }
351
+ const thresholdKey = new KeyList([accountKey, requesterKey], 1);
352
+ let connectionTopicId;
353
+ try {
354
+ if (connectionFeeConfig) {
355
+ const feeConfig = connectionFeeConfig.build();
356
+ const modifiedFeeConfig = {
357
+ ...feeConfig,
358
+ exemptAccounts: [...feeConfig.exemptAccounts || []]
359
+ };
360
+ connectionTopicId = await this.createTopic(
361
+ memo,
362
+ thresholdKey,
363
+ thresholdKey,
364
+ modifiedFeeConfig
365
+ );
366
+ } else {
367
+ connectionTopicId = await this.createTopic(
368
+ memo,
369
+ thresholdKey,
370
+ thresholdKey
371
+ );
372
+ }
373
+ this.logger.info(`Created new connection topic ID: ${connectionTopicId}`);
374
+ } catch (error) {
375
+ this.logger.error(`Failed to create connection topic: ${error}`);
376
+ throw new TopicCreationError(
377
+ `Failed to create connection topic: ${error}`
378
+ );
379
+ }
380
+ const operatorId = `${inboundTopicId}@${accountId}`;
381
+ const confirmedConnectionSequenceNumber = await this.confirmConnection(
382
+ inboundTopicId,
383
+ connectionTopicId,
384
+ requestingAccountId,
385
+ connectionRequestId,
386
+ "Connection accepted. Looking forward to collaborating!"
387
+ );
388
+ return {
389
+ connectionTopicId,
390
+ confirmedConnectionSequenceNumber,
391
+ operatorId
392
+ };
80
393
  }
81
- setInboundTopicType(inboundTopicType) {
82
- this.config.inboundTopicType = inboundTopicType;
83
- return this;
394
+ async confirmConnection(inboundTopicId, connectionTopicId, connectedAccountId, connectionId, memo, submitKey) {
395
+ const operatorId = await this.getOperatorId();
396
+ this.logger.info(`Confirming connection with ID ${connectionId}`);
397
+ const payload = {
398
+ p: "hcs-10",
399
+ op: "connection_created",
400
+ connection_topic_id: connectionTopicId,
401
+ connected_account_id: connectedAccountId,
402
+ operator_id: operatorId,
403
+ connection_id: connectionId,
404
+ m: memo
405
+ };
406
+ const submissionCheck = await this.canSubmitToTopic(
407
+ inboundTopicId,
408
+ this.client.operatorAccountId?.toString() || ""
409
+ );
410
+ const result = await this.submitPayload(
411
+ inboundTopicId,
412
+ payload,
413
+ submitKey,
414
+ submissionCheck.requiresFee
415
+ );
416
+ const sequenceNumber = result.topicSequenceNumber?.toNumber();
417
+ if (!sequenceNumber) {
418
+ throw new ConnectionConfirmationError(
419
+ "Failed to confirm connection: sequence number is null"
420
+ );
421
+ }
422
+ return sequenceNumber;
84
423
  }
85
- setFeeConfig(feeConfigBuilder) {
86
- this.config.feeConfig = feeConfigBuilder;
87
- return this;
424
+ async sendMessage(connectionTopicId, data, memo, submitKey, options) {
425
+ const submissionCheck = await this.canSubmitToTopic(
426
+ connectionTopicId,
427
+ this.client.operatorAccountId?.toString() || ""
428
+ );
429
+ const operatorId = await this.getOperatorId();
430
+ const payload = {
431
+ p: "hcs-10",
432
+ op: "message",
433
+ operator_id: operatorId,
434
+ data,
435
+ m: memo
436
+ };
437
+ const payloadString = JSON.stringify(payload);
438
+ const isLargePayload = Buffer.from(payloadString).length > 1e3;
439
+ if (isLargePayload) {
440
+ this.logger.info(
441
+ "Message payload exceeds 1000 bytes, storing via inscription"
442
+ );
443
+ try {
444
+ const contentBuffer = Buffer.from(data);
445
+ const fileName = `message-${Date.now()}.json`;
446
+ const inscriptionResult = await this.inscribeFile(
447
+ contentBuffer,
448
+ fileName,
449
+ {
450
+ progressCallback: options?.progressCallback,
451
+ waitMaxAttempts: options?.waitMaxAttempts,
452
+ waitIntervalMs: options?.waitIntervalMs
453
+ }
454
+ );
455
+ if (inscriptionResult?.topic_id) {
456
+ payload.data = `hcs://1/${inscriptionResult.topic_id}`;
457
+ this.logger.info(
458
+ `Large message inscribed with topic ID: ${inscriptionResult.topic_id}`
459
+ );
460
+ } else {
461
+ throw new Error("Failed to inscribe large message content");
462
+ }
463
+ } catch (error) {
464
+ this.logger.error("Error inscribing large message:", error);
465
+ throw new Error(
466
+ `Failed to handle large message: ${error instanceof Error ? error.message : "Unknown error"}`
467
+ );
468
+ }
469
+ }
470
+ this.logger.info("Submitting message to connection topic", payload);
471
+ return await this.submitPayload(
472
+ connectionTopicId,
473
+ payload,
474
+ submitKey,
475
+ submissionCheck.requiresFee
476
+ );
88
477
  }
89
- setConnectionFeeConfig(feeConfigBuilder) {
90
- this.config.connectionFeeConfig = feeConfigBuilder;
91
- return this;
478
+ async createTopic(memo, adminKey, submitKey, feeConfig) {
479
+ this.logger.info("Creating topic");
480
+ const transaction = new TopicCreateTransaction().setTopicMemo(memo);
481
+ if (adminKey) {
482
+ if (typeof adminKey === "boolean" && adminKey && this.client.operatorPublicKey) {
483
+ transaction.setAdminKey(this.client.operatorPublicKey);
484
+ transaction.setAutoRenewAccountId(this.client.operatorAccountId);
485
+ } else if (adminKey instanceof PublicKey || adminKey instanceof KeyList) {
486
+ transaction.setAdminKey(adminKey);
487
+ if (this.client.operatorAccountId) {
488
+ transaction.setAutoRenewAccountId(this.client.operatorAccountId);
489
+ }
490
+ }
491
+ }
492
+ if (submitKey) {
493
+ if (typeof submitKey === "boolean" && submitKey && this.client.operatorPublicKey) {
494
+ transaction.setSubmitKey(this.client.operatorPublicKey);
495
+ } else if (submitKey instanceof PublicKey || submitKey instanceof KeyList) {
496
+ transaction.setSubmitKey(submitKey);
497
+ }
498
+ }
499
+ if (feeConfig) {
500
+ await this.setupFees(transaction, feeConfig);
501
+ }
502
+ this.logger.debug("Executing topic creation transaction");
503
+ const txResponse = await transaction.execute(this.client);
504
+ const receipt = await txResponse.getReceipt(this.client);
505
+ if (!receipt.topicId) {
506
+ this.logger.error("Failed to create topic: topicId is null");
507
+ throw new Error("Failed to create topic: topicId is null");
508
+ }
509
+ const topicId = receipt.topicId.toString();
510
+ return topicId;
92
511
  }
93
- setExistingAccount(accountId, privateKey) {
94
- this.config.existingAccount = { accountId, privateKey };
95
- return this;
512
+ async submitPayload(topicId, payload, submitKey, requiresFee = false) {
513
+ const message = typeof payload === "string" ? payload : JSON.stringify(payload);
514
+ const payloadSizeInBytes = Buffer.byteLength(message, "utf8");
515
+ if (payloadSizeInBytes > 1e3) {
516
+ throw new PayloadSizeError(
517
+ "Payload size exceeds 1000 bytes limit",
518
+ payloadSizeInBytes
519
+ );
520
+ }
521
+ const transaction = new TopicMessageSubmitTransaction().setTopicId(TopicId.fromString(topicId)).setMessage(message);
522
+ if (requiresFee) {
523
+ this.logger.info(
524
+ "Topic requires fee payment, setting max transaction fee"
525
+ );
526
+ transaction.setMaxTransactionFee(new Hbar(this.feeAmount));
527
+ transaction.setTransactionMemo("HIP-991 Fee Payment");
528
+ }
529
+ let transactionResponse;
530
+ if (submitKey) {
531
+ const frozenTransaction = transaction.freezeWith(this.client);
532
+ const signedTransaction = await frozenTransaction.sign(submitKey);
533
+ transactionResponse = await signedTransaction.execute(this.client);
534
+ } else {
535
+ transactionResponse = await transaction.execute(this.client);
536
+ }
537
+ const receipt = await transactionResponse.getReceipt(this.client);
538
+ if (!receipt) {
539
+ this.logger.error("Failed to submit message: receipt is null");
540
+ throw new Error("Failed to submit message: receipt is null");
541
+ }
542
+ this.logger.info("Message submitted successfully");
543
+ return receipt;
96
544
  }
97
- build() {
98
- if (!this.config.name) {
99
- throw new Error("Agent name is required");
545
+ async submitConnectionRequest(inboundTopicId, memo) {
546
+ const accountResponse = this.getAccountAndSigner();
547
+ if (!accountResponse.accountId) {
548
+ throw new Error("Operator account ID is not set");
100
549
  }
101
- if (!this.config.description) {
102
- throw new Error("Agent description is required");
550
+ const operatorId = await this.getOperatorId();
551
+ const accountId = accountResponse.accountId;
552
+ const submissionCheck = await this.canSubmitToTopic(
553
+ inboundTopicId,
554
+ accountId
555
+ );
556
+ if (!submissionCheck.canSubmit) {
557
+ throw new Error(`Cannot submit to topic: ${submissionCheck.reason}`);
103
558
  }
104
- if (!this.config.pfpBuffer || !this.config.pfpFileName) {
105
- this.logger.warn("No profile picture provided, skipping...");
559
+ const connectionRequestMessage = {
560
+ p: "hcs-10",
561
+ op: "connection_request",
562
+ operator_id: operatorId,
563
+ m: memo
564
+ };
565
+ const requiresFee = submissionCheck.requiresFee;
566
+ const response = await this.submitPayload(
567
+ inboundTopicId,
568
+ connectionRequestMessage,
569
+ void 0,
570
+ requiresFee
571
+ );
572
+ this.logger.info(
573
+ `Submitted connection request to topic ID: ${inboundTopicId}`
574
+ );
575
+ const outboundTopic = await this.retrieveOutboundConnectTopic(accountId);
576
+ const responseSequenceNumber = response.topicSequenceNumber?.toNumber();
577
+ if (!responseSequenceNumber) {
578
+ throw new Error("Failed to get response sequence number");
106
579
  }
107
- if (!this.config.network) {
108
- throw new Error("Network is required");
580
+ await this.submitPayload(outboundTopic.outboundTopic, {
581
+ ...connectionRequestMessage,
582
+ outbound_topic_id: outboundTopic.outboundTopic,
583
+ connection_request_id: responseSequenceNumber
584
+ });
585
+ return response;
586
+ }
587
+ async inscribeFile(buffer, fileName, options) {
588
+ this.logger.info("Inscribing file");
589
+ if (!this.client.operatorAccountId) {
590
+ this.logger.error("Operator account ID is not set");
591
+ throw new Error("Operator account ID is not set");
109
592
  }
110
- if (!this.config.inboundTopicType) {
111
- this.config.inboundTopicType = InboundTopicType.PUBLIC;
593
+ if (!this.operatorPrivateKey) {
594
+ this.logger.error("Operator private key is not set");
595
+ throw new Error("Operator private key is not set");
112
596
  }
113
- if (!this.config.capabilities) {
114
- this.config.capabilities = [];
597
+ const mimeType = mimeTypesExports.lookup(fileName) || "application/octet-stream";
598
+ const sdk = await InscriptionSDK.createWithAuth({
599
+ type: "server",
600
+ accountId: this.client.operatorAccountId.toString(),
601
+ privateKey: this.operatorPrivateKey.toString(),
602
+ network: this.network
603
+ });
604
+ const inscriptionOptions = {
605
+ mode: "file",
606
+ waitForConfirmation: true,
607
+ waitMaxAttempts: options?.waitMaxAttempts || 30,
608
+ waitIntervalMs: options?.waitIntervalMs || 4e3,
609
+ progressCallback: options?.progressCallback,
610
+ logging: {
611
+ level: this.logger.getLevel ? this.logger.getLevel() : "info"
612
+ }
613
+ };
614
+ const response = await inscribe(
615
+ {
616
+ type: "buffer",
617
+ buffer,
618
+ fileName,
619
+ mimeType
620
+ },
621
+ {
622
+ accountId: this.client.operatorAccountId.toString(),
623
+ privateKey: this.operatorPrivateKey.toString(),
624
+ network: this.network
625
+ },
626
+ inscriptionOptions,
627
+ sdk
628
+ );
629
+ if (!response.confirmed || !response.inscription) {
630
+ throw new Error("Inscription was not confirmed");
115
631
  }
116
- if (!this.config.metadata) {
117
- this.config.metadata = { type: "autonomous" };
632
+ return response.inscription;
633
+ }
634
+ /**
635
+ * Waits for confirmation of a connection request
636
+ * @param inboundTopicId Inbound topic ID
637
+ * @param connectionRequestId Connection request ID
638
+ * @param maxAttempts Maximum number of attempts
639
+ * @param delayMs Delay between attempts in milliseconds
640
+ * @returns Connection confirmation details
641
+ */
642
+ async waitForConnectionConfirmation(inboundTopicId, connectionRequestId, maxAttempts = 60, delayMs = 2e3) {
643
+ this.logger.info(
644
+ `Waiting for connection confirmation on inbound topic ${inboundTopicId} for request ID ${connectionRequestId}`
645
+ );
646
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
647
+ this.logger.info(
648
+ `Attempt ${attempt + 1}/${maxAttempts} to find connection confirmation`
649
+ );
650
+ const messages = await this.mirrorNode.getTopicMessages(inboundTopicId);
651
+ const connectionCreatedMessages = messages.filter(
652
+ (m) => m.op === "connection_created"
653
+ );
654
+ this.logger.info(
655
+ `Found ${connectionCreatedMessages.length} connection_created messages`
656
+ );
657
+ if (connectionCreatedMessages.length > 0) {
658
+ for (const message of connectionCreatedMessages) {
659
+ if (Number(message.connection_id) === Number(connectionRequestId)) {
660
+ this.logger.info("Connection confirmation found");
661
+ return {
662
+ connectionTopicId: message.connection_topic_id,
663
+ sequence_number: Number(message.sequence_number),
664
+ confirmedBy: message.operator_id,
665
+ memo: message.m
666
+ };
667
+ }
668
+ }
669
+ }
670
+ if (attempt < maxAttempts - 1) {
671
+ this.logger.info(
672
+ `No matching confirmation found, waiting ${delayMs}ms before retrying...`
673
+ );
674
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
675
+ }
676
+ }
677
+ throw new Error(
678
+ `Connection confirmation not found after ${maxAttempts} attempts for request ID ${connectionRequestId}`
679
+ );
680
+ }
681
+ getAccountAndSigner() {
682
+ return {
683
+ accountId: this.client.operatorAccountId.toString(),
684
+ signer: this.operatorPrivateKey
685
+ };
686
+ }
687
+ /**
688
+ * Creates and registers an agent with a Guarded registry.
689
+ *
690
+ * This function performs the following steps:
691
+ * 1. Creates a new account if no existing account is provided.
692
+ * 2. Initializes an HCS10 client with the new account.
693
+ * 3. Creates an agent on the client.
694
+ * 4. Registers the agent with the Hashgraph Online Guarded Registry.
695
+ *
696
+ * @param builder The agent builder object
697
+ * @param options Optional configuration including progress callback and state management
698
+ * @returns Agent registration result
699
+ */
700
+ async createAndRegisterAgent(builder, options) {
701
+ try {
702
+ const config = builder.build();
703
+ const progressCallback = options?.progressCallback;
704
+ const baseUrl = options?.baseUrl || this.guardedRegistryBaseUrl;
705
+ let state = options?.existingState || void 0;
706
+ if (progressCallback) {
707
+ progressCallback({
708
+ stage: "preparing",
709
+ message: "Preparing agent registration",
710
+ progressPercent: 10,
711
+ details: { state }
712
+ });
713
+ }
714
+ const account = config.existingAccount || await this.createAccount();
715
+ if (progressCallback) {
716
+ progressCallback({
717
+ stage: "preparing",
718
+ message: "Created account or using existing account",
719
+ progressPercent: 20,
720
+ details: { state, account }
721
+ });
722
+ }
723
+ const agentClient = new HCS10Client({
724
+ network: config.network,
725
+ operatorId: account.accountId,
726
+ operatorPrivateKey: account.privateKey,
727
+ operatorPublicKey: PrivateKey.fromString(
728
+ account.privateKey
729
+ ).publicKey.toString(),
730
+ logLevel: "info",
731
+ guardedRegistryBaseUrl: baseUrl
732
+ });
733
+ if (progressCallback) {
734
+ progressCallback({
735
+ stage: "preparing",
736
+ message: "Initialized agent client",
737
+ progressPercent: 30,
738
+ details: { state }
739
+ });
740
+ }
741
+ const { outboundTopicId, inboundTopicId, pfpTopicId, profileTopicId } = await agentClient.createAgent(builder);
742
+ if (progressCallback) {
743
+ progressCallback({
744
+ stage: "submitting",
745
+ message: "Created agent with topics and profile",
746
+ progressPercent: 60,
747
+ details: {
748
+ state,
749
+ outboundTopicId,
750
+ inboundTopicId,
751
+ pfpTopicId,
752
+ profileTopicId
753
+ }
754
+ });
755
+ }
756
+ const operatorId = `${inboundTopicId}@${account.accountId}`;
757
+ const registrationResult = await agentClient.registerAgentWithGuardedRegistry(
758
+ account.accountId,
759
+ config.network,
760
+ {
761
+ progressCallback: (data) => {
762
+ const adjustedPercent = 60 + (data.progressPercent || 0) * 0.4;
763
+ if (progressCallback) {
764
+ progressCallback({
765
+ stage: data.stage,
766
+ message: data.message,
767
+ progressPercent: adjustedPercent,
768
+ details: {
769
+ ...data.details,
770
+ outboundTopicId,
771
+ inboundTopicId,
772
+ pfpTopicId,
773
+ profileTopicId,
774
+ operatorId,
775
+ state: data.details?.state || state
776
+ }
777
+ });
778
+ }
779
+ },
780
+ existingState: state
781
+ }
782
+ );
783
+ if (!registrationResult.success) {
784
+ return registrationResult;
785
+ }
786
+ if (progressCallback) {
787
+ progressCallback({
788
+ stage: "completed",
789
+ message: "Agent creation and registration complete",
790
+ progressPercent: 100,
791
+ details: {
792
+ outboundTopicId,
793
+ inboundTopicId,
794
+ pfpTopicId,
795
+ profileTopicId,
796
+ operatorId,
797
+ state: registrationResult.state
798
+ }
799
+ });
800
+ }
801
+ return {
802
+ ...registrationResult,
803
+ metadata: {
804
+ accountId: account.accountId,
805
+ privateKey: account.privateKey,
806
+ operatorId,
807
+ inboundTopicId,
808
+ outboundTopicId,
809
+ profileTopicId,
810
+ pfpTopicId
811
+ }
812
+ };
813
+ } catch (error) {
814
+ this.logger.error(
815
+ `Failed to create and register agent: ${error.message}`
816
+ );
817
+ return {
818
+ error: error.message,
819
+ success: false
820
+ };
821
+ }
822
+ }
823
+ /**
824
+ * Registers an agent with the guarded registry
825
+ * @param accountId Account ID to register
826
+ * @param inboundTopicId Inbound topic ID for the agent
827
+ * @param network Network type ('mainnet' or 'testnet')
828
+ * @param options Optional configuration including progress callback and confirmation settings
829
+ * @returns Registration result
830
+ */
831
+ async registerAgentWithGuardedRegistry(accountId, network = this.network, options) {
832
+ try {
833
+ this.logger.info("Registering agent with guarded registry");
834
+ const maxAttempts = options?.maxAttempts ?? 60;
835
+ const delayMs = options?.delayMs ?? 2e3;
836
+ const progressCallback = options?.progressCallback;
837
+ let state = options?.existingState || {
838
+ currentStage: "registration",
839
+ completedPercentage: 0,
840
+ createdResources: []
841
+ };
842
+ if (progressCallback) {
843
+ progressCallback({
844
+ stage: "preparing",
845
+ message: "Preparing agent registration",
846
+ progressPercent: 10,
847
+ details: {
848
+ state
849
+ }
850
+ });
851
+ }
852
+ const registrationResult = await this.executeRegistration(
853
+ accountId,
854
+ network,
855
+ this.guardedRegistryBaseUrl,
856
+ this.logger
857
+ );
858
+ if (!registrationResult.success) {
859
+ return {
860
+ ...registrationResult,
861
+ state
862
+ };
863
+ }
864
+ if (progressCallback) {
865
+ progressCallback({
866
+ stage: "submitting",
867
+ message: "Submitting registration to registry",
868
+ progressPercent: 30,
869
+ details: {
870
+ transactionId: registrationResult.transactionId,
871
+ state
872
+ }
873
+ });
874
+ }
875
+ if (registrationResult.transaction) {
876
+ const transaction = Transaction.fromBytes(
877
+ Buffer.from(registrationResult.transaction, "base64")
878
+ );
879
+ this.logger.info(`Processing registration transaction`);
880
+ await transaction.execute(this.client);
881
+ this.logger.info(`Successfully processed registration transaction`);
882
+ }
883
+ if (progressCallback) {
884
+ progressCallback({
885
+ stage: "confirming",
886
+ message: "Confirming registration transaction",
887
+ progressPercent: 60,
888
+ details: {
889
+ accountId,
890
+ transactionId: registrationResult.transactionId,
891
+ state
892
+ }
893
+ });
894
+ }
895
+ const confirmed = await this.waitForRegistrationConfirmation(
896
+ registrationResult.transactionId,
897
+ network,
898
+ this.guardedRegistryBaseUrl,
899
+ maxAttempts,
900
+ delayMs,
901
+ this.logger
902
+ );
903
+ state.currentStage = "complete";
904
+ state.completedPercentage = 100;
905
+ if (!state.createdResources) {
906
+ state.createdResources = [];
907
+ }
908
+ if (registrationResult.transactionId) {
909
+ state.createdResources.push(
910
+ `registration:${registrationResult.transactionId}`
911
+ );
912
+ }
913
+ if (progressCallback) {
914
+ progressCallback({
915
+ stage: "completed",
916
+ message: "Agent registration complete",
917
+ progressPercent: 100,
918
+ details: {
919
+ confirmed,
920
+ transactionId: registrationResult.transactionId,
921
+ state
922
+ }
923
+ });
924
+ }
925
+ return {
926
+ ...registrationResult,
927
+ confirmed,
928
+ state
929
+ };
930
+ } catch (error) {
931
+ this.logger.error(`Failed to register agent: ${error.message}`);
932
+ return {
933
+ error: error.message,
934
+ success: false
935
+ };
118
936
  }
119
- if (this.config.inboundTopicType === InboundTopicType.FEE_BASED && !this.config.feeConfig) {
120
- throw new Error("Fee configuration is required for fee-based topics");
937
+ }
938
+ /**
939
+ * Registers an agent with the guarded registry. Should be called by a registry.
940
+ * @param registryTopicId - The topic ID of the guarded registry.
941
+ * @param accountId - The account ID of the agent
942
+ * @param inboundTopicId - The topic ID of the inbound topic
943
+ * @param memo - The memo of the agent
944
+ * @param submitKey - The submit key of the agent
945
+ */
946
+ async registerAgent(registryTopicId, accountId, inboundTopicId, memo, submitKey) {
947
+ this.logger.info("Registering agent");
948
+ const payload = {
949
+ p: "hcs-10",
950
+ op: "register",
951
+ account_id: accountId,
952
+ inbound_topic_id: inboundTopicId,
953
+ m: memo
954
+ };
955
+ await this.submitPayload(registryTopicId, payload, submitKey);
956
+ }
957
+ async getInboundTopicType(topicId) {
958
+ try {
959
+ const topicInfo = await this.mirrorNode.getTopicInfo(topicId);
960
+ if (!topicInfo) {
961
+ throw new Error("Topic does not exist");
962
+ }
963
+ const hasSubmitKey = topicInfo.submit_key && topicInfo.submit_key.key;
964
+ if (!hasSubmitKey) {
965
+ return InboundTopicType.PUBLIC;
966
+ }
967
+ const hasFeeScheduleKey = topicInfo.fee_schedule_key && topicInfo.fee_schedule_key.key;
968
+ if (hasFeeScheduleKey && topicInfo.custom_fees) {
969
+ const customFees = topicInfo.custom_fees;
970
+ if (customFees && customFees.fixed_fees && customFees.fixed_fees.length > 0) {
971
+ this.logger.info(
972
+ `Topic ${topicId} is fee-based with ${customFees.fixed_fees.length} custom fees`
973
+ );
974
+ return InboundTopicType.FEE_BASED;
975
+ }
976
+ }
977
+ return InboundTopicType.CONTROLLED;
978
+ } catch (error) {
979
+ this.logger.error(`Error determining topic type: ${error.message}`);
980
+ throw new Error(`Failed to determine topic type: ${error.message}`);
121
981
  }
122
- return this.config;
982
+ }
983
+ getNetwork() {
984
+ return this.network;
985
+ }
986
+ getLogger() {
987
+ return this.logger;
123
988
  }
124
989
  }
125
990
  export {
126
- AgentBuilder
991
+ HCS10Client
127
992
  };
128
993
  //# sourceMappingURL=standards-sdk.es7.js.map