@hashgraphonline/standards-sdk 0.0.52 → 0.0.53

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 (236) hide show
  1. package/dist/es/hcs-10/base-client.d.ts +40 -45
  2. package/dist/es/hcs-10/base-client.d.ts.map +1 -1
  3. package/dist/es/hcs-10/browser.d.ts +8 -10
  4. package/dist/es/hcs-10/browser.d.ts.map +1 -1
  5. package/dist/es/hcs-10/sdk.d.ts +67 -13
  6. package/dist/es/hcs-10/sdk.d.ts.map +1 -1
  7. package/dist/es/hcs-10/types.d.ts +0 -7
  8. package/dist/es/hcs-10/types.d.ts.map +1 -1
  9. package/dist/es/hcs-11/index.d.ts +1 -1
  10. package/dist/es/hcs-11/index.d.ts.map +1 -1
  11. package/dist/es/inscribe/types.d.ts +1 -1
  12. package/dist/es/inscribe/types.d.ts.map +1 -1
  13. package/dist/es/services/mirror-node.d.ts.map +1 -1
  14. package/dist/es/standards-sdk.es.js +2 -1
  15. package/dist/es/standards-sdk.es10.js +138 -123
  16. package/dist/es/standards-sdk.es10.js.map +1 -1
  17. package/dist/es/standards-sdk.es100.js +3 -4
  18. package/dist/es/standards-sdk.es100.js.map +1 -1
  19. package/dist/es/standards-sdk.es101.js +16 -39
  20. package/dist/es/standards-sdk.es101.js.map +1 -1
  21. package/dist/es/standards-sdk.es102.js +5 -40
  22. package/dist/es/standards-sdk.es102.js.map +1 -1
  23. package/dist/es/standards-sdk.es103.js +37 -35
  24. package/dist/es/standards-sdk.es103.js.map +1 -1
  25. package/dist/es/standards-sdk.es104.js +34 -72
  26. package/dist/es/standards-sdk.es104.js.map +1 -1
  27. package/dist/es/standards-sdk.es105.js +37 -3
  28. package/dist/es/standards-sdk.es105.js.map +1 -1
  29. package/dist/es/standards-sdk.es106.js +78 -2
  30. package/dist/es/standards-sdk.es106.js.map +1 -1
  31. package/dist/es/standards-sdk.es107.js +3 -2
  32. package/dist/es/standards-sdk.es107.js.map +1 -1
  33. package/dist/es/standards-sdk.es108.js +2 -34
  34. package/dist/es/standards-sdk.es108.js.map +1 -1
  35. package/dist/es/standards-sdk.es109.js +2 -33
  36. package/dist/es/standards-sdk.es109.js.map +1 -1
  37. package/dist/es/standards-sdk.es110.js +34 -9
  38. package/dist/es/standards-sdk.es110.js.map +1 -1
  39. package/dist/es/standards-sdk.es111.js +31 -32
  40. package/dist/es/standards-sdk.es111.js.map +1 -1
  41. package/dist/es/standards-sdk.es112.js +12 -0
  42. package/dist/es/standards-sdk.es112.js.map +1 -0
  43. package/dist/es/standards-sdk.es113.js +37 -0
  44. package/dist/es/standards-sdk.es113.js.map +1 -0
  45. package/dist/es/standards-sdk.es12.js +3 -2
  46. package/dist/es/standards-sdk.es12.js.map +1 -1
  47. package/dist/es/standards-sdk.es13.js +1 -1
  48. package/dist/es/standards-sdk.es16.js +2 -1
  49. package/dist/es/standards-sdk.es16.js.map +1 -1
  50. package/dist/es/standards-sdk.es17.js +6 -3
  51. package/dist/es/standards-sdk.es17.js.map +1 -1
  52. package/dist/es/standards-sdk.es18.js.map +1 -1
  53. package/dist/es/standards-sdk.es19.js +1767 -3
  54. package/dist/es/standards-sdk.es19.js.map +1 -1
  55. package/dist/es/standards-sdk.es20.js +3 -4167
  56. package/dist/es/standards-sdk.es20.js.map +1 -1
  57. package/dist/es/standards-sdk.es21.js +4086 -960
  58. package/dist/es/standards-sdk.es21.js.map +1 -1
  59. package/dist/es/standards-sdk.es22.js +1041 -36
  60. package/dist/es/standards-sdk.es22.js.map +1 -1
  61. package/dist/es/standards-sdk.es23.js +5 -48
  62. package/dist/es/standards-sdk.es23.js.map +1 -1
  63. package/dist/es/standards-sdk.es24.js +36 -6624
  64. package/dist/es/standards-sdk.es24.js.map +1 -1
  65. package/dist/es/standards-sdk.es25.js +48 -5
  66. package/dist/es/standards-sdk.es25.js.map +1 -1
  67. package/dist/es/standards-sdk.es26.js +6627 -2
  68. package/dist/es/standards-sdk.es26.js.map +1 -1
  69. package/dist/es/standards-sdk.es27.js +2 -101
  70. package/dist/es/standards-sdk.es27.js.map +1 -1
  71. package/dist/es/standards-sdk.es28.js +419 -2
  72. package/dist/es/standards-sdk.es28.js.map +1 -1
  73. package/dist/es/standards-sdk.es29.js +2 -16
  74. package/dist/es/standards-sdk.es29.js.map +1 -1
  75. package/dist/es/standards-sdk.es30.js +120 -4
  76. package/dist/es/standards-sdk.es30.js.map +1 -1
  77. package/dist/es/standards-sdk.es31.js +101 -2282
  78. package/dist/es/standards-sdk.es31.js.map +1 -1
  79. package/dist/es/standards-sdk.es32.js +2 -2
  80. package/dist/es/standards-sdk.es32.js.map +1 -1
  81. package/dist/es/standards-sdk.es33.js +15 -418
  82. package/dist/es/standards-sdk.es33.js.map +1 -1
  83. package/dist/es/standards-sdk.es34.js +409 -2
  84. package/dist/es/standards-sdk.es34.js.map +1 -1
  85. package/dist/es/standards-sdk.es35.js +2282 -120
  86. package/dist/es/standards-sdk.es35.js.map +1 -1
  87. package/dist/es/standards-sdk.es36.js +164 -2
  88. package/dist/es/standards-sdk.es36.js.map +1 -1
  89. package/dist/es/standards-sdk.es37.js +0 -25
  90. package/dist/es/standards-sdk.es37.js.map +1 -1
  91. package/dist/es/standards-sdk.es38.js +2 -362
  92. package/dist/es/standards-sdk.es38.js.map +1 -1
  93. package/dist/es/standards-sdk.es39.js +3 -6
  94. package/dist/es/standards-sdk.es39.js.map +1 -1
  95. package/dist/es/standards-sdk.es4.js +1 -1
  96. package/dist/es/standards-sdk.es40.js +185 -169
  97. package/dist/es/standards-sdk.es40.js.map +1 -1
  98. package/dist/es/standards-sdk.es41.js +437 -80
  99. package/dist/es/standards-sdk.es41.js.map +1 -1
  100. package/dist/es/standards-sdk.es42.js +21 -110
  101. package/dist/es/standards-sdk.es42.js.map +1 -1
  102. package/dist/es/standards-sdk.es43.js +130 -43
  103. package/dist/es/standards-sdk.es43.js.map +1 -1
  104. package/dist/es/standards-sdk.es44.js +17 -9
  105. package/dist/es/standards-sdk.es44.js.map +1 -1
  106. package/dist/es/standards-sdk.es45.js +22 -90
  107. package/dist/es/standards-sdk.es45.js.map +1 -1
  108. package/dist/es/standards-sdk.es46.js +28 -3
  109. package/dist/es/standards-sdk.es46.js.map +1 -1
  110. package/dist/es/standards-sdk.es47.js +21 -2
  111. package/dist/es/standards-sdk.es47.js.map +1 -1
  112. package/dist/es/standards-sdk.es48.js +36 -104
  113. package/dist/es/standards-sdk.es48.js.map +1 -1
  114. package/dist/es/standards-sdk.es49.js +15 -71
  115. package/dist/es/standards-sdk.es49.js.map +1 -1
  116. package/dist/es/standards-sdk.es5.js +410 -134
  117. package/dist/es/standards-sdk.es5.js.map +1 -1
  118. package/dist/es/standards-sdk.es50.js +60 -5
  119. package/dist/es/standards-sdk.es50.js.map +1 -1
  120. package/dist/es/standards-sdk.es51.js +1288 -4
  121. package/dist/es/standards-sdk.es51.js.map +1 -1
  122. package/dist/es/standards-sdk.es52.js +131 -204
  123. package/dist/es/standards-sdk.es52.js.map +1 -1
  124. package/dist/es/standards-sdk.es53.js +89 -56
  125. package/dist/es/standards-sdk.es53.js.map +1 -1
  126. package/dist/es/standards-sdk.es54.js +84 -69
  127. package/dist/es/standards-sdk.es54.js.map +1 -1
  128. package/dist/es/standards-sdk.es55.js +27 -190
  129. package/dist/es/standards-sdk.es55.js.map +1 -1
  130. package/dist/es/standards-sdk.es56.js +5 -437
  131. package/dist/es/standards-sdk.es56.js.map +1 -1
  132. package/dist/es/standards-sdk.es57.js +155 -21
  133. package/dist/es/standards-sdk.es57.js.map +1 -1
  134. package/dist/es/standards-sdk.es58.js +21 -137
  135. package/dist/es/standards-sdk.es58.js.map +1 -1
  136. package/dist/es/standards-sdk.es59.js +788 -13
  137. package/dist/es/standards-sdk.es59.js.map +1 -1
  138. package/dist/es/standards-sdk.es60.js +167 -22
  139. package/dist/es/standards-sdk.es60.js.map +1 -1
  140. package/dist/es/standards-sdk.es61.js +137 -23
  141. package/dist/es/standards-sdk.es61.js.map +1 -1
  142. package/dist/es/standards-sdk.es62.js +358 -15
  143. package/dist/es/standards-sdk.es62.js.map +1 -1
  144. package/dist/es/standards-sdk.es63.js +5 -43
  145. package/dist/es/standards-sdk.es63.js.map +1 -1
  146. package/dist/es/standards-sdk.es64.js +174 -13
  147. package/dist/es/standards-sdk.es64.js.map +1 -1
  148. package/dist/es/standards-sdk.es65.js +76 -56
  149. package/dist/es/standards-sdk.es65.js.map +1 -1
  150. package/dist/es/standards-sdk.es66.js +104 -1279
  151. package/dist/es/standards-sdk.es66.js.map +1 -1
  152. package/dist/es/standards-sdk.es67.js +42 -138
  153. package/dist/es/standards-sdk.es67.js.map +1 -1
  154. package/dist/es/standards-sdk.es68.js +10 -91
  155. package/dist/es/standards-sdk.es68.js.map +1 -1
  156. package/dist/es/standards-sdk.es69.js +89 -76
  157. package/dist/es/standards-sdk.es69.js.map +1 -1
  158. package/dist/es/standards-sdk.es70.js +3 -31
  159. package/dist/es/standards-sdk.es70.js.map +1 -1
  160. package/dist/es/standards-sdk.es71.js +2 -6
  161. package/dist/es/standards-sdk.es71.js.map +1 -1
  162. package/dist/es/standards-sdk.es72.js +99 -145
  163. package/dist/es/standards-sdk.es72.js.map +1 -1
  164. package/dist/es/standards-sdk.es73.js +71 -20
  165. package/dist/es/standards-sdk.es73.js.map +1 -1
  166. package/dist/es/standards-sdk.es74.js +5 -792
  167. package/dist/es/standards-sdk.es74.js.map +1 -1
  168. package/dist/es/standards-sdk.es75.js +4 -142
  169. package/dist/es/standards-sdk.es75.js.map +1 -1
  170. package/dist/es/standards-sdk.es76.js +209 -162
  171. package/dist/es/standards-sdk.es76.js.map +1 -1
  172. package/dist/es/standards-sdk.es77.js +56 -30
  173. package/dist/es/standards-sdk.es77.js.map +1 -1
  174. package/dist/es/standards-sdk.es78.js +69 -63
  175. package/dist/es/standards-sdk.es78.js.map +1 -1
  176. package/dist/es/standards-sdk.es79.js +17 -46
  177. package/dist/es/standards-sdk.es79.js.map +1 -1
  178. package/dist/es/standards-sdk.es8.js +143 -180
  179. package/dist/es/standards-sdk.es8.js.map +1 -1
  180. package/dist/es/standards-sdk.es80.js +25 -8
  181. package/dist/es/standards-sdk.es80.js.map +1 -1
  182. package/dist/es/standards-sdk.es81.js +24 -63
  183. package/dist/es/standards-sdk.es81.js.map +1 -1
  184. package/dist/es/standards-sdk.es82.js +38 -6
  185. package/dist/es/standards-sdk.es82.js.map +1 -1
  186. package/dist/es/standards-sdk.es83.js +30 -13
  187. package/dist/es/standards-sdk.es83.js.map +1 -1
  188. package/dist/es/standards-sdk.es84.js +63 -7
  189. package/dist/es/standards-sdk.es84.js.map +1 -1
  190. package/dist/es/standards-sdk.es85.js +47 -42
  191. package/dist/es/standards-sdk.es85.js.map +1 -1
  192. package/dist/es/standards-sdk.es86.js +10 -2
  193. package/dist/es/standards-sdk.es86.js.map +1 -1
  194. package/dist/es/standards-sdk.es87.js +58 -129
  195. package/dist/es/standards-sdk.es87.js.map +1 -1
  196. package/dist/es/standards-sdk.es88.js +5 -171
  197. package/dist/es/standards-sdk.es88.js.map +1 -1
  198. package/dist/es/standards-sdk.es89.js +14 -20
  199. package/dist/es/standards-sdk.es89.js.map +1 -1
  200. package/dist/es/standards-sdk.es9.js +1 -1
  201. package/dist/es/standards-sdk.es90.js +7 -27
  202. package/dist/es/standards-sdk.es90.js.map +1 -1
  203. package/dist/es/standards-sdk.es91.js +45 -26
  204. package/dist/es/standards-sdk.es91.js.map +1 -1
  205. package/dist/es/standards-sdk.es92.js +2 -38
  206. package/dist/es/standards-sdk.es92.js.map +1 -1
  207. package/dist/es/standards-sdk.es93.js +134 -30
  208. package/dist/es/standards-sdk.es93.js.map +1 -1
  209. package/dist/es/standards-sdk.es94.js +171 -14
  210. package/dist/es/standards-sdk.es94.js.map +1 -1
  211. package/dist/es/standards-sdk.es95.js +13 -4
  212. package/dist/es/standards-sdk.es95.js.map +1 -1
  213. package/dist/es/standards-sdk.es96.js +13 -4
  214. package/dist/es/standards-sdk.es96.js.map +1 -1
  215. package/dist/es/standards-sdk.es97.js +31 -12
  216. package/dist/es/standards-sdk.es97.js.map +1 -1
  217. package/dist/es/standards-sdk.es98.js +15 -13
  218. package/dist/es/standards-sdk.es98.js.map +1 -1
  219. package/dist/es/standards-sdk.es99.js +3 -15
  220. package/dist/es/standards-sdk.es99.js.map +1 -1
  221. package/dist/umd/hcs-10/base-client.d.ts +40 -45
  222. package/dist/umd/hcs-10/base-client.d.ts.map +1 -1
  223. package/dist/umd/hcs-10/browser.d.ts +8 -10
  224. package/dist/umd/hcs-10/browser.d.ts.map +1 -1
  225. package/dist/umd/hcs-10/sdk.d.ts +67 -13
  226. package/dist/umd/hcs-10/sdk.d.ts.map +1 -1
  227. package/dist/umd/hcs-10/types.d.ts +0 -7
  228. package/dist/umd/hcs-10/types.d.ts.map +1 -1
  229. package/dist/umd/hcs-11/index.d.ts +1 -1
  230. package/dist/umd/hcs-11/index.d.ts.map +1 -1
  231. package/dist/umd/inscribe/types.d.ts +1 -1
  232. package/dist/umd/inscribe/types.d.ts.map +1 -1
  233. package/dist/umd/services/mirror-node.d.ts.map +1 -1
  234. package/dist/umd/standards-sdk.umd.js +23 -19
  235. package/dist/umd/standards-sdk.umd.js.map +1 -1
  236. package/package.json +1 -1
