@hashgraphonline/standards-sdk 0.0.121 → 0.0.123

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 (108) hide show
  1. package/dist/cjs/hcs-10/sdk.d.ts +47 -3
  2. package/dist/cjs/hcs-10/sdk.d.ts.map +1 -1
  3. package/dist/cjs/hcs-10/types.d.ts +17 -0
  4. package/dist/cjs/hcs-10/types.d.ts.map +1 -1
  5. package/dist/cjs/hcs-11/client.d.ts +18 -1
  6. package/dist/cjs/hcs-11/client.d.ts.map +1 -1
  7. package/dist/cjs/hcs-11/index.d.ts +1 -0
  8. package/dist/cjs/hcs-11/index.d.ts.map +1 -1
  9. package/dist/cjs/hcs-11/mcp-server-builder.d.ts +122 -0
  10. package/dist/cjs/hcs-11/mcp-server-builder.d.ts.map +1 -0
  11. package/dist/cjs/hcs-11/types.d.ts +81 -18
  12. package/dist/cjs/hcs-11/types.d.ts.map +1 -1
  13. package/dist/cjs/{index-CHar8dVv-B2IK-7-2.cjs → index-CHar8dVv-ZN8JTP7M.cjs} +2 -2
  14. package/dist/cjs/{index-CHar8dVv-B2IK-7-2.cjs.map → index-CHar8dVv-ZN8JTP7M.cjs.map} +1 -1
  15. package/dist/cjs/index-Clbwco-g.cjs +11 -0
  16. package/dist/cjs/index-Clbwco-g.cjs.map +1 -0
  17. package/dist/cjs/services/mirror-node.d.ts.map +1 -1
  18. package/dist/cjs/standards-sdk.cjs +1 -1
  19. package/dist/es/hcs-10/sdk.d.ts +47 -3
  20. package/dist/es/hcs-10/sdk.d.ts.map +1 -1
  21. package/dist/es/hcs-10/types.d.ts +17 -0
  22. package/dist/es/hcs-10/types.d.ts.map +1 -1
  23. package/dist/es/hcs-11/client.d.ts +18 -1
  24. package/dist/es/hcs-11/client.d.ts.map +1 -1
  25. package/dist/es/hcs-11/index.d.ts +1 -0
  26. package/dist/es/hcs-11/index.d.ts.map +1 -1
  27. package/dist/es/hcs-11/mcp-server-builder.d.ts +122 -0
  28. package/dist/es/hcs-11/mcp-server-builder.d.ts.map +1 -0
  29. package/dist/es/hcs-11/types.d.ts +81 -18
  30. package/dist/es/hcs-11/types.d.ts.map +1 -1
  31. package/dist/es/services/mirror-node.d.ts.map +1 -1
  32. package/dist/es/standards-sdk.es.js +17 -12
  33. package/dist/es/standards-sdk.es.js.map +1 -1
  34. package/dist/es/standards-sdk.es10.js +1 -1
  35. package/dist/es/standards-sdk.es11.js +2 -2
  36. package/dist/es/standards-sdk.es12.js +1 -1
  37. package/dist/es/standards-sdk.es13.js +236 -639
  38. package/dist/es/standards-sdk.es13.js.map +1 -1
  39. package/dist/es/standards-sdk.es14.js +770 -85
  40. package/dist/es/standards-sdk.es14.js.map +1 -1
  41. package/dist/es/standards-sdk.es15.js +132 -68
  42. package/dist/es/standards-sdk.es15.js.map +1 -1
  43. package/dist/es/standards-sdk.es16.js +66 -19
  44. package/dist/es/standards-sdk.es16.js.map +1 -1
  45. package/dist/es/standards-sdk.es17.js +18 -156
  46. package/dist/es/standards-sdk.es17.js.map +1 -1
  47. package/dist/es/standards-sdk.es18.js +150 -146
  48. package/dist/es/standards-sdk.es18.js.map +1 -1
  49. package/dist/es/standards-sdk.es19.js +134 -561
  50. package/dist/es/standards-sdk.es19.js.map +1 -1
  51. package/dist/es/standards-sdk.es2.js +1 -1
  52. package/dist/es/standards-sdk.es20.js +577 -24
  53. package/dist/es/standards-sdk.es20.js.map +1 -1
  54. package/dist/es/standards-sdk.es21.js +23 -400
  55. package/dist/es/standards-sdk.es21.js.map +1 -1
  56. package/dist/es/standards-sdk.es22.js +381 -1507
  57. package/dist/es/standards-sdk.es22.js.map +1 -1
  58. package/dist/es/standards-sdk.es23.js +1511 -133
  59. package/dist/es/standards-sdk.es23.js.map +1 -1
  60. package/dist/es/standards-sdk.es24.js +155 -7
  61. package/dist/es/standards-sdk.es24.js.map +1 -1
  62. package/dist/es/standards-sdk.es25.js +7 -7190
  63. package/dist/es/standards-sdk.es25.js.map +1 -1
  64. package/dist/es/standards-sdk.es26.js +7190 -2
  65. package/dist/es/standards-sdk.es26.js.map +1 -1
  66. package/dist/es/standards-sdk.es27.js +2 -501
  67. package/dist/es/standards-sdk.es27.js.map +1 -1
  68. package/dist/es/standards-sdk.es28.js +457 -65
  69. package/dist/es/standards-sdk.es28.js.map +1 -1
  70. package/dist/es/standards-sdk.es29.js +80 -37
  71. package/dist/es/standards-sdk.es29.js.map +1 -1
  72. package/dist/es/standards-sdk.es3.js +1 -1
  73. package/dist/es/standards-sdk.es30.js +33 -223
  74. package/dist/es/standards-sdk.es30.js.map +1 -1
  75. package/dist/es/standards-sdk.es31.js +184 -101
  76. package/dist/es/standards-sdk.es31.js.map +1 -1
  77. package/dist/es/standards-sdk.es32.js +167 -5
  78. package/dist/es/standards-sdk.es32.js.map +1 -1
  79. package/dist/es/standards-sdk.es33.js +8 -7132
  80. package/dist/es/standards-sdk.es33.js.map +1 -1
  81. package/dist/es/standards-sdk.es34.js +7134 -41
  82. package/dist/es/standards-sdk.es34.js.map +1 -1
  83. package/dist/es/standards-sdk.es35.js +45 -0
  84. package/dist/es/standards-sdk.es35.js.map +1 -0
  85. package/dist/es/standards-sdk.es4.js +1 -1
  86. package/dist/es/standards-sdk.es5.js +4 -4
  87. package/dist/es/standards-sdk.es7.js +573 -62
  88. package/dist/es/standards-sdk.es7.js.map +1 -1
  89. package/dist/es/standards-sdk.es8.js +5 -5
  90. package/dist/es/standards-sdk.es9.js +2 -2
  91. package/dist/umd/hcs-10/sdk.d.ts +47 -3
  92. package/dist/umd/hcs-10/sdk.d.ts.map +1 -1
  93. package/dist/umd/hcs-10/types.d.ts +17 -0
  94. package/dist/umd/hcs-10/types.d.ts.map +1 -1
  95. package/dist/umd/hcs-11/client.d.ts +18 -1
  96. package/dist/umd/hcs-11/client.d.ts.map +1 -1
  97. package/dist/umd/hcs-11/index.d.ts +1 -0
  98. package/dist/umd/hcs-11/index.d.ts.map +1 -1
  99. package/dist/umd/hcs-11/mcp-server-builder.d.ts +122 -0
  100. package/dist/umd/hcs-11/mcp-server-builder.d.ts.map +1 -0
  101. package/dist/umd/hcs-11/types.d.ts +81 -18
  102. package/dist/umd/hcs-11/types.d.ts.map +1 -1
  103. package/dist/umd/services/mirror-node.d.ts.map +1 -1
  104. package/dist/umd/standards-sdk.umd.js +19 -19
  105. package/dist/umd/standards-sdk.umd.js.map +1 -1
  106. package/package.json +1 -1
  107. package/dist/cjs/index-CHS2J8pS.cjs +0 -11
  108. package/dist/cjs/index-CHS2J8pS.cjs.map +0 -1
