@hashgraphonline/standards-sdk 0.0.31 → 0.0.33
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.
- package/dist/es/hcs-10/base-client.d.ts +7 -1
- package/dist/es/index.d.ts +2 -0
- package/dist/es/services/mirror-node.d.ts +1 -0
- package/dist/es/standards-sdk.es.js +406 -293
- package/dist/es/standards-sdk.es.js.map +1 -1
- package/dist/umd/hcs-10/base-client.d.ts +7 -1
- package/dist/umd/index.d.ts +2 -0
- package/dist/umd/services/mirror-node.d.ts +1 -0
- package/dist/umd/standards-sdk.umd.js +6 -6
- package/dist/umd/standards-sdk.umd.js.map +1 -1
- package/package.json +9 -1
|
@@ -249,7 +249,7 @@ class HCS {
|
|
|
249
249
|
async loadScript(scriptElement) {
|
|
250
250
|
const src = scriptElement.getAttribute("data-src");
|
|
251
251
|
const scriptId = scriptElement.getAttribute("data-script-id");
|
|
252
|
-
const topicId = src
|
|
252
|
+
const topicId = src?.split("/").pop();
|
|
253
253
|
const type = scriptElement.getAttribute("type");
|
|
254
254
|
const isRequired = scriptElement.hasAttribute("data-required");
|
|
255
255
|
const isModule = scriptElement.getAttribute("type") === "module";
|
|
@@ -330,7 +330,7 @@ class HCS {
|
|
|
330
330
|
async loadStylesheet(linkElement) {
|
|
331
331
|
const src = linkElement.getAttribute("data-src");
|
|
332
332
|
const stylesheetId = linkElement.getAttribute("data-script-id");
|
|
333
|
-
const topicId = src
|
|
333
|
+
const topicId = src?.split("/").pop();
|
|
334
334
|
const isRequired = linkElement.hasAttribute("data-required");
|
|
335
335
|
if (this.isDuplicate(topicId || "")) {
|
|
336
336
|
return;
|
|
@@ -357,7 +357,7 @@ class HCS {
|
|
|
357
357
|
}
|
|
358
358
|
async loadImage(imageElement) {
|
|
359
359
|
const src = imageElement.getAttribute("data-src");
|
|
360
|
-
const topicId = src
|
|
360
|
+
const topicId = src?.split("/").pop();
|
|
361
361
|
this.log("Loading image: " + topicId);
|
|
362
362
|
this.updateLoadingStatus("Image: " + topicId, "loaded");
|
|
363
363
|
try {
|
|
@@ -376,7 +376,7 @@ class HCS {
|
|
|
376
376
|
}
|
|
377
377
|
async loadMedia(mediaElement, mediaType) {
|
|
378
378
|
const src = mediaElement.getAttribute("data-src");
|
|
379
|
-
const topicId = src
|
|
379
|
+
const topicId = src?.split("/").pop();
|
|
380
380
|
this.log("Loading " + mediaType + ": " + topicId);
|
|
381
381
|
this.updateLoadingStatus(mediaType + ": " + topicId, "loading");
|
|
382
382
|
try {
|
|
@@ -418,10 +418,9 @@ class HCS {
|
|
|
418
418
|
return this.modelViewerLoading;
|
|
419
419
|
}
|
|
420
420
|
async loadGLB(glbElement) {
|
|
421
|
-
var _a;
|
|
422
421
|
await this.loadModelViewer();
|
|
423
422
|
const src = glbElement.getAttribute("data-src");
|
|
424
|
-
const topicId = src
|
|
423
|
+
const topicId = src?.split("/").pop();
|
|
425
424
|
this.log("Loading GLB: " + topicId);
|
|
426
425
|
this.updateLoadingStatus("GLB: " + topicId, "loading");
|
|
427
426
|
try {
|
|
@@ -436,7 +435,7 @@ class HCS {
|
|
|
436
435
|
modelViewer.setAttribute("camera-controls", "");
|
|
437
436
|
modelViewer.setAttribute("auto-rotate", "");
|
|
438
437
|
modelViewer.setAttribute("ar", "");
|
|
439
|
-
|
|
438
|
+
glbElement.parentNode?.replaceChild(modelViewer, glbElement);
|
|
440
439
|
} else {
|
|
441
440
|
modelViewer = glbElement;
|
|
442
441
|
}
|
|
@@ -510,7 +509,6 @@ class HCS {
|
|
|
510
509
|
return newContent;
|
|
511
510
|
}
|
|
512
511
|
async processInlineStyles() {
|
|
513
|
-
var _a;
|
|
514
512
|
const elementsWithStyle = document.querySelectorAll('[style*="hcs://"]');
|
|
515
513
|
this.log(
|
|
516
514
|
"Found " + elementsWithStyle.length + " elements with HCS style references"
|
|
@@ -528,7 +526,7 @@ class HCS {
|
|
|
528
526
|
}
|
|
529
527
|
const styleTags = document.querySelectorAll("style");
|
|
530
528
|
for (const styleTag of Array.from(styleTags)) {
|
|
531
|
-
if (
|
|
529
|
+
if (styleTag.textContent?.includes("hcs://")) {
|
|
532
530
|
const newContent = await this.replaceHCSInStyle(styleTag.textContent);
|
|
533
531
|
if (styleTag.textContent !== newContent) {
|
|
534
532
|
styleTag.textContent = newContent;
|
|
@@ -585,18 +583,16 @@ class HCS {
|
|
|
585
583
|
await Promise.all(loadPromises);
|
|
586
584
|
const observer = new MutationObserver((mutations) => {
|
|
587
585
|
mutations.forEach((mutation) => {
|
|
588
|
-
var _a;
|
|
589
586
|
mutation.addedNodes.forEach((node) => {
|
|
590
|
-
var _a2, _b, _c;
|
|
591
587
|
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
592
588
|
const element = node;
|
|
593
|
-
if (
|
|
589
|
+
if (element.getAttribute("style")?.includes("hcs://")) {
|
|
594
590
|
this.processInlineStyles();
|
|
595
591
|
}
|
|
596
|
-
if (element.tagName.toLowerCase() === "style" &&
|
|
592
|
+
if (element.tagName.toLowerCase() === "style" && element.textContent?.includes("hcs://")) {
|
|
597
593
|
this.processInlineStyles();
|
|
598
594
|
}
|
|
599
|
-
if (
|
|
595
|
+
if (element.getAttribute("src")?.startsWith("hcs://")) {
|
|
600
596
|
const src = element.getAttribute("src");
|
|
601
597
|
element.setAttribute("data-src", src);
|
|
602
598
|
element.removeAttribute("src");
|
|
@@ -634,7 +630,7 @@ class HCS {
|
|
|
634
630
|
const childElement = child;
|
|
635
631
|
const tagName = childElement.tagName.toLowerCase();
|
|
636
632
|
const src = childElement.getAttribute("src");
|
|
637
|
-
if (src
|
|
633
|
+
if (src?.startsWith("hcs://")) {
|
|
638
634
|
childElement.setAttribute("data-src", src);
|
|
639
635
|
childElement.removeAttribute("src");
|
|
640
636
|
}
|
|
@@ -663,11 +659,11 @@ class HCS {
|
|
|
663
659
|
});
|
|
664
660
|
if (mutation.type === "attributes") {
|
|
665
661
|
const element = mutation.target;
|
|
666
|
-
if (mutation.attributeName === "style" &&
|
|
662
|
+
if (mutation.attributeName === "style" && element.getAttribute("style")?.includes("hcs://")) {
|
|
667
663
|
this.processInlineStyles();
|
|
668
664
|
} else if (mutation.attributeName === "src") {
|
|
669
665
|
const src = element.getAttribute("src");
|
|
670
|
-
if (src
|
|
666
|
+
if (src?.startsWith("hcs://")) {
|
|
671
667
|
element.setAttribute("data-src", src);
|
|
672
668
|
element.removeAttribute("src");
|
|
673
669
|
const type = element.tagName.toLowerCase();
|
|
@@ -748,16 +744,15 @@ class HCS {
|
|
|
748
744
|
}
|
|
749
745
|
}
|
|
750
746
|
async pauseAudio(topicId) {
|
|
751
|
-
var _a, _b;
|
|
752
747
|
const audioElement = document.querySelector(
|
|
753
748
|
'audio[data-topic-id="' + topicId + '"]'
|
|
754
749
|
);
|
|
755
750
|
if (audioElement) {
|
|
756
751
|
console.log("found element", audioElement);
|
|
757
752
|
audioElement.pause();
|
|
758
|
-
|
|
753
|
+
this.LoadedAudios[topicId]?.pause();
|
|
759
754
|
} else {
|
|
760
|
-
|
|
755
|
+
this.LoadedAudios[topicId]?.pause();
|
|
761
756
|
}
|
|
762
757
|
}
|
|
763
758
|
async loadAndPlayAudio(topicId, autoplay = false, volume = 1) {
|
|
@@ -937,9 +932,8 @@ class WasmBridge {
|
|
|
937
932
|
}
|
|
938
933
|
}
|
|
939
934
|
createStateData(wasmConfig, stateData = {}) {
|
|
940
|
-
var _a, _b;
|
|
941
935
|
let dynamicStateData = {};
|
|
942
|
-
if (
|
|
936
|
+
if (wasmConfig?.c?.inputType?.stateData) {
|
|
943
937
|
if (stateData.latestRoundData && Object.keys(wasmConfig.c.inputType.stateData).every((key) => key in stateData.latestRoundData)) {
|
|
944
938
|
dynamicStateData.latestRoundData = {};
|
|
945
939
|
Object.entries(wasmConfig.c.inputType.stateData).forEach(([key, _]) => {
|
|
@@ -5883,7 +5877,6 @@ class EVMBridge {
|
|
|
5883
5877
|
this.logger = Logger$1.getInstance({ module: "EVMBridge" });
|
|
5884
5878
|
}
|
|
5885
5879
|
async executeCommands(evmConfigs, initialState = {}) {
|
|
5886
|
-
var _a;
|
|
5887
5880
|
let stateData = { ...initialState };
|
|
5888
5881
|
const results = {};
|
|
5889
5882
|
for (const config of evmConfigs) {
|
|
@@ -5909,8 +5902,8 @@ class EVMBridge {
|
|
|
5909
5902
|
AccountId.fromString("0.0.800"),
|
|
5910
5903
|
contractId
|
|
5911
5904
|
);
|
|
5912
|
-
this.logger.info(`Result for ${config.c.contractAddress}:`, result
|
|
5913
|
-
if (!
|
|
5905
|
+
this.logger.info(`Result for ${config.c.contractAddress}:`, result?.result);
|
|
5906
|
+
if (!result?.result) {
|
|
5914
5907
|
this.logger.warn(
|
|
5915
5908
|
`Failed to get result from mirror node for ${config.c.contractAddress}`
|
|
5916
5909
|
);
|
|
@@ -5918,7 +5911,7 @@ class EVMBridge {
|
|
|
5918
5911
|
Object.assign(stateData, results[config.c.abi.name]);
|
|
5919
5912
|
continue;
|
|
5920
5913
|
}
|
|
5921
|
-
const decodedResult = iface
|
|
5914
|
+
const decodedResult = iface?.decodeFunctionResult(
|
|
5922
5915
|
config.c.abi.name,
|
|
5923
5916
|
result.result
|
|
5924
5917
|
);
|
|
@@ -5927,7 +5920,7 @@ class EVMBridge {
|
|
|
5927
5920
|
// Initialize array for values
|
|
5928
5921
|
};
|
|
5929
5922
|
if (decodedResult) {
|
|
5930
|
-
|
|
5923
|
+
config.c.abi.outputs?.forEach((output2, idx) => {
|
|
5931
5924
|
const value = decodedResult[idx];
|
|
5932
5925
|
const formattedValue = formatValue(value, output2.type);
|
|
5933
5926
|
processedResult.values.push(formattedValue);
|
|
@@ -5978,7 +5971,7 @@ class EVMBridge {
|
|
|
5978
5971
|
gas: 3e5,
|
|
5979
5972
|
gasPrice: 1e8,
|
|
5980
5973
|
from: fromAddress.startsWith("0x") ? fromAddress : `0x${fromAddress}`,
|
|
5981
|
-
to:
|
|
5974
|
+
to: toAddress?.startsWith("0x") ? toAddress : `0x${toAddress}`,
|
|
5982
5975
|
value: 0
|
|
5983
5976
|
})
|
|
5984
5977
|
}
|
|
@@ -15311,181 +15304,12 @@ const {
|
|
|
15311
15304
|
getAdapter,
|
|
15312
15305
|
mergeConfig
|
|
15313
15306
|
} = axios;
|
|
15314
|
-
class Registration {
|
|
15315
|
-
async checkRegistrationStatus(transactionId, network, baseUrl, logger) {
|
|
15316
|
-
try {
|
|
15317
|
-
const response = await fetch(`${baseUrl}/api/request-confirm`, {
|
|
15318
|
-
method: "POST",
|
|
15319
|
-
headers: {
|
|
15320
|
-
"Content-Type": "application/json",
|
|
15321
|
-
"X-Network": network
|
|
15322
|
-
},
|
|
15323
|
-
body: JSON.stringify({ transaction_id: transactionId })
|
|
15324
|
-
});
|
|
15325
|
-
if (!response.ok) {
|
|
15326
|
-
const error = `Failed to confirm registration: ${response.statusText}`;
|
|
15327
|
-
if (logger) {
|
|
15328
|
-
logger.error(error);
|
|
15329
|
-
}
|
|
15330
|
-
throw new Error(error);
|
|
15331
|
-
}
|
|
15332
|
-
return await response.json();
|
|
15333
|
-
} catch (error) {
|
|
15334
|
-
if (logger) {
|
|
15335
|
-
logger.error(`Error checking registration status: ${error.message}`);
|
|
15336
|
-
}
|
|
15337
|
-
throw error;
|
|
15338
|
-
}
|
|
15339
|
-
}
|
|
15340
|
-
async waitForRegistrationConfirmation(transactionId, network, baseUrl, maxAttempts = 60, delayMs = 2e3, logger) {
|
|
15341
|
-
let attempts = 0;
|
|
15342
|
-
while (attempts < maxAttempts) {
|
|
15343
|
-
if (logger) {
|
|
15344
|
-
logger.info(
|
|
15345
|
-
`Checking registration status. Attempt ${attempts + 1}/${maxAttempts}`
|
|
15346
|
-
);
|
|
15347
|
-
}
|
|
15348
|
-
const status = await this.checkRegistrationStatus(
|
|
15349
|
-
transactionId,
|
|
15350
|
-
network,
|
|
15351
|
-
baseUrl,
|
|
15352
|
-
logger
|
|
15353
|
-
);
|
|
15354
|
-
if (status.status === "success") {
|
|
15355
|
-
if (logger) {
|
|
15356
|
-
logger.info("Registration confirmed successfully");
|
|
15357
|
-
}
|
|
15358
|
-
return true;
|
|
15359
|
-
}
|
|
15360
|
-
if (status.status === "failed") {
|
|
15361
|
-
if (logger) {
|
|
15362
|
-
logger.error("Registration confirmation failed");
|
|
15363
|
-
}
|
|
15364
|
-
throw new Error("Registration confirmation failed");
|
|
15365
|
-
}
|
|
15366
|
-
if (logger) {
|
|
15367
|
-
logger.info(
|
|
15368
|
-
`Registration still pending. Waiting ${delayMs}ms before next attempt`
|
|
15369
|
-
);
|
|
15370
|
-
}
|
|
15371
|
-
await new Promise((resolve2) => setTimeout(resolve2, delayMs));
|
|
15372
|
-
attempts++;
|
|
15373
|
-
}
|
|
15374
|
-
if (logger) {
|
|
15375
|
-
logger.warn(`Registration not confirmed after ${maxAttempts} attempts`);
|
|
15376
|
-
}
|
|
15377
|
-
return false;
|
|
15378
|
-
}
|
|
15379
|
-
async executeRegistration(accountId, inboundTopicId, network, baseUrl, logger, metadata = { tags: [] }) {
|
|
15380
|
-
var _a;
|
|
15381
|
-
try {
|
|
15382
|
-
if (logger) {
|
|
15383
|
-
logger.info("Registering agent with guarded registry");
|
|
15384
|
-
}
|
|
15385
|
-
const response = await fetch(`${baseUrl}/api/request-register`, {
|
|
15386
|
-
method: "POST",
|
|
15387
|
-
headers: {
|
|
15388
|
-
"Content-Type": "application/json",
|
|
15389
|
-
Accept: "*/*",
|
|
15390
|
-
"Accept-Language": "en;q=0.5",
|
|
15391
|
-
Origin: baseUrl,
|
|
15392
|
-
Referer: `${baseUrl}/`,
|
|
15393
|
-
"X-Network": network
|
|
15394
|
-
},
|
|
15395
|
-
body: JSON.stringify({
|
|
15396
|
-
accountId,
|
|
15397
|
-
inboundTopicId,
|
|
15398
|
-
metadata
|
|
15399
|
-
})
|
|
15400
|
-
});
|
|
15401
|
-
const data = await response.json();
|
|
15402
|
-
if (!response.ok) {
|
|
15403
|
-
if (((_a = data.details) == null ? void 0 : _a.length) > 0) {
|
|
15404
|
-
return {
|
|
15405
|
-
validationErrors: data.details,
|
|
15406
|
-
error: data.error || "Validation failed",
|
|
15407
|
-
success: false
|
|
15408
|
-
};
|
|
15409
|
-
}
|
|
15410
|
-
return {
|
|
15411
|
-
error: data.error || "Failed to register agent",
|
|
15412
|
-
success: false
|
|
15413
|
-
};
|
|
15414
|
-
}
|
|
15415
|
-
if (logger) {
|
|
15416
|
-
logger.info(
|
|
15417
|
-
`Created new registration request. Transaction ID: ${data.transaction_id}`
|
|
15418
|
-
);
|
|
15419
|
-
}
|
|
15420
|
-
return {
|
|
15421
|
-
transactionId: data.transaction_id,
|
|
15422
|
-
transaction: data.transaction,
|
|
15423
|
-
success: true
|
|
15424
|
-
};
|
|
15425
|
-
} catch (error) {
|
|
15426
|
-
return {
|
|
15427
|
-
error: `Error during registration request: ${error.message}`,
|
|
15428
|
-
success: false
|
|
15429
|
-
};
|
|
15430
|
-
}
|
|
15431
|
-
}
|
|
15432
|
-
async findRegistrations(options = {}, baseUrl = "https://hcs-10.hashgraphonline.com") {
|
|
15433
|
-
var _a;
|
|
15434
|
-
try {
|
|
15435
|
-
const queryParams = new URLSearchParams();
|
|
15436
|
-
(_a = options.tags) == null ? void 0 : _a.forEach((tag) => queryParams.append("tags", tag));
|
|
15437
|
-
if (options.accountId) {
|
|
15438
|
-
queryParams.append("accountId", options.accountId);
|
|
15439
|
-
}
|
|
15440
|
-
if (options.network) {
|
|
15441
|
-
queryParams.append("network", options.network);
|
|
15442
|
-
}
|
|
15443
|
-
const response = await fetch(
|
|
15444
|
-
`${baseUrl}/api/registrations?${queryParams}`,
|
|
15445
|
-
{
|
|
15446
|
-
headers: {
|
|
15447
|
-
Accept: "*/*",
|
|
15448
|
-
"Accept-Language": "en;q=0.5",
|
|
15449
|
-
Origin: baseUrl,
|
|
15450
|
-
Referer: `${baseUrl}/`
|
|
15451
|
-
}
|
|
15452
|
-
}
|
|
15453
|
-
);
|
|
15454
|
-
if (!response.ok) {
|
|
15455
|
-
const error = await response.text();
|
|
15456
|
-
return {
|
|
15457
|
-
registrations: [],
|
|
15458
|
-
error: error || "Failed to fetch registrations",
|
|
15459
|
-
success: false
|
|
15460
|
-
};
|
|
15461
|
-
}
|
|
15462
|
-
const data = await response.json();
|
|
15463
|
-
if (data.error) {
|
|
15464
|
-
return {
|
|
15465
|
-
registrations: [],
|
|
15466
|
-
error: data.error,
|
|
15467
|
-
success: false
|
|
15468
|
-
};
|
|
15469
|
-
}
|
|
15470
|
-
return {
|
|
15471
|
-
registrations: data.registrations || [],
|
|
15472
|
-
success: true
|
|
15473
|
-
};
|
|
15474
|
-
} catch (e) {
|
|
15475
|
-
const error = e;
|
|
15476
|
-
return {
|
|
15477
|
-
registrations: [],
|
|
15478
|
-
error: `Error fetching registrations: ${error.message}`,
|
|
15479
|
-
success: false
|
|
15480
|
-
};
|
|
15481
|
-
}
|
|
15482
|
-
}
|
|
15483
|
-
}
|
|
15484
15307
|
class HederaMirrorNode {
|
|
15485
15308
|
constructor(network, logger) {
|
|
15486
15309
|
this.network = network;
|
|
15487
15310
|
this.baseUrl = this.getMirrorNodeUrl();
|
|
15488
15311
|
this.logger = logger;
|
|
15312
|
+
this.isServerEnvironment = typeof window === "undefined";
|
|
15489
15313
|
}
|
|
15490
15314
|
getMirrorNodeUrl() {
|
|
15491
15315
|
return this.network === "mainnet" ? "https://mainnet-public.mirrornode.hedera.com" : "https://testnet.mirrornode.hedera.com";
|
|
@@ -15551,7 +15375,6 @@ class HederaMirrorNode {
|
|
|
15551
15375
|
}
|
|
15552
15376
|
}
|
|
15553
15377
|
async getTopicMessages(topicId) {
|
|
15554
|
-
var _a;
|
|
15555
15378
|
if (this.logger) {
|
|
15556
15379
|
this.logger.info(`Querying messages for topic ${topicId}`);
|
|
15557
15380
|
}
|
|
@@ -15562,26 +15385,45 @@ class HederaMirrorNode {
|
|
|
15562
15385
|
const response = await axios.get(nextUrl);
|
|
15563
15386
|
const data = response.data;
|
|
15564
15387
|
if (data.messages && data.messages.length > 0) {
|
|
15565
|
-
data.messages
|
|
15566
|
-
const messageContent = Buffer2.from(msg.message, "base64").toString(
|
|
15567
|
-
"utf8"
|
|
15568
|
-
);
|
|
15569
|
-
let messageJson;
|
|
15388
|
+
for (const message of data.messages) {
|
|
15570
15389
|
try {
|
|
15571
|
-
|
|
15390
|
+
if (!message.message) continue;
|
|
15391
|
+
let messageContent;
|
|
15392
|
+
try {
|
|
15393
|
+
if (this.isServerEnvironment) {
|
|
15394
|
+
messageContent = Buffer2.from(message.message, "base64").toString("utf-8");
|
|
15395
|
+
} else {
|
|
15396
|
+
messageContent = new TextDecoder().decode(
|
|
15397
|
+
Uint8Array.from(atob(message.message), (c) => c.charCodeAt(0))
|
|
15398
|
+
);
|
|
15399
|
+
}
|
|
15400
|
+
} catch (error) {
|
|
15401
|
+
if (this.logger) {
|
|
15402
|
+
this.logger.error(`Error decoding message: ${error}`);
|
|
15403
|
+
}
|
|
15404
|
+
continue;
|
|
15405
|
+
}
|
|
15406
|
+
let messageJson;
|
|
15407
|
+
try {
|
|
15408
|
+
messageJson = JSON.parse(messageContent);
|
|
15409
|
+
} catch (error) {
|
|
15410
|
+
if (this.logger) {
|
|
15411
|
+
this.logger.error(
|
|
15412
|
+
`Invalid JSON message content: ${messageContent}`
|
|
15413
|
+
);
|
|
15414
|
+
}
|
|
15415
|
+
return;
|
|
15416
|
+
}
|
|
15417
|
+
messageJson.sequence_number = message.sequence_number;
|
|
15418
|
+
messages.push(messageJson);
|
|
15572
15419
|
} catch (error) {
|
|
15573
15420
|
if (this.logger) {
|
|
15574
|
-
this.logger.error(
|
|
15575
|
-
`Invalid JSON message content: ${messageContent}`
|
|
15576
|
-
);
|
|
15421
|
+
this.logger.error(`Error processing message: ${error.message}`);
|
|
15577
15422
|
}
|
|
15578
|
-
return;
|
|
15579
15423
|
}
|
|
15580
|
-
|
|
15581
|
-
messages.push(messageJson);
|
|
15582
|
-
});
|
|
15424
|
+
}
|
|
15583
15425
|
}
|
|
15584
|
-
nextUrl =
|
|
15426
|
+
nextUrl = data.links?.next ? `${this.baseUrl}${data.links.next}` : "";
|
|
15585
15427
|
} catch (error) {
|
|
15586
15428
|
if (this.logger) {
|
|
15587
15429
|
this.logger.error(`Error querying topic messages: ${error.message}`);
|
|
@@ -15670,6 +15512,174 @@ class HederaMirrorNode {
|
|
|
15670
15512
|
}
|
|
15671
15513
|
}
|
|
15672
15514
|
}
|
|
15515
|
+
class Registration {
|
|
15516
|
+
async checkRegistrationStatus(transactionId, network, baseUrl, logger) {
|
|
15517
|
+
try {
|
|
15518
|
+
const response = await fetch(`${baseUrl}/api/request-confirm`, {
|
|
15519
|
+
method: "POST",
|
|
15520
|
+
headers: {
|
|
15521
|
+
"Content-Type": "application/json",
|
|
15522
|
+
"X-Network": network
|
|
15523
|
+
},
|
|
15524
|
+
body: JSON.stringify({ transaction_id: transactionId })
|
|
15525
|
+
});
|
|
15526
|
+
if (!response.ok) {
|
|
15527
|
+
const error = `Failed to confirm registration: ${response.statusText}`;
|
|
15528
|
+
if (logger) {
|
|
15529
|
+
logger.error(error);
|
|
15530
|
+
}
|
|
15531
|
+
throw new Error(error);
|
|
15532
|
+
}
|
|
15533
|
+
return await response.json();
|
|
15534
|
+
} catch (error) {
|
|
15535
|
+
if (logger) {
|
|
15536
|
+
logger.error(`Error checking registration status: ${error.message}`);
|
|
15537
|
+
}
|
|
15538
|
+
throw error;
|
|
15539
|
+
}
|
|
15540
|
+
}
|
|
15541
|
+
async waitForRegistrationConfirmation(transactionId, network, baseUrl, maxAttempts = 60, delayMs = 2e3, logger) {
|
|
15542
|
+
let attempts = 0;
|
|
15543
|
+
while (attempts < maxAttempts) {
|
|
15544
|
+
if (logger) {
|
|
15545
|
+
logger.info(
|
|
15546
|
+
`Checking registration status. Attempt ${attempts + 1}/${maxAttempts}`
|
|
15547
|
+
);
|
|
15548
|
+
}
|
|
15549
|
+
const status = await this.checkRegistrationStatus(
|
|
15550
|
+
transactionId,
|
|
15551
|
+
network,
|
|
15552
|
+
baseUrl,
|
|
15553
|
+
logger
|
|
15554
|
+
);
|
|
15555
|
+
if (status.status === "success") {
|
|
15556
|
+
if (logger) {
|
|
15557
|
+
logger.info("Registration confirmed successfully");
|
|
15558
|
+
}
|
|
15559
|
+
return true;
|
|
15560
|
+
}
|
|
15561
|
+
if (status.status === "failed") {
|
|
15562
|
+
if (logger) {
|
|
15563
|
+
logger.error("Registration confirmation failed");
|
|
15564
|
+
}
|
|
15565
|
+
throw new Error("Registration confirmation failed");
|
|
15566
|
+
}
|
|
15567
|
+
if (logger) {
|
|
15568
|
+
logger.info(
|
|
15569
|
+
`Registration still pending. Waiting ${delayMs}ms before next attempt`
|
|
15570
|
+
);
|
|
15571
|
+
}
|
|
15572
|
+
await new Promise((resolve2) => setTimeout(resolve2, delayMs));
|
|
15573
|
+
attempts++;
|
|
15574
|
+
}
|
|
15575
|
+
if (logger) {
|
|
15576
|
+
logger.warn(`Registration not confirmed after ${maxAttempts} attempts`);
|
|
15577
|
+
}
|
|
15578
|
+
return false;
|
|
15579
|
+
}
|
|
15580
|
+
async executeRegistration(accountId, inboundTopicId, network, baseUrl, logger, metadata = { tags: [] }) {
|
|
15581
|
+
try {
|
|
15582
|
+
if (logger) {
|
|
15583
|
+
logger.info("Registering agent with guarded registry");
|
|
15584
|
+
}
|
|
15585
|
+
const response = await fetch(`${baseUrl}/api/request-register`, {
|
|
15586
|
+
method: "POST",
|
|
15587
|
+
headers: {
|
|
15588
|
+
"Content-Type": "application/json",
|
|
15589
|
+
Accept: "*/*",
|
|
15590
|
+
"Accept-Language": "en;q=0.5",
|
|
15591
|
+
Origin: baseUrl,
|
|
15592
|
+
Referer: `${baseUrl}/`,
|
|
15593
|
+
"X-Network": network
|
|
15594
|
+
},
|
|
15595
|
+
body: JSON.stringify({
|
|
15596
|
+
accountId,
|
|
15597
|
+
inboundTopicId,
|
|
15598
|
+
metadata
|
|
15599
|
+
})
|
|
15600
|
+
});
|
|
15601
|
+
const data = await response.json();
|
|
15602
|
+
if (!response.ok) {
|
|
15603
|
+
if (data.details?.length > 0) {
|
|
15604
|
+
return {
|
|
15605
|
+
validationErrors: data.details,
|
|
15606
|
+
error: data.error || "Validation failed",
|
|
15607
|
+
success: false
|
|
15608
|
+
};
|
|
15609
|
+
}
|
|
15610
|
+
return {
|
|
15611
|
+
error: data.error || "Failed to register agent",
|
|
15612
|
+
success: false
|
|
15613
|
+
};
|
|
15614
|
+
}
|
|
15615
|
+
if (logger) {
|
|
15616
|
+
logger.info(
|
|
15617
|
+
`Created new registration request. Transaction ID: ${data.transaction_id}`
|
|
15618
|
+
);
|
|
15619
|
+
}
|
|
15620
|
+
return {
|
|
15621
|
+
transactionId: data.transaction_id,
|
|
15622
|
+
transaction: data.transaction,
|
|
15623
|
+
success: true
|
|
15624
|
+
};
|
|
15625
|
+
} catch (error) {
|
|
15626
|
+
return {
|
|
15627
|
+
error: `Error during registration request: ${error.message}`,
|
|
15628
|
+
success: false
|
|
15629
|
+
};
|
|
15630
|
+
}
|
|
15631
|
+
}
|
|
15632
|
+
async findRegistrations(options = {}, baseUrl = "https://hcs-10.hashgraphonline.com") {
|
|
15633
|
+
try {
|
|
15634
|
+
const queryParams = new URLSearchParams();
|
|
15635
|
+
options.tags?.forEach((tag) => queryParams.append("tags", tag));
|
|
15636
|
+
if (options.accountId) {
|
|
15637
|
+
queryParams.append("accountId", options.accountId);
|
|
15638
|
+
}
|
|
15639
|
+
if (options.network) {
|
|
15640
|
+
queryParams.append("network", options.network);
|
|
15641
|
+
}
|
|
15642
|
+
const response = await fetch(
|
|
15643
|
+
`${baseUrl}/api/registrations?${queryParams}`,
|
|
15644
|
+
{
|
|
15645
|
+
headers: {
|
|
15646
|
+
Accept: "*/*",
|
|
15647
|
+
"Accept-Language": "en;q=0.5",
|
|
15648
|
+
Origin: baseUrl,
|
|
15649
|
+
Referer: `${baseUrl}/`
|
|
15650
|
+
}
|
|
15651
|
+
}
|
|
15652
|
+
);
|
|
15653
|
+
if (!response.ok) {
|
|
15654
|
+
const error = await response.text();
|
|
15655
|
+
return {
|
|
15656
|
+
registrations: [],
|
|
15657
|
+
error: error || "Failed to fetch registrations",
|
|
15658
|
+
success: false
|
|
15659
|
+
};
|
|
15660
|
+
}
|
|
15661
|
+
const data = await response.json();
|
|
15662
|
+
if (data.error) {
|
|
15663
|
+
return {
|
|
15664
|
+
registrations: [],
|
|
15665
|
+
error: data.error,
|
|
15666
|
+
success: false
|
|
15667
|
+
};
|
|
15668
|
+
}
|
|
15669
|
+
return {
|
|
15670
|
+
registrations: data.registrations || [],
|
|
15671
|
+
success: true
|
|
15672
|
+
};
|
|
15673
|
+
} catch (e) {
|
|
15674
|
+
const error = e;
|
|
15675
|
+
return {
|
|
15676
|
+
registrations: [],
|
|
15677
|
+
error: `Error fetching registrations: ${error.message}`,
|
|
15678
|
+
success: false
|
|
15679
|
+
};
|
|
15680
|
+
}
|
|
15681
|
+
}
|
|
15682
|
+
}
|
|
15673
15683
|
class HCS10BaseClient extends Registration {
|
|
15674
15684
|
constructor(config) {
|
|
15675
15685
|
super();
|
|
@@ -15874,6 +15884,37 @@ class HCS10BaseClient extends Registration {
|
|
|
15874
15884
|
clearCache() {
|
|
15875
15885
|
HCS10Cache.getInstance().clear();
|
|
15876
15886
|
}
|
|
15887
|
+
/**
|
|
15888
|
+
* Gets message content, resolving any HRL references if needed
|
|
15889
|
+
* @param data The message data which might be an HRL reference
|
|
15890
|
+
* @returns The resolved content
|
|
15891
|
+
*/
|
|
15892
|
+
async getMessageContent(data) {
|
|
15893
|
+
const hrlPattern = /^hcs:\/\/(\d+)\/([0-9.]+)$/;
|
|
15894
|
+
const match = data.match(hrlPattern);
|
|
15895
|
+
if (!match) {
|
|
15896
|
+
return data;
|
|
15897
|
+
}
|
|
15898
|
+
const [_, standard, topicId] = match;
|
|
15899
|
+
this.logger.info(
|
|
15900
|
+
`Resolving HRL reference: standard=${standard}, topicId=${topicId}`
|
|
15901
|
+
);
|
|
15902
|
+
try {
|
|
15903
|
+
const cdnUrl = `https://kiloscribe.com/api/inscription-cdn/${topicId}?network=${this.network}`;
|
|
15904
|
+
const response = await axios.get(cdnUrl);
|
|
15905
|
+
if (!response.data) {
|
|
15906
|
+
throw new Error(`Failed to fetch content from topic: ${topicId}`);
|
|
15907
|
+
}
|
|
15908
|
+
return response.data.content || response.data.text || JSON.stringify(response.data);
|
|
15909
|
+
} catch (error) {
|
|
15910
|
+
this.logger.error(
|
|
15911
|
+
`Error resolving HRL reference: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
15912
|
+
);
|
|
15913
|
+
throw new Error(
|
|
15914
|
+
`Failed to resolve HRL reference: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
15915
|
+
);
|
|
15916
|
+
}
|
|
15917
|
+
}
|
|
15877
15918
|
}
|
|
15878
15919
|
class HCS10Cache {
|
|
15879
15920
|
constructor() {
|
|
@@ -27115,7 +27156,6 @@ var InboundTopicType = /* @__PURE__ */ ((InboundTopicType2) => {
|
|
|
27115
27156
|
return InboundTopicType2;
|
|
27116
27157
|
})(InboundTopicType || {});
|
|
27117
27158
|
async function inscribe(input, clientConfig, options, existingSDK) {
|
|
27118
|
-
var _a, _b;
|
|
27119
27159
|
const logger = Logger$1.getInstance({
|
|
27120
27160
|
module: "Inscriber",
|
|
27121
27161
|
...options.logging
|
|
@@ -27191,8 +27231,8 @@ async function inscribe(input, clientConfig, options, existingSDK) {
|
|
|
27191
27231
|
}
|
|
27192
27232
|
if (options.mode === "hashinal") {
|
|
27193
27233
|
request.metadataObject = options.metadata;
|
|
27194
|
-
request.creator =
|
|
27195
|
-
request.description =
|
|
27234
|
+
request.creator = options.metadata?.creator || clientConfig.accountId;
|
|
27235
|
+
request.description = options.metadata?.description;
|
|
27196
27236
|
if (options.jsonFileURL) {
|
|
27197
27237
|
request.jsonFileURL = options.jsonFileURL;
|
|
27198
27238
|
}
|
|
@@ -27241,7 +27281,6 @@ async function inscribe(input, clientConfig, options, existingSDK) {
|
|
|
27241
27281
|
}
|
|
27242
27282
|
}
|
|
27243
27283
|
async function inscribeWithSigner(input, signer, options, existingSDK) {
|
|
27244
|
-
var _a, _b;
|
|
27245
27284
|
const logger = Logger$1.getInstance({
|
|
27246
27285
|
module: "Inscriber",
|
|
27247
27286
|
...options.logging
|
|
@@ -27319,8 +27358,8 @@ async function inscribeWithSigner(input, signer, options, existingSDK) {
|
|
|
27319
27358
|
}
|
|
27320
27359
|
if (options.mode === "hashinal") {
|
|
27321
27360
|
request.metadataObject = options.metadata;
|
|
27322
|
-
request.creator =
|
|
27323
|
-
request.description =
|
|
27361
|
+
request.creator = options.metadata?.creator || accountId;
|
|
27362
|
+
request.description = options.metadata?.description;
|
|
27324
27363
|
if (options.jsonFileURL) {
|
|
27325
27364
|
request.jsonFileURL = options.jsonFileURL;
|
|
27326
27365
|
}
|
|
@@ -31669,15 +31708,15 @@ class HCS11Client {
|
|
|
31669
31708
|
version: "1.0",
|
|
31670
31709
|
type: 0,
|
|
31671
31710
|
display_name: displayName,
|
|
31672
|
-
alias: options
|
|
31673
|
-
bio: options
|
|
31674
|
-
socials: options
|
|
31675
|
-
profileImage: options
|
|
31676
|
-
language: options
|
|
31677
|
-
timezone: options
|
|
31678
|
-
properties: options
|
|
31679
|
-
inboundTopicId: options
|
|
31680
|
-
outboundTopicId: options
|
|
31711
|
+
alias: options?.alias,
|
|
31712
|
+
bio: options?.bio,
|
|
31713
|
+
socials: options?.socials,
|
|
31714
|
+
profileImage: options?.profileImage,
|
|
31715
|
+
language: options?.language,
|
|
31716
|
+
timezone: options?.timezone,
|
|
31717
|
+
properties: options?.properties,
|
|
31718
|
+
inboundTopicId: options?.inboundTopicId,
|
|
31719
|
+
outboundTopicId: options?.outboundTopicId
|
|
31681
31720
|
};
|
|
31682
31721
|
}
|
|
31683
31722
|
createAIAgentProfile(displayName, agentType, capabilities, model, options) {
|
|
@@ -31685,18 +31724,18 @@ class HCS11Client {
|
|
|
31685
31724
|
version: "1.0",
|
|
31686
31725
|
type: 1,
|
|
31687
31726
|
display_name: displayName,
|
|
31688
|
-
alias: options
|
|
31689
|
-
bio: options
|
|
31690
|
-
socials: options
|
|
31691
|
-
profileImage: options
|
|
31692
|
-
properties: options
|
|
31693
|
-
inboundTopicId: options
|
|
31694
|
-
outboundTopicId: options
|
|
31727
|
+
alias: options?.alias,
|
|
31728
|
+
bio: options?.bio,
|
|
31729
|
+
socials: options?.socials,
|
|
31730
|
+
profileImage: options?.profileImage,
|
|
31731
|
+
properties: options?.properties,
|
|
31732
|
+
inboundTopicId: options?.inboundTopicId,
|
|
31733
|
+
outboundTopicId: options?.outboundTopicId,
|
|
31695
31734
|
aiAgent: {
|
|
31696
31735
|
type: agentType,
|
|
31697
31736
|
capabilities,
|
|
31698
31737
|
model,
|
|
31699
|
-
creator: options
|
|
31738
|
+
creator: options?.creator
|
|
31700
31739
|
}
|
|
31701
31740
|
});
|
|
31702
31741
|
if (!validation.valid) {
|
|
@@ -31708,18 +31747,18 @@ class HCS11Client {
|
|
|
31708
31747
|
version: "1.0",
|
|
31709
31748
|
type: 1,
|
|
31710
31749
|
display_name: displayName,
|
|
31711
|
-
alias: options
|
|
31712
|
-
bio: options
|
|
31713
|
-
socials: options
|
|
31714
|
-
profileImage: options
|
|
31715
|
-
properties: options
|
|
31716
|
-
inboundTopicId: options
|
|
31717
|
-
outboundTopicId: options
|
|
31750
|
+
alias: options?.alias,
|
|
31751
|
+
bio: options?.bio,
|
|
31752
|
+
socials: options?.socials,
|
|
31753
|
+
profileImage: options?.profileImage,
|
|
31754
|
+
properties: options?.properties,
|
|
31755
|
+
inboundTopicId: options?.inboundTopicId,
|
|
31756
|
+
outboundTopicId: options?.outboundTopicId,
|
|
31718
31757
|
aiAgent: {
|
|
31719
31758
|
type: agentType,
|
|
31720
31759
|
capabilities,
|
|
31721
31760
|
model,
|
|
31722
|
-
creator: options
|
|
31761
|
+
creator: options?.creator
|
|
31723
31762
|
}
|
|
31724
31763
|
};
|
|
31725
31764
|
}
|
|
@@ -31729,13 +31768,12 @@ class HCS11Client {
|
|
|
31729
31768
|
return { valid: true, errors: [] };
|
|
31730
31769
|
}
|
|
31731
31770
|
const formattedErrors = result.error.errors.map((err) => {
|
|
31732
|
-
var _a;
|
|
31733
31771
|
const path = err.path.join(".");
|
|
31734
31772
|
let message = err.message;
|
|
31735
31773
|
if (err.code === "invalid_type") {
|
|
31736
31774
|
message = `Expected ${err.expected}, got ${err.received}`;
|
|
31737
31775
|
} else if (err.code === "invalid_enum_value") {
|
|
31738
|
-
const validOptions =
|
|
31776
|
+
const validOptions = err.options?.join(", ");
|
|
31739
31777
|
message = `Invalid value. Valid options are: ${validOptions}`;
|
|
31740
31778
|
} else if (err.code === "too_small" && err.type === "string") {
|
|
31741
31779
|
message = "Cannot be empty";
|
|
@@ -32154,11 +32192,10 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32154
32192
|
* @returns Object with topic IDs
|
|
32155
32193
|
*/
|
|
32156
32194
|
async createAgent(builder) {
|
|
32157
|
-
var _a;
|
|
32158
32195
|
const config = builder.build();
|
|
32159
32196
|
const outboundTopicId = await this.createTopic("hcs-10:0:60:1", true, true);
|
|
32160
32197
|
this.logger.info(`Created new outbound topic ID: ${outboundTopicId}`);
|
|
32161
|
-
const accountId =
|
|
32198
|
+
const accountId = this.client.operatorAccountId?.toString();
|
|
32162
32199
|
if (!accountId) {
|
|
32163
32200
|
throw new Error("Failed to retrieve operator account ID");
|
|
32164
32201
|
}
|
|
@@ -32324,10 +32361,7 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32324
32361
|
if (exemptAccountIds.length > 0) {
|
|
32325
32362
|
const uniqueExemptAccountIds = Array.from(new Set(exemptAccountIds));
|
|
32326
32363
|
const filteredExemptAccounts = uniqueExemptAccountIds.filter(
|
|
32327
|
-
(account) =>
|
|
32328
|
-
var _a;
|
|
32329
|
-
return account !== ((_a = this.client.operatorAccountId) == null ? void 0 : _a.toString());
|
|
32330
|
-
}
|
|
32364
|
+
(account) => account !== this.client.operatorAccountId?.toString()
|
|
32331
32365
|
);
|
|
32332
32366
|
let exemptKeys = [];
|
|
32333
32367
|
if (filteredExemptAccounts.length > 0) {
|
|
@@ -32358,12 +32392,11 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32358
32392
|
* @returns Response with connection details
|
|
32359
32393
|
*/
|
|
32360
32394
|
async handleConnectionRequest(inboundTopicId, requestingAccountId, connectionRequestId, connectionFeeConfig) {
|
|
32361
|
-
var _a;
|
|
32362
32395
|
const memo = `hcs-10:${inboundTopicId}:${connectionRequestId}`;
|
|
32363
32396
|
this.logger.info(
|
|
32364
32397
|
`Handling connection request ${connectionRequestId} from ${requestingAccountId}`
|
|
32365
32398
|
);
|
|
32366
|
-
const accountId =
|
|
32399
|
+
const accountId = this.getClient().operatorAccountId?.toString();
|
|
32367
32400
|
if (!accountId) {
|
|
32368
32401
|
throw new Error("Failed to retrieve operator account ID");
|
|
32369
32402
|
}
|
|
@@ -32417,7 +32450,6 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32417
32450
|
};
|
|
32418
32451
|
}
|
|
32419
32452
|
async confirmConnection(inboundTopicId, connectionTopicId, connectedAccountId, connectionId, operatorId, memo, submitKey) {
|
|
32420
|
-
var _a;
|
|
32421
32453
|
this.logger.info(`Confirming connection with ID ${connectionId}`);
|
|
32422
32454
|
const payload = {
|
|
32423
32455
|
p: "hcs-10",
|
|
@@ -32429,7 +32461,7 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32429
32461
|
m: memo
|
|
32430
32462
|
};
|
|
32431
32463
|
const result = await this.submitPayload(inboundTopicId, payload, submitKey);
|
|
32432
|
-
const sequenceNumber =
|
|
32464
|
+
const sequenceNumber = result.topicSequenceNumber?.toNumber();
|
|
32433
32465
|
if (!sequenceNumber) {
|
|
32434
32466
|
throw new ConnectionConfirmationError(
|
|
32435
32467
|
"Failed to confirm connection: sequence number is null"
|
|
@@ -32438,10 +32470,9 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32438
32470
|
return sequenceNumber;
|
|
32439
32471
|
}
|
|
32440
32472
|
async sendMessage(connectionTopicId, operatorId, data, memo, submitKey) {
|
|
32441
|
-
var _a;
|
|
32442
32473
|
const submissionCheck = await this.canSubmitToInboundTopic(
|
|
32443
32474
|
connectionTopicId,
|
|
32444
|
-
|
|
32475
|
+
this.client.operatorAccountId?.toString() || ""
|
|
32445
32476
|
);
|
|
32446
32477
|
const payload = {
|
|
32447
32478
|
p: "hcs-10",
|
|
@@ -32450,6 +32481,35 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32450
32481
|
data,
|
|
32451
32482
|
m: memo
|
|
32452
32483
|
};
|
|
32484
|
+
const payloadString = JSON.stringify(payload);
|
|
32485
|
+
const isLargePayload = Buffer2.from(payloadString).length > 1e3;
|
|
32486
|
+
if (isLargePayload) {
|
|
32487
|
+
this.logger.info(
|
|
32488
|
+
"Message payload exceeds 1000 bytes, storing via inscription"
|
|
32489
|
+
);
|
|
32490
|
+
try {
|
|
32491
|
+
const contentBuffer = Buffer2.from(data);
|
|
32492
|
+
const fileName = `message-${Date.now()}.json`;
|
|
32493
|
+
const inscriptionResult = await this.inscribeFile(
|
|
32494
|
+
contentBuffer,
|
|
32495
|
+
fileName
|
|
32496
|
+
);
|
|
32497
|
+
if (inscriptionResult?.topic_id) {
|
|
32498
|
+
payload.data = `hcs://1/${inscriptionResult.topic_id}`;
|
|
32499
|
+
this.logger.info(
|
|
32500
|
+
`Large message inscribed with topic ID: ${inscriptionResult.topic_id}`
|
|
32501
|
+
);
|
|
32502
|
+
} else {
|
|
32503
|
+
throw new Error("Failed to inscribe large message content");
|
|
32504
|
+
}
|
|
32505
|
+
} catch (error) {
|
|
32506
|
+
this.logger.error("Error inscribing large message:", error);
|
|
32507
|
+
throw new Error(
|
|
32508
|
+
`Failed to handle large message: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
32509
|
+
);
|
|
32510
|
+
}
|
|
32511
|
+
}
|
|
32512
|
+
this.logger.info("Submitting message to connection topic", payload);
|
|
32453
32513
|
await this.submitPayload(
|
|
32454
32514
|
connectionTopicId,
|
|
32455
32515
|
payload,
|
|
@@ -32492,10 +32552,9 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32492
32552
|
return topicId;
|
|
32493
32553
|
}
|
|
32494
32554
|
async submitMessage(topicId, message, submitKey) {
|
|
32495
|
-
var _a;
|
|
32496
32555
|
const submissionCheck = await this.canSubmitToInboundTopic(
|
|
32497
32556
|
topicId,
|
|
32498
|
-
|
|
32557
|
+
this.client.operatorAccountId?.toString() || ""
|
|
32499
32558
|
);
|
|
32500
32559
|
return this.submitPayload(
|
|
32501
32560
|
topicId,
|
|
@@ -32507,9 +32566,9 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32507
32566
|
async submitPayload(topicId, payload, submitKey, requiresFee = false) {
|
|
32508
32567
|
const message = typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
32509
32568
|
const payloadSizeInBytes = Buffer2.byteLength(message, "utf8");
|
|
32510
|
-
if (payloadSizeInBytes >
|
|
32569
|
+
if (payloadSizeInBytes > 1e3) {
|
|
32511
32570
|
throw new PayloadSizeError(
|
|
32512
|
-
"Payload size exceeds
|
|
32571
|
+
"Payload size exceeds 1000 bytes limit",
|
|
32513
32572
|
payloadSizeInBytes
|
|
32514
32573
|
);
|
|
32515
32574
|
}
|
|
@@ -32538,7 +32597,6 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32538
32597
|
return receipt;
|
|
32539
32598
|
}
|
|
32540
32599
|
async submitConnectionRequest(inboundTopicId, requestingAccountId, operatorId, memo) {
|
|
32541
|
-
var _a;
|
|
32542
32600
|
const submissionCheck = await this.canSubmitToInboundTopic(
|
|
32543
32601
|
inboundTopicId,
|
|
32544
32602
|
requestingAccountId
|
|
@@ -32565,7 +32623,7 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32565
32623
|
const outboundTopic = await this.retrieveOutboundConnectTopic(
|
|
32566
32624
|
requestingAccountId
|
|
32567
32625
|
);
|
|
32568
|
-
const responseSequenceNumber =
|
|
32626
|
+
const responseSequenceNumber = response.topicSequenceNumber?.toNumber();
|
|
32569
32627
|
if (!responseSequenceNumber) {
|
|
32570
32628
|
throw new Error("Failed to get response sequence number");
|
|
32571
32629
|
}
|
|
@@ -32707,7 +32765,6 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32707
32765
|
* @returns Object with canSubmit, requiresFee, and optional reason
|
|
32708
32766
|
*/
|
|
32709
32767
|
async canSubmitToInboundTopic(topicId, userAccountId) {
|
|
32710
|
-
var _a, _b, _c, _d;
|
|
32711
32768
|
try {
|
|
32712
32769
|
const topicInfo = await this.mirrorNode.getTopicInfo(topicId);
|
|
32713
32770
|
if (!topicInfo) {
|
|
@@ -32717,7 +32774,7 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32717
32774
|
reason: "Topic does not exist"
|
|
32718
32775
|
};
|
|
32719
32776
|
}
|
|
32720
|
-
if (!
|
|
32777
|
+
if (!topicInfo.submit_key?.key) {
|
|
32721
32778
|
return { canSubmit: true, requiresFee: false };
|
|
32722
32779
|
}
|
|
32723
32780
|
try {
|
|
@@ -32742,7 +32799,7 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32742
32799
|
`Key validation error: ${error instanceof Error ? error.message : String(error)}`
|
|
32743
32800
|
);
|
|
32744
32801
|
}
|
|
32745
|
-
if (
|
|
32802
|
+
if (topicInfo.fee_schedule_key?.key && topicInfo.custom_fees?.fixed_fees?.length > 0) {
|
|
32746
32803
|
return {
|
|
32747
32804
|
canSubmit: true,
|
|
32748
32805
|
requiresFee: true,
|
|
@@ -32817,9 +32874,9 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32817
32874
|
async registerAgentWithGuardedRegistry(accountId, inboundTopicId, network = this.network, options) {
|
|
32818
32875
|
try {
|
|
32819
32876
|
this.logger.info("Registering agent with guarded registry");
|
|
32820
|
-
const maxAttempts =
|
|
32821
|
-
const delayMs =
|
|
32822
|
-
const progressCallback = options
|
|
32877
|
+
const maxAttempts = options?.maxAttempts ?? 60;
|
|
32878
|
+
const delayMs = options?.delayMs ?? 2e3;
|
|
32879
|
+
const progressCallback = options?.progressCallback;
|
|
32823
32880
|
if (progressCallback) {
|
|
32824
32881
|
progressCallback({
|
|
32825
32882
|
stage: "preparing",
|
|
@@ -33065,27 +33122,39 @@ class AgentBuilder {
|
|
|
33065
33122
|
return this.config;
|
|
33066
33123
|
}
|
|
33067
33124
|
}
|
|
33125
|
+
const isBrowser$1 = typeof window !== "undefined";
|
|
33068
33126
|
class BrowserHCSClient extends HCS10BaseClient {
|
|
33069
33127
|
constructor(config) {
|
|
33070
33128
|
super({
|
|
33071
33129
|
network: config.network,
|
|
33072
33130
|
logLevel: config.logLevel
|
|
33073
33131
|
});
|
|
33074
|
-
this.
|
|
33132
|
+
this.hcs11Client = null;
|
|
33075
33133
|
this.hwc = config.hwc;
|
|
33134
|
+
this.guardedRegistryBaseUrl = config.guardedRegistryBaseUrl || "https://moonscape.tech";
|
|
33076
33135
|
this.logger = Logger$1.getInstance({
|
|
33077
33136
|
level: config.logLevel || "info",
|
|
33078
33137
|
module: "HCS-Browser"
|
|
33079
33138
|
});
|
|
33080
|
-
|
|
33081
|
-
|
|
33082
|
-
|
|
33083
|
-
|
|
33084
|
-
|
|
33085
|
-
|
|
33086
|
-
|
|
33087
|
-
|
|
33088
|
-
|
|
33139
|
+
if (isBrowser$1) {
|
|
33140
|
+
try {
|
|
33141
|
+
const { accountId, signer } = this.getAccountAndSigner();
|
|
33142
|
+
this.hcs11Client = new HCS11Client({
|
|
33143
|
+
network: config.network,
|
|
33144
|
+
auth: {
|
|
33145
|
+
operatorId: accountId,
|
|
33146
|
+
signer
|
|
33147
|
+
},
|
|
33148
|
+
logLevel: config.logLevel
|
|
33149
|
+
});
|
|
33150
|
+
} catch (err) {
|
|
33151
|
+
this.logger.warn(`Failed to initialize HCS11Client: ${err}`);
|
|
33152
|
+
}
|
|
33153
|
+
} else {
|
|
33154
|
+
this.logger.error(
|
|
33155
|
+
"BrowserHCSClient initialized in server environment - browser-specific features will not be available. Use HCS10Client instead."
|
|
33156
|
+
);
|
|
33157
|
+
}
|
|
33089
33158
|
}
|
|
33090
33159
|
async sendMessage(connectionTopicId, operatorId, data, memo) {
|
|
33091
33160
|
this.logger.info("Sending message");
|
|
@@ -33096,10 +33165,37 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33096
33165
|
data,
|
|
33097
33166
|
m: memo
|
|
33098
33167
|
};
|
|
33168
|
+
const payloadString = JSON.stringify(payload);
|
|
33169
|
+
const isLargePayload = Buffer2.from(payloadString).length > 1e3;
|
|
33170
|
+
if (isLargePayload) {
|
|
33171
|
+
this.logger.info(
|
|
33172
|
+
"Message payload exceeds 1000 bytes, storing via inscription"
|
|
33173
|
+
);
|
|
33174
|
+
try {
|
|
33175
|
+
const contentBuffer = Buffer2.from(data);
|
|
33176
|
+
const fileName = `message-${Date.now()}.json`;
|
|
33177
|
+
const inscriptionResult = await this.inscribeFile(
|
|
33178
|
+
contentBuffer,
|
|
33179
|
+
fileName
|
|
33180
|
+
);
|
|
33181
|
+
if (inscriptionResult?.topic_id) {
|
|
33182
|
+
payload.data = `hcs://1/${inscriptionResult.topic_id}`;
|
|
33183
|
+
this.logger.info(
|
|
33184
|
+
`Large message inscribed with topic ID: ${inscriptionResult.topic_id}`
|
|
33185
|
+
);
|
|
33186
|
+
} else {
|
|
33187
|
+
throw new Error("Failed to inscribe large message content");
|
|
33188
|
+
}
|
|
33189
|
+
} catch (error) {
|
|
33190
|
+
this.logger.error("Error inscribing large message:", error);
|
|
33191
|
+
throw new Error(
|
|
33192
|
+
`Failed to handle large message: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
33193
|
+
);
|
|
33194
|
+
}
|
|
33195
|
+
}
|
|
33099
33196
|
await this.submitPayload(connectionTopicId, payload);
|
|
33100
33197
|
}
|
|
33101
33198
|
async submitConnectionRequest(inboundTopicId, requestingAccountId, operatorId, memo) {
|
|
33102
|
-
var _a, _b;
|
|
33103
33199
|
this.logger.info("Submitting connection request");
|
|
33104
33200
|
const connectionRequestMessage = {
|
|
33105
33201
|
p: "hcs-10",
|
|
@@ -33118,7 +33214,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33118
33214
|
const outboundTopic = await this.retrieveOutboundConnectTopic(
|
|
33119
33215
|
requestingAccountId
|
|
33120
33216
|
);
|
|
33121
|
-
if (!
|
|
33217
|
+
if (!outboundTopic?.outboundTopic) {
|
|
33122
33218
|
this.logger.error(
|
|
33123
33219
|
`Failed to retrieve outbound topic for account ID: ${requestingAccountId}`
|
|
33124
33220
|
);
|
|
@@ -33129,7 +33225,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33129
33225
|
this.logger.info(
|
|
33130
33226
|
`Retrieved outbound topic ID: ${outboundTopic.outboundTopic} for account ID: ${requestingAccountId}`
|
|
33131
33227
|
);
|
|
33132
|
-
const responseSequenceNumber =
|
|
33228
|
+
const responseSequenceNumber = response?.result?.topicSequenceNumber?.toNumber();
|
|
33133
33229
|
if (!responseSequenceNumber) {
|
|
33134
33230
|
throw new Error("Failed to get response sequence number");
|
|
33135
33231
|
}
|
|
@@ -33189,7 +33285,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33189
33285
|
throw new Error(receipt.error);
|
|
33190
33286
|
}
|
|
33191
33287
|
const result = receipt.result;
|
|
33192
|
-
if (!
|
|
33288
|
+
if (!result?.topicId) {
|
|
33193
33289
|
this.logger.error("Failed to create topic: topicId is null");
|
|
33194
33290
|
throw new Error("Failed to create topic: topicId is null");
|
|
33195
33291
|
}
|
|
@@ -33210,7 +33306,6 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33210
33306
|
};
|
|
33211
33307
|
}
|
|
33212
33308
|
async confirmConnection(inboundTopicId, connectionTopicId, connectedAccountId, connectionId, operatorId, memo) {
|
|
33213
|
-
var _a;
|
|
33214
33309
|
this.logger.info("Confirming connection");
|
|
33215
33310
|
const payload = {
|
|
33216
33311
|
p: "hcs-10",
|
|
@@ -33225,7 +33320,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33225
33320
|
inboundTopicId,
|
|
33226
33321
|
payload
|
|
33227
33322
|
);
|
|
33228
|
-
if (!
|
|
33323
|
+
if (!transactionResponse?.result?.topicSequenceNumber) {
|
|
33229
33324
|
this.logger.error(
|
|
33230
33325
|
"Failed to confirm connection: sequence number is null"
|
|
33231
33326
|
);
|
|
@@ -33332,7 +33427,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33332
33427
|
}
|
|
33333
33428
|
async createAndRegisterAgent(name, description, capabilities, metadata, pfpBuffer, pfpFileName, network, existingPfpTopicId, options) {
|
|
33334
33429
|
try {
|
|
33335
|
-
const progressCallback = options
|
|
33430
|
+
const progressCallback = options?.progressCallback;
|
|
33336
33431
|
const reportProgress = (stage, message, percent, details) => {
|
|
33337
33432
|
if (progressCallback) {
|
|
33338
33433
|
try {
|
|
@@ -33381,8 +33476,8 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33381
33476
|
progress.details
|
|
33382
33477
|
);
|
|
33383
33478
|
},
|
|
33384
|
-
maxAttempts: options
|
|
33385
|
-
delayMs: options
|
|
33479
|
+
maxAttempts: options?.maxAttempts,
|
|
33480
|
+
delayMs: options?.delayMs
|
|
33386
33481
|
}
|
|
33387
33482
|
);
|
|
33388
33483
|
if (!registrationResult.success) {
|
|
@@ -33411,9 +33506,9 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33411
33506
|
async registerAgentWithGuardedRegistry(accountId, inboundTopicId, network = this.network, options) {
|
|
33412
33507
|
try {
|
|
33413
33508
|
this.logger.info("Registering agent with guarded registry");
|
|
33414
|
-
const maxAttempts =
|
|
33415
|
-
const delayMs =
|
|
33416
|
-
const progressCallback = options
|
|
33509
|
+
const maxAttempts = options?.maxAttempts ?? 60;
|
|
33510
|
+
const delayMs = options?.delayMs ?? 2e3;
|
|
33511
|
+
const progressCallback = options?.progressCallback;
|
|
33417
33512
|
const reportProgress = (stage, message, percent, details) => {
|
|
33418
33513
|
if (progressCallback) {
|
|
33419
33514
|
try {
|
|
@@ -33490,6 +33585,13 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33490
33585
|
}
|
|
33491
33586
|
async storeHCS11Profile(agentName, agentDescription, inboundTopicId, outboundTopicId, capabilities = [], metadata = {}, pfpBuffer, pfpFileName, existingPfpTopicId) {
|
|
33492
33587
|
try {
|
|
33588
|
+
if (!this.hcs11Client) {
|
|
33589
|
+
return {
|
|
33590
|
+
profileTopicId: "",
|
|
33591
|
+
success: false,
|
|
33592
|
+
error: "HCS11Client is not available in this environment"
|
|
33593
|
+
};
|
|
33594
|
+
}
|
|
33493
33595
|
let pfpTopicId = existingPfpTopicId;
|
|
33494
33596
|
if (!pfpTopicId && pfpBuffer && pfpFileName) {
|
|
33495
33597
|
const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName);
|
|
@@ -33630,7 +33732,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33630
33732
|
};
|
|
33631
33733
|
}
|
|
33632
33734
|
const result = transactionResponse.result;
|
|
33633
|
-
if (!
|
|
33735
|
+
if (!result?.topicId) {
|
|
33634
33736
|
this.logger.error("Failed to create topic: topicId is null");
|
|
33635
33737
|
return {
|
|
33636
33738
|
success: false,
|
|
@@ -33706,6 +33808,13 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33706
33808
|
*/
|
|
33707
33809
|
async inscribePfp(buffer2, fileName) {
|
|
33708
33810
|
try {
|
|
33811
|
+
if (!this.hcs11Client) {
|
|
33812
|
+
return {
|
|
33813
|
+
pfpTopicId: "",
|
|
33814
|
+
success: false,
|
|
33815
|
+
error: "HCS11Client is not available in this environment"
|
|
33816
|
+
};
|
|
33817
|
+
}
|
|
33709
33818
|
this.logger.info("Inscribing profile picture using HCS-11 client");
|
|
33710
33819
|
const imageResult = await this.hcs11Client.inscribeImage(
|
|
33711
33820
|
buffer2,
|
|
@@ -33738,6 +33847,8 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33738
33847
|
}
|
|
33739
33848
|
}
|
|
33740
33849
|
}
|
|
33850
|
+
const isBrowser = typeof window !== "undefined";
|
|
33851
|
+
const isServer = !isBrowser;
|
|
33741
33852
|
export {
|
|
33742
33853
|
AIAgentCapability,
|
|
33743
33854
|
AIAgentType,
|
|
@@ -33766,6 +33877,8 @@ export {
|
|
|
33766
33877
|
capabilityNameToCapabilityMap,
|
|
33767
33878
|
inscribe,
|
|
33768
33879
|
inscribeWithSigner,
|
|
33880
|
+
isBrowser,
|
|
33881
|
+
isServer,
|
|
33769
33882
|
retrieveInscription,
|
|
33770
33883
|
sleep
|
|
33771
33884
|
};
|