@@ -1,9 +1,10 @@
1
- import { Client, PrivateKey, AccountCreateTransaction, Hbar, CustomFixedFee, AccountId, KeyList, TopicCreateTransaction, PublicKey, TopicMessageSubmitTransaction, TopicId } from "@hashgraph/sdk";
1
+ import Buffer from "./standards-sdk.es19.js";
2
+ import { Client, PrivateKey, AccountCreateTransaction, Hbar, CustomFixedFee, AccountId, KeyList, TopicCreateTransaction, PublicKey, TopicMessageSubmitTransaction, TopicId, Transaction } from "@hashgraph/sdk";
2
3
  import { AccountCreationError, TopicCreationError, ConnectionConfirmationError, PayloadSizeError } from "./standards-sdk.es6.js";
3
- import { InscriptionSDK } from "./standards-sdk.es24.js";
4
+ import { InscriptionSDK } from "./standards-sdk.es26.js";
4
5
  import { Logger } from "./standards-sdk.es13.js";
5
- import { HCS10BaseClient } from "./standards-sdk.es8.js";
6
- import { m as mimeTypesExports } from "./standards-sdk.es19.js";
6
+ import { HCS10BaseClient, Hcs10MemoType } from "./standards-sdk.es8.js";
7
+ import { m as mimeTypesExports } from "./standards-sdk.es20.js";
7
8
  import { InboundTopicType } from "./standards-sdk.es18.js";