@@ -1,88 +1,773 @@
1
- var ProfileType = /* @__PURE__ */ ((ProfileType2) => {
2
- ProfileType2[ProfileType2["PERSONAL"] = 0] = "PERSONAL";
3
- ProfileType2[ProfileType2["AI_AGENT"] = 1] = "AI_AGENT";
4
- return ProfileType2;
5
- })(ProfileType || {});
6
- var AIAgentType = /* @__PURE__ */ ((AIAgentType2) => {
7
- AIAgentType2[AIAgentType2["MANUAL"] = 0] = "MANUAL";
8
- AIAgentType2[AIAgentType2["AUTONOMOUS"] = 1] = "AUTONOMOUS";
9
- return AIAgentType2;
10
- })(AIAgentType || {});
11
- var EndpointType = /* @__PURE__ */ ((EndpointType2) => {
12
- EndpointType2[EndpointType2["REST"] = 0] = "REST";
13
- EndpointType2[EndpointType2["WEBSOCKET"] = 1] = "WEBSOCKET";
14
- EndpointType2[EndpointType2["GRPC"] = 2] = "GRPC";
15
- return EndpointType2;
16
- })(EndpointType || {});
17
- var AIAgentCapability = /* @__PURE__ */ ((AIAgentCapability2) => {
18
- AIAgentCapability2[AIAgentCapability2["TEXT_GENERATION"] = 0] = "TEXT_GENERATION";
19
- AIAgentCapability2[AIAgentCapability2["IMAGE_GENERATION"] = 1] = "IMAGE_GENERATION";
20
- AIAgentCapability2[AIAgentCapability2["AUDIO_GENERATION"] = 2] = "AUDIO_GENERATION";
21
- AIAgentCapability2[AIAgentCapability2["VIDEO_GENERATION"] = 3] = "VIDEO_GENERATION";
22
- AIAgentCapability2[AIAgentCapability2["CODE_GENERATION"] = 4] = "CODE_GENERATION";
23
- AIAgentCapability2[AIAgentCapability2["LANGUAGE_TRANSLATION"] = 5] = "LANGUAGE_TRANSLATION";
24
- AIAgentCapability2[AIAgentCapability2["SUMMARIZATION_EXTRACTION"] = 6] = "SUMMARIZATION_EXTRACTION";
25
- AIAgentCapability2[AIAgentCapability2["KNOWLEDGE_RETRIEVAL"] = 7] = "KNOWLEDGE_RETRIEVAL";
26
- AIAgentCapability2[AIAgentCapability2["DATA_INTEGRATION"] = 8] = "DATA_INTEGRATION";
27
- AIAgentCapability2[AIAgentCapability2["MARKET_INTELLIGENCE"] = 9] = "MARKET_INTELLIGENCE";
28
- AIAgentCapability2[AIAgentCapability2["TRANSACTION_ANALYTICS"] = 10] = "TRANSACTION_ANALYTICS";
29
- AIAgentCapability2[AIAgentCapability2["SMART_CONTRACT_AUDIT"] = 11] = "SMART_CONTRACT_AUDIT";
30
- AIAgentCapability2[AIAgentCapability2["GOVERNANCE_FACILITATION"] = 12] = "GOVERNANCE_FACILITATION";
31
- AIAgentCapability2[AIAgentCapability2["SECURITY_MONITORING"] = 13] = "SECURITY_MONITORING";
32
- AIAgentCapability2[AIAgentCapability2["COMPLIANCE_ANALYSIS"] = 14] = "COMPLIANCE_ANALYSIS";
33
- AIAgentCapability2[AIAgentCapability2["FRAUD_DETECTION"] = 15] = "FRAUD_DETECTION";
34
- AIAgentCapability2[AIAgentCapability2["MULTI_AGENT_COORDINATION"] = 16] = "MULTI_AGENT_COORDINATION";
35
- AIAgentCapability2[AIAgentCapability2["API_INTEGRATION"] = 17] = "API_INTEGRATION";
36
- AIAgentCapability2[AIAgentCapability2["WORKFLOW_AUTOMATION"] = 18] = "WORKFLOW_AUTOMATION";
37
- return AIAgentCapability2;
38
- })(AIAgentCapability || {});
39
- var InboundTopicType = /* @__PURE__ */ ((InboundTopicType2) => {
40
- InboundTopicType2["PUBLIC"] = "PUBLIC";
41
- InboundTopicType2["CONTROLLED"] = "CONTROLLED";
42
- InboundTopicType2["FEE_BASED"] = "FEE_BASED";
43
- return InboundTopicType2;
44
- })(InboundTopicType || {});
45
- const SUPPORTED_SOCIAL_PLATFORMS = [
46
- "twitter",
47
- "github",
48
- "discord",
49
- "telegram",
50
- "linkedin",
51
- "youtube",
52
- "website",
53
- "x"
54
- ];
55
- const capabilityNameToCapabilityMap = {
56
- text_generation: 0,
57
- image_generation: 1,
58
- audio_generation: 2,
59
- video_generation: 3,
60
- code_generation: 4,
61
- language_translation: 5,
62
- summarization: 6,
63
- extraction: 6,
64
- knowledge_retrieval: 7,
65
- data_integration: 8,
66
- data_visualization: 8,
67
- market_intelligence: 9,
68
- transaction_analytics: 10,
69
- smart_contract_audit: 11,
70
- governance: 12,
71
- security_monitoring: 13,
72
- compliance_analysis: 14,
73
- fraud_detection: 15,
74
- multi_agent: 16,
75
- api_integration: 17,
76
- workflow_automation: 18
77
- /* WORKFLOW_AUTOMATION */
78
- };
1
+ import { Client, PrivateKey, Status, AccountUpdateTransaction } from "@hashgraph/sdk";
2
+ import { inscribeWithSigner, inscribe } from "./standards-sdk.es22.js";
3
+ import { Logger } from "./standards-sdk.es16.js";
4
+ import { HederaMirrorNode } from "./standards-sdk.es23.js";
5
+ import { ProgressReporter } from "./standards-sdk.es18.js";
6
+ import "axios";
7
+ import "@hashgraph/proto";
8
+ import "buffer";
9
+ import "ethers";
10
+ import { detectKeyTypeFromString } from "./standards-sdk.es21.js";
11
+ import * as mime from "mime-types";
12
+ import { z } from "zod";
13
+ import { AIAgentCapability, AIAgentType, VerificationType, MCPServerCapability, ProfileType, capabilityNameToCapabilityMap } from "./standards-sdk.es15.js";
14
+ const SocialLinkSchema = z.object({
15
+ platform: z.string().min(1),
16
+ handle: z.string().min(1)
17
+ });
18
+ const AIAgentDetailsSchema = z.object({
19
+ type: z.nativeEnum(AIAgentType),
20
+ capabilities: z.array(z.nativeEnum(AIAgentCapability)).min(1),
21
+ model: z.string().min(1),
22
+ creator: z.string().optional()
23
+ });
24
+ const MCPServerConnectionInfoSchema = z.object({
25
+ url: z.string().min(1),
26
+ transport: z.enum(["stdio", "sse"])
27
+ });
28
+ const MCPServerVerificationSchema = z.object({
29
+ type: z.nativeEnum(VerificationType),
30
+ value: z.string(),
31
+ dns_field: z.string().optional(),
32
+ challenge_path: z.string().optional()
33
+ });
34
+ const MCPServerHostSchema = z.object({
35
+ minVersion: z.string().optional()
36
+ });
37
+ const MCPServerResourceSchema = z.object({
38
+ name: z.string().min(1),
39
+ description: z.string().min(1)
40
+ });
41
+ const MCPServerToolSchema = z.object({
42
+ name: z.string().min(1),
43
+ description: z.string().min(1)
44
+ });
45
+ const MCPServerDetailsSchema = z.object({
46
+ version: z.string().min(1),
47
+ connectionInfo: MCPServerConnectionInfoSchema,
48
+ services: z.array(z.nativeEnum(MCPServerCapability)).min(1),
49
+ description: z.string().min(1),
50
+ verification: MCPServerVerificationSchema.optional(),
51
+ host: MCPServerHostSchema.optional(),
52
+ capabilities: z.array(z.string()).optional(),
53
+ resources: z.array(MCPServerResourceSchema).optional(),
54
+ tools: z.array(MCPServerToolSchema).optional(),
55
+ maintainer: z.string().optional(),
56
+ repository: z.string().optional(),
57
+ docs: z.string().optional()
58
+ });
59
+ const BaseProfileSchema = z.object({
60
+ version: z.string().min(1),
61
+ type: z.nativeEnum(ProfileType),
62
+ display_name: z.string().min(1),
63
+ alias: z.string().optional(),
64
+ bio: z.string().optional(),
65
+ socials: z.array(SocialLinkSchema).optional(),
66
+ profileImage: z.string().optional(),
67
+ properties: z.record(z.any()).optional(),
68
+ inboundTopicId: z.string().optional(),
69
+ outboundTopicId: z.string().optional()
70
+ });
71
+ const PersonalProfileSchema = BaseProfileSchema.extend({
72
+ type: z.literal(ProfileType.PERSONAL),
73
+ language: z.string().optional(),
74
+ timezone: z.string().optional()
75
+ });
76
+ const AIAgentProfileSchema = BaseProfileSchema.extend({
77
+ type: z.literal(ProfileType.AI_AGENT),
78
+ aiAgent: AIAgentDetailsSchema
79
+ });
80
+ const MCPServerProfileSchema = BaseProfileSchema.extend({
81
+ type: z.literal(ProfileType.MCP_SERVER),
82
+ mcpServer: MCPServerDetailsSchema
83
+ });
84
+ const HCS11ProfileSchema = z.union([
85
+ PersonalProfileSchema,
86
+ AIAgentProfileSchema,
87
+ MCPServerProfileSchema
88
+ ]);
89
+ class HCS11Client {
90
+ constructor(config) {
91
+ this.client = config.network === "mainnet" ? Client.forMainnet() : Client.forTestnet();
92
+ this.auth = config.auth;
93
+ this.network = config.network;
94
+ this.operatorId = config.auth.operatorId;
95
+ this.logger = Logger.getInstance({
96
+ level: config.logLevel || "info",
97
+ module: "HCS-11",
98
+ silent: config.silent
99
+ });
100
+ this.mirrorNode = new HederaMirrorNode(
101
+ this.network,
102
+ this.logger
103
+ );
104
+ if (this.auth.privateKey) {
105
+ if (config.keyType) {
106
+ this.keyType = config.keyType;
107
+ this.initializeOperatorWithKeyType();
108
+ } else {
109
+ try {
110
+ const keyDetection = detectKeyTypeFromString(this.auth.privateKey);
111
+ this.keyType = keyDetection.detectedType;
112
+ this.client.setOperator(this.operatorId, keyDetection.privateKey);
113
+ } catch (error) {
114
+ this.logger.warn(
115
+ "Failed to detect key type from private key format, will query mirror node"
116
+ );
117
+ this.keyType = "ed25519";
118
+ }
119
+ this.initializeOperator();
120
+ }
121
+ }
122
+ }
123
+ getClient() {
124
+ return this.client;
125
+ }
126
+ getOperatorId() {
127
+ return this.auth.operatorId;
128
+ }
129
+ async initializeOperator() {
130
+ const account = await this.mirrorNode.requestAccount(this.operatorId);
131
+ const keyType = account?.key?._type;
132
+ if (keyType && keyType.includes("ECDSA")) {
133
+ this.keyType = "ecdsa";
134
+ } else if (keyType && keyType.includes("ED25519")) {
135
+ this.keyType = "ed25519";
136
+ } else {
137
+ this.keyType = "ed25519";
138
+ }
139
+ this.initializeOperatorWithKeyType();
140
+ }
141
+ initializeOperatorWithKeyType() {
142
+ if (!this.auth.privateKey) {
143
+ return;
144
+ }
145
+ const PK = this.keyType === "ecdsa" ? PrivateKey.fromStringECDSA(this.auth.privateKey) : PrivateKey.fromStringED25519(this.auth.privateKey);
146
+ this.client.setOperator(this.operatorId, PK);
147
+ }
148
+ createPersonalProfile(displayName, options) {
149
+ return {
150
+ version: "1.0",
151
+ type: ProfileType.PERSONAL,
152
+ display_name: displayName,
153
+ alias: options?.alias,
154
+ bio: options?.bio,
155
+ socials: options?.socials,
156
+ profileImage: options?.profileImage,
157
+ properties: options?.properties,
158
+ inboundTopicId: options?.inboundTopicId,
159
+ outboundTopicId: options?.outboundTopicId
160
+ };
161
+ }
162
+ createAIAgentProfile(displayName, agentType, capabilities, model, options) {
163
+ const validation = this.validateProfile({
164
+ version: "1.0",
165
+ type: ProfileType.AI_AGENT,
166
+ display_name: displayName,
167
+ alias: options?.alias,
168
+ bio: options?.bio,
169
+ socials: options?.socials,
170
+ profileImage: options?.profileImage,
171
+ properties: options?.properties,
172
+ inboundTopicId: options?.inboundTopicId,
173
+ outboundTopicId: options?.outboundTopicId,
174
+ aiAgent: {
175
+ type: agentType,
176
+ capabilities,
177
+ model,
178
+ creator: options?.creator
179
+ }
180
+ });
181
+ if (!validation.valid) {
182
+ throw new Error(
183
+ `Invalid AI Agent Profile: ${validation.errors.join(", ")}`
184
+ );
185
+ }
186
+ return {
187
+ version: "1.0",
188
+ type: ProfileType.AI_AGENT,
189
+ display_name: displayName,
190
+ alias: options?.alias,
191
+ bio: options?.bio,
192
+ socials: options?.socials,
193
+ profileImage: options?.profileImage,
194
+ properties: options?.properties,
195
+ inboundTopicId: options?.inboundTopicId,
196
+ outboundTopicId: options?.outboundTopicId,
197
+ aiAgent: {
198
+ type: agentType,
199
+ capabilities,
200
+ model,
201
+ creator: options?.creator
202
+ }
203
+ };
204
+ }
205
+ /**
206
+ * Creates an MCP server profile.
207
+ *
208
+ * @param displayName - The display name for the MCP server
209
+ * @param serverDetails - The MCP server details
210
+ * @param options - Additional profile options
211
+ * @returns An MCPServerProfile object
212
+ */
213
+ createMCPServerProfile(displayName, serverDetails, options) {
214
+ const validation = this.validateProfile({
215
+ version: "1.0",
216
+ type: ProfileType.MCP_SERVER,
217
+ display_name: displayName,
218
+ alias: options?.alias,
219
+ bio: options?.bio,
220
+ socials: options?.socials,
221
+ profileImage: options?.profileImage,
222
+ properties: options?.properties,
223
+ inboundTopicId: options?.inboundTopicId,
224
+ outboundTopicId: options?.outboundTopicId,
225
+ mcpServer: serverDetails
226
+ });
227
+ if (!validation.valid) {
228
+ throw new Error(
229
+ `Invalid MCP Server Profile: ${validation.errors.join(", ")}`
230
+ );
231
+ }
232
+ return {
233
+ version: "1.0",
234
+ type: ProfileType.MCP_SERVER,
235
+ display_name: displayName,
236
+ alias: options?.alias,
237
+ bio: options?.bio,
238
+ socials: options?.socials,
239
+ profileImage: options?.profileImage,
240
+ properties: options?.properties,
241
+ inboundTopicId: options?.inboundTopicId,
242
+ outboundTopicId: options?.outboundTopicId,
243
+ mcpServer: serverDetails
244
+ };
245
+ }
246
+ validateProfile(profile) {
247
+ const result = HCS11ProfileSchema.safeParse(profile);
248
+ if (result.success) {
249
+ return { valid: true, errors: [] };
250
+ }
251
+ const formattedErrors = result.error.errors.map((err) => {
252
+ const path = err.path.join(".");
253
+ let message = err.message;
254
+ if (err.code === "invalid_type") {
255
+ message = `Expected ${err.expected}, got ${err.received}`;
256
+ } else if (err.code === "invalid_enum_value") {
257
+ const validOptions = err.options?.join(", ");
258
+ message = `Invalid value. Valid options are: ${validOptions}`;
259
+ } else if (err.code === "too_small" && err.type === "string") {
260
+ message = "Cannot be empty";
261
+ }
262
+ return `${path}: ${message}`;
263
+ });
264
+ return { valid: false, errors: formattedErrors };
265
+ }
266
+ profileToJSONString(profile) {
267
+ return JSON.stringify(profile);
268
+ }
269
+ parseProfileFromString(profileStr) {
270
+ try {
271
+ const parsedProfile = JSON.parse(profileStr);
272
+ const validation = this.validateProfile(parsedProfile);
273
+ if (!validation.valid) {
274
+ this.logger.error("Invalid profile format:", validation.errors);
275
+ return null;
276
+ }
277
+ return parsedProfile;
278
+ } catch (error) {
279
+ this.logger.error("Error parsing profile:");
280
+ return null;
281
+ }
282
+ }
283
+ setProfileForAccountMemo(topicId, topicStandard = 1) {
284
+ return `hcs-11:hcs://${topicStandard}/${topicId}`;
285
+ }
286
+ async executeTransaction(transaction) {
287
+ try {
288
+ if (this.auth.privateKey) {
289
+ const signedTx = await transaction.signWithOperator(this.client);
290
+ const response2 = await signedTx.execute(this.client);
291
+ const receipt2 = await response2.getReceipt(this.client);
292
+ if (receipt2.status.toString() !== Status.Success.toString()) {
293
+ return {
294
+ success: false,
295
+ error: `Transaction failed: ${receipt2.status.toString()}`
296
+ };
297
+ }
298
+ return {
299
+ success: true,
300
+ result: receipt2
301
+ };
302
+ }
303
+ if (!this.auth.signer) {
304
+ throw new Error("No valid authentication method provided");
305
+ }
306
+ const signer = this.auth.signer;
307
+ const frozenTransaction = await transaction.freezeWithSigner(signer);
308
+ const response = await frozenTransaction.executeWithSigner(signer);
309
+ const receipt = await response.getReceiptWithSigner(signer);
310
+ if (receipt.status.toString() !== Status.Success.toString()) {
311
+ return {
312
+ success: false,
313
+ error: `Transaction failed: ${receipt.status.toString()}: ${Status.Success.toString()}`
314
+ };
315
+ }
316
+ return {
317
+ success: true,
318
+ result: receipt
319
+ };
320
+ } catch (error) {
321
+ return {
322
+ success: false,
323
+ error: error instanceof Error ? error.message : "Unknown error during transaction execution"
324
+ };
325
+ }
326
+ }
327
+ async inscribeImage(buffer, fileName, options) {
328
+ try {
329
+ const progressCallback = options?.progressCallback;
330
+ const progressReporter = new ProgressReporter({
331
+ module: "HCS11-Image",
332
+ logger: this.logger,
333
+ callback: progressCallback
334
+ });
335
+ progressReporter.preparing("Preparing to inscribe image", 0);
336
+ const mimeType = mime.lookup(fileName) || "application/octet-stream";
337
+ const waitForConfirmation = options?.waitForConfirmation ?? true;
338
+ let inscriptionResponse;
339
+ if (this.auth.signer) {
340
+ if ("accountId" in this.auth.signer) {
341
+ progressReporter.preparing("Using signer for inscription", 10);
342
+ inscriptionResponse = await inscribeWithSigner(
343
+ {
344
+ type: "buffer",
345
+ buffer,
346
+ fileName,
347
+ mimeType
348
+ },
349
+ this.auth.signer,
350
+ {
351
+ network: this.network,
352
+ waitForConfirmation,
353
+ waitMaxAttempts: 150,
354
+ waitIntervalMs: 4e3,
355
+ logging: {
356
+ level: "debug"
357
+ },
358
+ progressCallback: (data) => {
359
+ const adjustedPercent = 10 + (data.progressPercent || 0) * 0.8;
360
+ progressReporter.report({
361
+ stage: data.stage,
362
+ message: data.message,
363
+ progressPercent: adjustedPercent,
364
+ details: data.details
365
+ });
366
+ }
367
+ }
368
+ );
369
+ } else {
370
+ progressReporter.failed(
371
+ "Signer must be a DAppSigner for inscription"
372
+ );
373
+ throw new Error("Signer must be a DAppSigner for inscription");
374
+ }
375
+ } else {
376
+ if (!this.auth.privateKey) {
377
+ progressReporter.failed("Private key is required for inscription");
378
+ this.logger.error("Private key is required for inscription");
379
+ throw new Error("Private key is required for inscription");
380
+ }
381
+ progressReporter.preparing("Using private key for inscription", 10);
382
+ inscriptionResponse = await inscribe(
383
+ {
384
+ type: "buffer",
385
+ buffer,
386
+ fileName,
387
+ mimeType
388
+ },
389
+ {
390
+ accountId: this.auth.operatorId,
391
+ privateKey: this.auth.privateKey,
392
+ network: this.network
393
+ },
394
+ {
395
+ waitForConfirmation,
396
+ waitMaxAttempts: 150,
397
+ waitIntervalMs: 2e3,
398
+ logging: {
399
+ level: "debug"
400
+ },
401
+ progressCallback: (data) => {
402
+ const adjustedPercent = 10 + (data.progressPercent || 0) * 0.8;
403
+ progressReporter.report({
404
+ stage: data.stage,
405
+ message: data.message,
406
+ progressPercent: adjustedPercent,
407
+ details: data.details
408
+ });
409
+ }
410
+ }
411
+ );
412
+ }
413
+ if (inscriptionResponse.confirmed) {
414
+ progressReporter.completed("Image inscription completed", {
415
+ topic_id: inscriptionResponse.inscription.topic_id
416
+ });
417
+ return {
418
+ imageTopicId: inscriptionResponse.inscription.topic_id || "",
419
+ transactionId: inscriptionResponse.result.jobId,
420
+ success: true
421
+ };
422
+ } else {
423
+ progressReporter.verifying("Waiting for inscription confirmation", 50, {
424
+ jobId: inscriptionResponse.result.jobId
425
+ });
426
+ return {
427
+ imageTopicId: "",
428
+ transactionId: inscriptionResponse.result.jobId,
429
+ success: false,
430
+ error: "Inscription not confirmed"
431
+ };
432
+ }
433
+ } catch (error) {
434
+ this.logger.error("Error inscribing image:", error);
435
+ return {
436
+ imageTopicId: "",
437
+ transactionId: "",
438
+ success: false,
439
+ error: error.message || "Error inscribing image"
440
+ };
441
+ }
442
+ }
443
+ async inscribeProfile(profile, options) {
444
+ this.logger.info("Inscribing HCS-11 profile");
445
+ const progressCallback = options?.progressCallback;
446
+ const progressReporter = new ProgressReporter({
447
+ module: "HCS11-Profile",
448
+ logger: this.logger,
449
+ callback: progressCallback
450
+ });
451
+ progressReporter.preparing("Validating profile data", 5);
452
+ const validation = this.validateProfile(profile);
453
+ if (!validation.valid) {
454
+ progressReporter.failed(
455
+ `Invalid profile: ${validation.errors.join(", ")}`
456
+ );
457
+ return {
458
+ profileTopicId: "",
459
+ transactionId: "",
460
+ success: false,
461
+ error: `Invalid profile: ${validation.errors.join(", ")}`
462
+ };
463
+ }
464
+ progressReporter.preparing("Formatting profile for inscription", 15);
465
+ const profileJson = this.profileToJSONString(profile);
466
+ const fileName = `profile-${profile.display_name.toLowerCase().replace(/\s+/g, "-")}.json`;
467
+ try {
468
+ const contentBuffer = Buffer.from(profileJson, "utf-8");
469
+ const contentType = "application/json";
470
+ progressReporter.preparing("Preparing profile for inscription", 20);
471
+ const input = {
472
+ type: "buffer",
473
+ buffer: contentBuffer,
474
+ fileName,
475
+ mimeType: contentType
476
+ };
477
+ const inscriptionOptions = {
478
+ waitForConfirmation: true,
479
+ mode: "file",
480
+ network: this.network,
481
+ waitMaxAttempts: 100,
482
+ waitIntervalMs: 2e3,
483
+ progressCallback: (data) => {
484
+ const adjustedPercent = 20 + Number(data?.progressPercent || 0) * 0.75;
485
+ progressReporter?.report({
486
+ stage: data.stage,
487
+ message: data.message,
488
+ progressPercent: adjustedPercent,
489
+ details: data.details
490
+ });
491
+ }
492
+ };
493
+ progressReporter.submitting("Submitting profile to Hedera network", 30);
494
+ const inscriptionResponse = this.auth.privateKey ? await inscribe(
495
+ input,
496
+ {
497
+ accountId: this.auth.operatorId,
498
+ privateKey: this.auth.privateKey,
499
+ network: this.network
500
+ },
501
+ inscriptionOptions
502
+ ) : await inscribeWithSigner(
503
+ input,
504
+ this.auth.signer,
505
+ inscriptionOptions
506
+ );
507
+ if (!inscriptionResponse.confirmed || !inscriptionResponse.inscription.topic_id) {
508
+ progressReporter.failed("Failed to inscribe profile content");
509
+ return {
510
+ profileTopicId: "",
511
+ transactionId: "",
512
+ success: false,
513
+ error: "Failed to inscribe profile content"
514
+ };
515
+ }
516
+ const topicId = inscriptionResponse.inscription.topic_id;
517
+ progressReporter.completed("Profile inscription completed", {
518
+ topicId,
519
+ transactionId: inscriptionResponse.result.transactionId
520
+ });
521
+ return {
522
+ profileTopicId: topicId,
523
+ transactionId: inscriptionResponse.result.transactionId,
524
+ success: true
525
+ };
526
+ } catch (error) {
527
+ progressReporter.failed(
528
+ `Error inscribing profile: ${error.message || "Unknown error"}`
529
+ );
530
+ return {
531
+ profileTopicId: "",
532
+ transactionId: "",
533
+ success: false,
534
+ error: error.message || "Unknown error during inscription"
535
+ };
536
+ }
537
+ }
538
+ async updateAccountMemoWithProfile(accountId, profileTopicId) {
539
+ try {
540
+ this.logger.info(
541
+ `Updating account memo for ${accountId} with profile ${profileTopicId}`
542
+ );
543
+ const memo = this.setProfileForAccountMemo(profileTopicId);
544
+ const transaction = new AccountUpdateTransaction().setAccountMemo(memo).setAccountId(accountId);
545
+ return this.executeTransaction(transaction);
546
+ } catch (error) {
547
+ this.logger.error(
548
+ `Error updating account memo: ${error instanceof Error ? error.message : "Unknown error"}`
549
+ );
550
+ return {
551
+ success: false,
552
+ error: error instanceof Error ? error.message : "Unknown error updating account memo"
553
+ };
554
+ }
555
+ }
556
+ /**
557
+ * Creates and inscribes a profile.
558
+ *
559
+ * @param profile - The profile to create and inscribe.
560
+ * @param updateAccountMemo - Whether to update the account memo with the profile.
561
+ * @param options - Optional configuration options.
562
+ * @returns A promise that resolves to the inscription result.
563
+ */
564
+ async createAndInscribeProfile(profile, updateAccountMemo = true, options) {
565
+ const progressCallback = options?.progressCallback;
566
+ const progressReporter = new ProgressReporter({
567
+ module: "HCS11-ProfileCreation",
568
+ logger: this.logger,
569
+ callback: progressCallback
570
+ });
571
+ progressReporter.preparing("Starting profile creation process", 0);
572
+ const inscriptionProgress = progressReporter.createSubProgress({
573
+ minPercent: 0,
574
+ maxPercent: 80,
575
+ logPrefix: "Inscription"
576
+ });
577
+ const inscriptionResult = await this.inscribeProfile(profile, {
578
+ ...options,
579
+ progressCallback: (data) => {
580
+ inscriptionProgress.report({
581
+ stage: data.stage,
582
+ message: data.message,
583
+ progressPercent: data.progressPercent,
584
+ details: data.details
585
+ });
586
+ }
587
+ });
588
+ if (!inscriptionResult?.success) {
589
+ progressReporter.failed("Profile inscription failed", {
590
+ error: inscriptionResult?.error
591
+ });
592
+ return inscriptionResult;
593
+ }
594
+ progressReporter.confirming("Profile inscribed, updating account memo", 85);
595
+ if (updateAccountMemo) {
596
+ const memoResult = await this.updateAccountMemoWithProfile(
597
+ this.auth.operatorId,
598
+ inscriptionResult.profileTopicId
599
+ );
600
+ if (!memoResult.success) {
601
+ progressReporter.failed("Failed to update account memo", {
602
+ error: memoResult?.error
603
+ });
604
+ return {
605
+ ...inscriptionResult,
606
+ success: false,
607
+ error: memoResult?.error
608
+ };
609
+ }
610
+ }
611
+ progressReporter.completed("Profile creation completed successfully", {
612
+ profileTopicId: inscriptionResult.profileTopicId,
613
+ transactionId: inscriptionResult.transactionId
614
+ });
615
+ return inscriptionResult;
616
+ }
617
+ /**
618
+ * Gets the capabilities from the capability names.
619
+ *
620
+ * @param capabilityNames - The capability names to get the capabilities for.
621
+ * @returns The capabilities.
622
+ */
623
+ async getCapabilitiesFromTags(capabilityNames) {
624
+ const capabilities = [];
625
+ if (capabilityNames.length === 0) {
626
+ return [AIAgentCapability.TEXT_GENERATION];
627
+ }
628
+ for (const capabilityName of capabilityNames) {
629
+ const capability = capabilityNameToCapabilityMap[capabilityName.toLowerCase()];
630
+ if (capability !== void 0 && !capabilities.includes(capability)) {
631
+ capabilities.push(capability);
632
+ }
633
+ }
634
+ if (capabilities.length === 0) {
635
+ capabilities.push(AIAgentCapability.TEXT_GENERATION);
636
+ }
637
+ return capabilities;
638
+ }
639
+ /**
640
+ * Gets the agent type from the metadata.
641
+ *
642
+ * @param metadata - The metadata of the agent.
643
+ * @returns The agent type.
644
+ */
645
+ getAgentTypeFromMetadata(metadata) {
646
+ if (metadata.type === "autonomous") {
647
+ return AIAgentType.AUTONOMOUS;
648
+ } else {
649
+ return AIAgentType.MANUAL;
650
+ }
651
+ }
652
+ /**
653
+ * Fetches a profile from the account memo.
654
+ *
655
+ * @param accountId - The account ID of the agent to fetch the profile for.
656
+ * @param network - The network to use for the fetch.
657
+ * @returns A promise that resolves to the profile.
658
+ */
659
+ async fetchProfileByAccountId(accountId, network) {
660
+ try {
661
+ this.logger.info(
662
+ `Fetching profile for account ${accountId.toString()} on ${this.network}`
663
+ );
664
+ const memo = await this.mirrorNode.getAccountMemo(accountId.toString());
665
+ this.logger.info(`Got account memo: ${memo}`);
666
+ if (!memo?.startsWith("hcs-11:")) {
667
+ return {
668
+ success: false,
669
+ error: `Account ${accountId.toString()} does not have a valid HCS-11 memo`
670
+ };
671
+ }
672
+ this.logger.info(`Found HCS-11 memo: ${memo}`);
673
+ const protocolReference = memo.substring(7);
674
+ if (protocolReference?.startsWith("hcs://")) {
675
+ const hcsFormat = protocolReference.match(/hcs:\/\/(\d+)\/(.+)/);
676
+ if (!hcsFormat) {
677
+ return {
678
+ success: false,
679
+ error: `Invalid HCS protocol reference format: ${protocolReference}`
680
+ };
681
+ }
682
+ const [_, protocolId, profileTopicId] = hcsFormat;
683
+ const networkParam = network || this.network || "mainnet";
684
+ this.logger.info(
685
+ `Retrieving profile from Kiloscribe CDN: ${profileTopicId}`
686
+ );
687
+ const cdnUrl = `https://kiloscribe.com/api/inscription-cdn/${profileTopicId}?network=${networkParam}`;
688
+ try {
689
+ const response = await fetch(cdnUrl);
690
+ if (!response.ok) {
691
+ return {
692
+ success: false,
693
+ error: `Failed to fetch profile from Kiloscribe CDN: ${response.statusText}`
694
+ };
695
+ }
696
+ const profileData = await response.json();
697
+ if (!profileData) {
698
+ return {
699
+ success: false,
700
+ error: `No profile data found for topic ${profileTopicId}`
701
+ };
702
+ }
703
+ return {
704
+ success: true,
705
+ profile: profileData,
706
+ topicInfo: {
707
+ inboundTopic: profileData.inboundTopicId,
708
+ outboundTopic: profileData.outboundTopicId,
709
+ profileTopicId
710
+ }
711
+ };
712
+ } catch (cdnError) {
713
+ this.logger.error(
714
+ `Error retrieving from Kiloscribe CDN: ${cdnError.message}`
715
+ );
716
+ return {
717
+ success: false,
718
+ error: `Error retrieving from Kiloscribe CDN: ${cdnError.message}`
719
+ };
720
+ }
721
+ } else if (protocolReference.startsWith("ipfs://")) {
722
+ this.logger.warn("IPFS protocol references are not fully supported");
723
+ const response = await fetch(
724
+ `https://ipfs.io/ipfs/${protocolReference.replace("ipfs://", "")}`
725
+ );
726
+ const profileData = await response.json();
727
+ return {
728
+ success: true,
729
+ profile: profileData,
730
+ topicInfo: {
731
+ inboundTopic: profileData.inboundTopicId,
732
+ outboundTopic: profileData.outboundTopicId,
733
+ profileTopicId: profileData.profileTopicId
734
+ }
735
+ };
736
+ } else if (protocolReference.startsWith("ar://")) {
737
+ const arTxId = protocolReference.replace("ar://", "");
738
+ const response = await fetch(`https://arweave.net/${arTxId}`);
739
+ if (!response.ok) {
740
+ return {
741
+ success: false,
742
+ error: `Failed to fetch profile from Arweave ${arTxId}: ${response.statusText}`
743
+ };
744
+ }
745
+ const profileData = await response.json();
746
+ return {
747
+ success: true,
748
+ profile: profileData,
749
+ topicInfo: {
750
+ inboundTopic: profileData.inboundTopicId,
751
+ outboundTopic: profileData.outboundTopicId,
752
+ profileTopicId: profileData.profileTopicId
753
+ }
754
+ };
755
+ } else {
756
+ return {
757
+ success: false,
758
+ error: `Invalid protocol reference format: ${protocolReference}`
759
+ };
760
+ }
761
+ } catch (error) {
762
+ this.logger.error(`Error fetching profile: ${error.message}`);
763
+ return {
764
+ success: false,
765
+ error: `Error fetching profile: ${error.message}`
766
+ };
767
+ }
768
+ }
769
+ }
79
770
  export {
80
- AIAgentCapability,
81
- AIAgentType,
82
- EndpointType,
83
- InboundTopicType,
84
- ProfileType,
85
- SUPPORTED_SOCIAL_PLATFORMS,
86
- capabilityNameToCapabilityMap
771
+ HCS11Client
87
772
  };
88
773
  //# sourceMappingURL=standards-sdk.es14.js.map