8
9
  import { HCS11Client } from "./standards-sdk.es12.js";
9
10
  import { accountIdsToExemptKeys } from "./standards-sdk.es14.js";
@@ -12,13 +13,10 @@ class HCS10Client extends HCS10BaseClient {
12
13
  super({
13
14
  network: config.network,
14
15
  logLevel: config.logLevel,
15
- prettyPrint: config.prettyPrint
16
+ prettyPrint: config.prettyPrint,
17
+ feeAmount: config.feeAmount
16
18
  });
17
- if (config.network === "mainnet") {
18
- this.client = Client.forMainnet();
19
- } else {
20
- this.client = Client.forTestnet();
21
- }
19
+ this.client = config.network === "mainnet" ? Client.forMainnet() : Client.forTestnet();
22
20
  this.operatorPrivateKey = PrivateKey.fromString(config.operatorPrivateKey);
23
21
  this.network = config.network;
24
22
  this.client.setOperator(
@@ -69,37 +67,53 @@ class HCS10Client extends HCS10BaseClient {
69
67
  };
70
68
  }
71
69
  /**
72
- * Creates an inbound topic with the specified configuration
73
- * @param accountId Account ID associated with the topic
70
+ * Creates an inbound topic for an agent
71
+ * @param accountId The account ID associated with the inbound topic
74
72
  * @param topicType Type of inbound topic (public, controlled, or fee-based)
75
- * @param feeConfig Optional fee configuration for fee-based topics
73
+ * @param ttl Optional Time-To-Live for the topic memo, defaults to 60
74
+ * @param feeConfigBuilder Optional fee configuration builder for fee-based topics
76
75
  * @returns The topic ID of the created inbound topic
77
76
  */
78
- async createInboundTopic(accountId, topicType, feeConfig) {
79
- this.logger.info(`Creating ${topicType} inbound topic`);
80
- const memo = `hcs-10:0:60:0:${accountId}`;
77
+ async createInboundTopic(accountId, topicType, ttl = 60, feeConfigBuilder) {
78
+ const memo = this._generateHcs10Memo(Hcs10MemoType.INBOUND, {
79
+ accountId,
80
+ ttl
81
+ });
82
+ let submitKey;
83
+ let feeConfig;
81
84
  switch (topicType) {
82
85
  case InboundTopicType.PUBLIC:
83
- return this.createTopic(memo, true, false);
86
+ submitKey = false;
87
+ break;
84
88
  case InboundTopicType.CONTROLLED:
85
- return this.createTopic(memo, true, true);
89
+ submitKey = true;
90
+ break;
86
91
  case InboundTopicType.FEE_BASED:
87
- if (!feeConfig) {
88
- throw new Error("Fee configuration is required for fee-based topics");
92
+ submitKey = true;
93
+ if (!feeConfigBuilder) {
94
+ throw new Error(
95
+ "Fee configuration builder is required for fee-based topics"
96
+ );
89
97
  }
90
- return this.createTopic(memo, true, true, feeConfig.build());
98
+ feeConfig = feeConfigBuilder.build();
99
+ break;
91
100
  default:
92
101
  throw new Error(`Unsupported inbound topic type: ${topicType}`);
93
102
  }
103
+ return this.createTopic(memo, true, submitKey, feeConfig);
94
104
  }
95
105
  /**
96
106
  * Creates a new agent with inbound and outbound topics
97
107
  * @param builder The agent builder object
108
+ * @param ttl Optional Time-To-Live for the topic memos, defaults to 60
98
109
  * @returns Object with topic IDs
99
110
  */
100
- async createAgent(builder) {
111
+ async createAgent(builder, ttl = 60) {
101
112
  const config = builder.build();
102
- const outboundTopicId = await this.createTopic("hcs-10:0:60:1", true, true);
113
+ const outboundMemo = this._generateHcs10Memo(Hcs10MemoType.OUTBOUND, {
114
+ ttl
115
+ });
116
+ const outboundTopicId = await this.createTopic(outboundMemo, true, true);
103
117
  this.logger.info(`Created new outbound topic ID: ${outboundTopicId}`);
104
118
  const accountId = this.client.operatorAccountId?.toString();
105
119
  if (!accountId) {
@@ -108,9 +122,9 @@ class HCS10Client extends HCS10BaseClient {
108
122
  const inboundTopicId = await this.createInboundTopic(
109
123
  accountId,
110
124
  config.inboundTopicType,
125
+ ttl,
111
126
  config.inboundTopicType === InboundTopicType.FEE_BASED ? config.feeConfig : void 0
112
127
  );
113
- this.logger.info(`Created new inbound topic ID: ${inboundTopicId}`);
114
128
  let pfpTopicId = config.existingPfpTopicId || "";
115
129
  if (!pfpTopicId && config.pfpBuffer && config.pfpBuffer.length > 0) {
116
130
  this.logger.info("Inscribing new profile picture");
@@ -127,10 +141,6 @@ class HCS10Client extends HCS10BaseClient {
127
141
  `Using existing profile picture with topic ID: ${config.existingPfpTopicId}`
128
142
  );
129
143
  }
130
- let pfpBufferToUse = void 0;
131
- if (config.pfpBuffer && config.pfpBuffer.length > 0) {
132
- pfpBufferToUse = config.pfpBuffer;
133
- }
134
144
  const profileResult = await this.storeHCS11Profile(
135
145
  config.name,
136
146
  config.description,
@@ -138,15 +148,15 @@ class HCS10Client extends HCS10BaseClient {
138
148
  outboundTopicId,
139
149
  config.capabilities,
140
150
  config.metadata,
141
- pfpBufferToUse,
151
+ config.pfpBuffer && config.pfpBuffer.length > 0 ? config.pfpBuffer : void 0,
142
152
  config.pfpFileName,
143
153
  config.existingPfpTopicId
144
154
  );
145
155
  const profileTopicId = profileResult.profileTopicId;
146
156
  this.logger.info(`Profile stored with topic ID: ${profileTopicId}`);
147
157
  return {
148
- outboundTopicId,
149
158
  inboundTopicId,
159
+ outboundTopicId,
150
160
  pfpTopicId,
151
161
  profileTopicId
152
162
  };
@@ -223,16 +233,10 @@ class HCS10Client extends HCS10BaseClient {
223
233
  const agentType = this.hcs11Client.getAgentTypeFromMetadata({
224
234
  type: metadata.type || "autonomous"
225
235
  });
226
- const formattedSocials = metadata.socials ? Object.entries(metadata.socials).filter(([_, handle]) => handle).map(([platform, handle]) => {
227
- let resolvedPlatform = platform;
228
- if (platform === "x") {
229
- resolvedPlatform = "twitter";
230
- }
231
- return {
232
- platform: resolvedPlatform,
233
- handle
234
- };
235
- }) : void 0;
236
+ const formattedSocials = metadata.socials ? Object.entries(metadata.socials).filter(([_, handle]) => handle).map(([platform, handle]) => ({
237
+ platform: platform === "x" ? "twitter" : platform,
238
+ handle
239
+ })) : void 0;
236
240
  const profile = this.hcs11Client.createAIAgentProfile(
237
241
  agentName,
238
242
  agentType,
@@ -241,7 +245,7 @@ class HCS10Client extends HCS10BaseClient {
241
245
  {
242
246
  alias: agentName.toLowerCase().replace(/\s+/g, "_"),
243
247
  bio: agentDescription,
244
- profileImage: void 0,
248
+ profileImage: pfpTopicId ? `hcs://1/${pfpTopicId}` : void 0,
245
249
  socials: formattedSocials,
246
250
  properties: metadata.properties,
247
251
  inboundTopicId,
@@ -249,9 +253,6 @@ class HCS10Client extends HCS10BaseClient {
249
253
  creator: metadata.creator
250
254
  }
251
255
  );
252
- if (pfpTopicId) {
253
- profile.profileImage = `hcs://1/${pfpTopicId}`;
254
- }
255
256
  const profileResult = await this.hcs11Client.createAndInscribeProfile(
256
257
  profile,
257
258
  true
@@ -324,10 +325,15 @@ class HCS10Client extends HCS10BaseClient {
324
325
  * @param requestingAccountId Requesting account ID
325
326
  * @param connectionRequestId Connection request ID
326
327
  * @param connectionFeeConfig Optional fee configuration for the connection topic
328
+ * @param ttl Optional ttl parameter with default
327
329
  * @returns Response with connection details
328
330
  */
329
- async handleConnectionRequest(inboundTopicId, requestingAccountId, connectionRequestId, connectionFeeConfig) {
330
- const memo = `hcs-10:${inboundTopicId}:${connectionRequestId}`;
331
+ async handleConnectionRequest(inboundTopicId, requestingAccountId, connectionRequestId, connectionFeeConfig, ttl = 60) {
332
+ const memo = this._generateHcs10Memo(Hcs10MemoType.CONNECTION, {
333
+ ttl,
334
+ inboundTopicId,
335
+ connectionId: connectionRequestId
336
+ });
331
337
  this.logger.info(
332
338
  `Handling connection request ${connectionRequestId} from ${requestingAccountId}`
333
339
  );
@@ -395,7 +401,16 @@ class HCS10Client extends HCS10BaseClient {
395
401
  connection_id: connectionId,
396
402
  m: memo
397
403
  };
398
- const result = await this.submitPayload(inboundTopicId, payload, submitKey);
404
+ const submissionCheck = await this.canSubmitToTopic(
405
+ inboundTopicId,
406
+ this.client.operatorAccountId?.toString() || ""
407
+ );
408
+ const result = await this.submitPayload(
409
+ inboundTopicId,
410
+ payload,
411
+ submitKey,
412
+ submissionCheck.requiresFee
413
+ );
399
414
  const sequenceNumber = result.topicSequenceNumber?.toNumber();
400
415
  if (!sequenceNumber) {
401
416
  throw new ConnectionConfirmationError(
@@ -404,6 +419,54 @@ class HCS10Client extends HCS10BaseClient {
404
419
  }
405
420
  return sequenceNumber;
406
421
  }
422
+ async sendMessage(connectionTopicId, operatorId, data, memo, submitKey) {
423
+ const submissionCheck = await this.canSubmitToTopic(
424
+ connectionTopicId,
425
+ this.client.operatorAccountId?.toString() || ""
426
+ );
427
+ const payload = {
428
+ p: "hcs-10",
429
+ op: "message",
430
+ operator_id: operatorId,
431
+ data,
432
+ m: memo
433
+ };
434
+ const payloadString = JSON.stringify(payload);
435
+ const isLargePayload = Buffer.from(payloadString).length > 1e3;
436
+ if (isLargePayload) {
437
+ this.logger.info(
438
+ "Message payload exceeds 1000 bytes, storing via inscription"
439
+ );
440
+ try {
441
+ const contentBuffer = Buffer.from(data);
442
+ const fileName = `message-${Date.now()}.json`;
443
+ const inscriptionResult = await this.inscribeFile(
444
+ contentBuffer,
445
+ fileName
446
+ );
447
+ if (inscriptionResult?.topic_id) {
448
+ payload.data = `hcs://1/${inscriptionResult.topic_id}`;
449
+ this.logger.info(
450
+ `Large message inscribed with topic ID: ${inscriptionResult.topic_id}`
451
+ );
452
+ } else {
453
+ throw new Error("Failed to inscribe large message content");
454
+ }
455
+ } catch (error) {
456
+ this.logger.error("Error inscribing large message:", error);
457
+ throw new Error(
458
+ `Failed to handle large message: ${error instanceof Error ? error.message : "Unknown error"}`
459
+ );
460
+ }
461
+ }
462
+ this.logger.info("Submitting message to connection topic", payload);
463
+ await this.submitPayload(
464
+ connectionTopicId,
465
+ payload,
466
+ submitKey,
467
+ submissionCheck.requiresFee
468
+ );
469
+ }
407
470
  async createTopic(memo, adminKey, submitKey, feeConfig) {
408
471
  this.logger.info("Creating topic");
409
472
  const transaction = new TopicCreateTransaction().setTopicMemo(memo);
@@ -438,25 +501,8 @@ class HCS10Client extends HCS10BaseClient {
438
501
  const topicId = receipt.topicId.toString();
439
502
  return topicId;
440
503
  }
441
- async submitMessage(topicId, message, submitKey) {
442
- const submissionCheck = await this.canSubmitToInboundTopic(
443
- topicId,
444
- this.client.operatorAccountId?.toString() || ""
445
- );
446
- return this.submitPayload(
447
- topicId,
448
- message,
449
- submitKey,
450
- submissionCheck.requiresFee
451
- );
452
- }
453
504
  async submitPayload(topicId, payload, submitKey, requiresFee = false) {
454
- let message;
455
- if (typeof payload === "string") {
456
- message = payload;
457
- } else {
458
- message = JSON.stringify(payload);
459
- }
505
+ const message = typeof payload === "string" ? payload : JSON.stringify(payload);
460
506
  const payloadSizeInBytes = Buffer.byteLength(message, "utf8");
461
507
  if (payloadSizeInBytes > 1e3) {
462
508
  throw new PayloadSizeError(
@@ -489,7 +535,7 @@ class HCS10Client extends HCS10BaseClient {
489
535
  return receipt;
490
536
  }
491
537
  async submitConnectionRequest(inboundTopicId, requestingAccountId, operatorId, memo) {
492
- const submissionCheck = await this.canSubmitToInboundTopic(
538
+ const submissionCheck = await this.canSubmitToTopic(
493
539
  inboundTopicId,
494
540
  requestingAccountId
495
541
  );
@@ -530,7 +576,7 @@ class HCS10Client extends HCS10BaseClient {
530
576
  );
531
577
  return response;
532
578
  }
533
- async inscribeFile(buffer, fileName, options) {
579
+ async inscribeFile(buffer, fileName) {
534
580
  this.logger.info("Inscribing file");
535
581
  if (!this.client.operatorAccountId) {
536
582
  this.logger.error("Operator account ID is not set");
@@ -547,14 +593,6 @@ class HCS10Client extends HCS10BaseClient {
547
593
  privateKey: this.operatorPrivateKey.toString(),
548
594
  network: this.network
549
595
  });
550
- const progressCallback = options?.progressCallback;
551
- if (progressCallback) {
552
- progressCallback({
553
- stage: "preparing",
554
- message: "Preparing file for inscription",
555
- progressPercent: 10
556
- });
557
- }
558
596
  const result = await sdk.inscribeAndExecute(
559
597
  {
560
598
  file: {
@@ -581,66 +619,8 @@ class HCS10Client extends HCS10BaseClient {
581
619
  this.logger.info(
582
620
  `Transaction ID: ${result.transactionId}, Job ID: ${result.jobId}`
583
621
  );
584
- if (progressCallback) {
585
- progressCallback({
586
- stage: "submitting",
587
- message: "Inscription transaction submitted",
588
- progressPercent: 30,
589
- details: {
590
- transactionId: result.transactionId,
591
- jobId: result.jobId
592
- }
593
- });
594
- }
595
- }
596
- const maxAttempts = options?.waitMaxAttempts || 30;
597
- const intervalMs = options?.waitIntervalMs || 4e3;
598
- let wrappedProgressCallback = void 0;
599
- if (progressCallback) {
600
- wrappedProgressCallback = (data) => {
601
- let stage;
602
- if (data.confirmed) {
603
- stage = "confirming";
604
- } else if (data.status === "COMPLETED") {
605
- stage = "completed";
606
- } else {
607
- stage = "verifying";
608
- }
609
- let attemptPercent;
610
- if (data.currentAttempt) {
611
- attemptPercent = data.currentAttempt / maxAttempts * 60 + 30;
612
- } else if (data.confirmed) {
613
- attemptPercent = 90;
614
- } else if (data.status === "COMPLETED") {
615
- attemptPercent = 100;
616
- } else {
617
- attemptPercent = 60;
618
- }
619
- progressCallback({
620
- stage,
621
- message: `Waiting for inscription confirmation (attempt ${data.currentAttempt || "?"}/${maxAttempts})`,
622
- progressPercent: Math.min(attemptPercent, 100),
623
- details: data
624
- });
625
- };
626
- }
627
- const status = await sdk.waitForInscription(
628
- result.jobId,
629
- maxAttempts,
630
- intervalMs,
631
- true,
632
- wrappedProgressCallback
633
- );
634
- if (progressCallback && status.topic_id) {
635
- progressCallback({
636
- stage: "completed",
637
- message: "Inscription completed successfully",
638
- progressPercent: 100,
639
- details: {
640
- topicId: status.topic_id
641
- }
642
- });
643
622
  }
623
+ const status = await sdk.waitForInscription(result.jobId, 30, 4e3, true);
644
624
  return status;
645
625
  }
646
626
  /**
@@ -696,6 +676,302 @@ class HCS10Client extends HCS10BaseClient {
696
676
  signer: this.operatorPrivateKey
697
677
  };
698
678
  }
679
+ /**
680
+ * Creates and registers an agent with a Guarded registry.
681
+ *
682
+ * This function performs the following steps:
683
+ * 1. Creates a new account if no existing account is provided.
684
+ * 2. Initializes an HCS10 client with the new account.
685
+ * 3. Creates an agent on the client.
686
+ * 4. Registers the agent with the Hashgraph Online Guarded Registry.
687
+ *
688
+ * @param builder The agent builder object
689
+ * @param options Optional configuration including progress callback and state management
690
+ * @returns Agent registration result
691
+ */
692
+ async createAndRegisterAgent(builder, options) {
693
+ try {
694
+ const config = builder.build();
695
+ const progressCallback = options?.progressCallback;
696
+ const baseUrl = options?.baseUrl || this.guardedRegistryBaseUrl;
697
+ let state = options?.existingState || void 0;
698
+ if (progressCallback) {
699
+ progressCallback({
700
+ stage: "preparing",
701
+ message: "Preparing agent registration",
702
+ progressPercent: 10,
703
+ details: { state }
704
+ });
705
+ }
706
+ const account = config.existingAccount || await this.createAccount();
707
+ if (progressCallback) {
708
+ progressCallback({
709
+ stage: "preparing",
710
+ message: "Created account or using existing account",
711
+ progressPercent: 20,
712
+ details: { state, account }
713
+ });
714
+ }
715
+ const agentClient = new HCS10Client({
716
+ network: config.network,
717
+ operatorId: account.accountId,
718
+ operatorPrivateKey: account.privateKey,
719
+ operatorPublicKey: PrivateKey.fromString(
720
+ account.privateKey
721
+ ).publicKey.toString(),
722
+ logLevel: "info",
723
+ guardedRegistryBaseUrl: baseUrl
724
+ });
725
+ if (progressCallback) {
726
+ progressCallback({
727
+ stage: "preparing",
728
+ message: "Initialized agent client",
729
+ progressPercent: 30,
730
+ details: { state }
731
+ });
732
+ }
733
+ const { outboundTopicId, inboundTopicId, pfpTopicId, profileTopicId } = await agentClient.createAgent(builder);
734
+ if (progressCallback) {
735
+ progressCallback({
736
+ stage: "submitting",
737
+ message: "Created agent with topics and profile",
738
+ progressPercent: 60,
739
+ details: {
740
+ state,
741
+ outboundTopicId,
742
+ inboundTopicId,
743
+ pfpTopicId,
744
+ profileTopicId
745
+ }
746
+ });
747
+ }
748
+ const operatorId = `${inboundTopicId}@${account.accountId}`;
749
+ const registrationResult = await agentClient.registerAgentWithGuardedRegistry(
750
+ account.accountId,
751
+ config.network,
752
+ {
753
+ progressCallback: (data) => {
754
+ const adjustedPercent = 60 + (data.progressPercent || 0) * 0.4;
755
+ if (progressCallback) {
756
+ progressCallback({
757
+ stage: data.stage,
758
+ message: data.message,
759
+ progressPercent: adjustedPercent,
760
+ details: {
761
+ ...data.details,
762
+ outboundTopicId,
763
+ inboundTopicId,
764
+ pfpTopicId,
765
+ profileTopicId,
766
+ operatorId,
767
+ state: data.details?.state || state
768
+ }
769
+ });
770
+ }
771
+ },
772
+ existingState: state
773
+ }
774
+ );
775
+ if (!registrationResult.success) {
776
+ return registrationResult;
777
+ }
778
+ if (progressCallback) {
779
+ progressCallback({
780
+ stage: "completed",
781
+ message: "Agent creation and registration complete",
782
+ progressPercent: 100,
783
+ details: {
784
+ outboundTopicId,
785
+ inboundTopicId,
786
+ pfpTopicId,
787
+ profileTopicId,
788
+ operatorId,
789
+ state: registrationResult.state
790
+ }
791
+ });
792
+ }
793
+ return {
794
+ ...registrationResult,
795
+ metadata: {
796
+ accountId: account.accountId,
797
+ privateKey: account.privateKey,
798
+ operatorId,
799
+ inboundTopicId,
800
+ outboundTopicId,
801
+ profileTopicId,
802
+ pfpTopicId
803
+ }
804
+ };
805
+ } catch (error) {
806
+ this.logger.error(
807
+ `Failed to create and register agent: ${error.message}`
808
+ );
809
+ return {
810
+ error: error.message,
811
+ success: false
812
+ };
813
+ }
814
+ }
815
+ /**
816
+ * Registers an agent with the guarded registry
817
+ * @param accountId Account ID to register
818
+ * @param inboundTopicId Inbound topic ID for the agent
819
+ * @param network Network type ('mainnet' or 'testnet')
820
+ * @param options Optional configuration including progress callback and confirmation settings
821
+ * @returns Registration result
822
+ */
823
+ async registerAgentWithGuardedRegistry(accountId, network = this.network, options) {
824
+ try {
825
+ this.logger.info("Registering agent with guarded registry");
826
+ const maxAttempts = options?.maxAttempts ?? 60;
827
+ const delayMs = options?.delayMs ?? 2e3;
828
+ const progressCallback = options?.progressCallback;
829
+ let state = options?.existingState || {
830
+ currentStage: "registration",
831
+ completedPercentage: 0,
832
+ createdResources: []
833
+ };
834
+ if (progressCallback) {
835
+ progressCallback({
836
+ stage: "preparing",
837
+ message: "Preparing agent registration",
838
+ progressPercent: 10,
839
+ details: {
840
+ state
841
+ }
842
+ });
843
+ }
844
+ const registrationResult = await this.executeRegistration(
845
+ accountId,
846
+ network,
847
+ this.guardedRegistryBaseUrl,
848
+ this.logger
849
+ );
850
+ if (!registrationResult.success) {
851
+ return {
852
+ ...registrationResult,
853
+ state
854
+ };
855
+ }
856
+ if (progressCallback) {
857
+ progressCallback({
858
+ stage: "submitting",
859
+ message: "Submitting registration to registry",
860
+ progressPercent: 30,
861
+ details: {
862
+ transactionId: registrationResult.transactionId,
863
+ state
864
+ }
865
+ });
866
+ }
867
+ if (registrationResult.transaction) {
868
+ const transaction = Transaction.fromBytes(
869
+ Buffer.from(registrationResult.transaction, "base64")
870
+ );
871
+ this.logger.info(`Processing registration transaction`);
872
+ await transaction.execute(this.client);
873
+ this.logger.info(`Successfully processed registration transaction`);
874
+ }
875
+ if (progressCallback) {
876
+ progressCallback({
877
+ stage: "confirming",
878
+ message: "Confirming registration transaction",
879
+ progressPercent: 60,
880
+ details: {
881
+ accountId,
882
+ transactionId: registrationResult.transactionId,
883
+ state
884
+ }
885
+ });
886
+ }
887
+ const confirmed = await this.waitForRegistrationConfirmation(
888
+ registrationResult.transactionId,
889
+ network,
890
+ this.guardedRegistryBaseUrl,
891
+ maxAttempts,
892
+ delayMs,
893
+ this.logger
894
+ );
895
+ state.currentStage = "complete";
896
+ state.completedPercentage = 100;
897
+ if (!state.createdResources) {
898
+ state.createdResources = [];
899
+ }
900
+ if (registrationResult.transactionId) {
901
+ state.createdResources.push(
902
+ `registration:${registrationResult.transactionId}`
903
+ );
904
+ }
905
+ if (progressCallback) {
906
+ progressCallback({
907
+ stage: "completed",
908
+ message: "Agent registration complete",
909
+ progressPercent: 100,
910
+ details: {
911
+ confirmed,
912
+ transactionId: registrationResult.transactionId,
913
+ state
914
+ }
915
+ });
916
+ }
917
+ return {
918
+ ...registrationResult,
919
+ confirmed,
920
+ state
921
+ };
922
+ } catch (error) {
923
+ this.logger.error(`Failed to register agent: ${error.message}`);
924
+ return {
925
+ error: error.message,
926
+ success: false
927
+ };
928
+ }
929
+ }
930
+ /**
931
+ * Registers an agent with the guarded registry. Should be called by a registry.
932
+ * @param registryTopicId - The topic ID of the guarded registry.
933
+ * @param accountId - The account ID of the agent
934
+ * @param inboundTopicId - The topic ID of the inbound topic
935
+ * @param memo - The memo of the agent
936
+ * @param submitKey - The submit key of the agent
937
+ */
938
+ async registerAgent(registryTopicId, accountId, inboundTopicId, memo, submitKey) {
939
+ this.logger.info("Registering agent");
940
+ const payload = {
941
+ p: "hcs-10",
942
+ op: "register",
943
+ account_id: accountId,
944
+ inbound_topic_id: inboundTopicId,
945
+ m: memo
946
+ };
947
+ await this.submitPayload(registryTopicId, payload, submitKey);
948
+ }
949
+ async getInboundTopicType(topicId) {
950
+ try {
951
+ const topicInfo = await this.mirrorNode.getTopicInfo(topicId);
952
+ if (!topicInfo) {
953
+ throw new Error("Topic does not exist");
954
+ }
955
+ const hasSubmitKey = topicInfo.submit_key && topicInfo.submit_key.key;
956
+ if (!hasSubmitKey) {
957
+ return InboundTopicType.PUBLIC;
958
+ }
959
+ const hasFeeScheduleKey = topicInfo.fee_schedule_key && topicInfo.fee_schedule_key.key;
960
+ if (hasFeeScheduleKey && topicInfo.custom_fees) {
961
+ const customFees = topicInfo.custom_fees;
962
+ if (customFees && customFees.fixed_fees && customFees.fixed_fees.length > 0) {
963
+ this.logger.info(
964
+ `Topic ${topicId} is fee-based with ${customFees.fixed_fees.length} custom fees`
965
+ );
966
+ return InboundTopicType.FEE_BASED;
967
+ }
968
+ }
969
+ return InboundTopicType.CONTROLLED;
970
+ } catch (error) {
971
+ this.logger.error(`Error determining topic type: ${error.message}`);
972
+ throw new Error(`Failed to determine topic type: ${error.message}`);
973
+ }
974
+ }
699
975
  getNetwork() {
700
976
  return this.network;
701
977
  }