@hashgraphonline/standards-sdk 0.0.32 → 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/index.d.ts +2 -0
- package/dist/es/services/mirror-node.d.ts +1 -0
- package/dist/es/standards-sdk.es.js +152 -127
- package/dist/es/standards-sdk.es.js.map +1 -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
|
}
|
|
@@ -15316,6 +15309,7 @@ class HederaMirrorNode {
|
|
|
15316
15309
|
this.network = network;
|
|
15317
15310
|
this.baseUrl = this.getMirrorNodeUrl();
|
|
15318
15311
|
this.logger = logger;
|
|
15312
|
+
this.isServerEnvironment = typeof window === "undefined";
|
|
15319
15313
|
}
|
|
15320
15314
|
getMirrorNodeUrl() {
|
|
15321
15315
|
return this.network === "mainnet" ? "https://mainnet-public.mirrornode.hedera.com" : "https://testnet.mirrornode.hedera.com";
|
|
@@ -15381,7 +15375,6 @@ class HederaMirrorNode {
|
|
|
15381
15375
|
}
|
|
15382
15376
|
}
|
|
15383
15377
|
async getTopicMessages(topicId) {
|
|
15384
|
-
var _a;
|
|
15385
15378
|
if (this.logger) {
|
|
15386
15379
|
this.logger.info(`Querying messages for topic ${topicId}`);
|
|
15387
15380
|
}
|
|
@@ -15392,26 +15385,45 @@ class HederaMirrorNode {
|
|
|
15392
15385
|
const response = await axios.get(nextUrl);
|
|
15393
15386
|
const data = response.data;
|
|
15394
15387
|
if (data.messages && data.messages.length > 0) {
|
|
15395
|
-
data.messages
|
|
15396
|
-
const messageContent = Buffer2.from(msg.message, "base64").toString(
|
|
15397
|
-
"utf8"
|
|
15398
|
-
);
|
|
15399
|
-
let messageJson;
|
|
15388
|
+
for (const message of data.messages) {
|
|
15400
15389
|
try {
|
|
15401
|
-
|
|
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);
|
|
15402
15419
|
} catch (error) {
|
|
15403
15420
|
if (this.logger) {
|
|
15404
|
-
this.logger.error(
|
|
15405
|
-
`Invalid JSON message content: ${messageContent}`
|
|
15406
|
-
);
|
|
15421
|
+
this.logger.error(`Error processing message: ${error.message}`);
|
|
15407
15422
|
}
|
|
15408
|
-
return;
|
|
15409
15423
|
}
|
|
15410
|
-
|
|
15411
|
-
messages.push(messageJson);
|
|
15412
|
-
});
|
|
15424
|
+
}
|
|
15413
15425
|
}
|
|
15414
|
-
nextUrl =
|
|
15426
|
+
nextUrl = data.links?.next ? `${this.baseUrl}${data.links.next}` : "";
|
|
15415
15427
|
} catch (error) {
|
|
15416
15428
|
if (this.logger) {
|
|
15417
15429
|
this.logger.error(`Error querying topic messages: ${error.message}`);
|
|
@@ -15566,7 +15578,6 @@ class Registration {
|
|
|
15566
15578
|
return false;
|
|
15567
15579
|
}
|
|
15568
15580
|
async executeRegistration(accountId, inboundTopicId, network, baseUrl, logger, metadata = { tags: [] }) {
|
|
15569
|
-
var _a;
|
|
15570
15581
|
try {
|
|
15571
15582
|
if (logger) {
|
|
15572
15583
|
logger.info("Registering agent with guarded registry");
|
|
@@ -15589,7 +15600,7 @@ class Registration {
|
|
|
15589
15600
|
});
|
|
15590
15601
|
const data = await response.json();
|
|
15591
15602
|
if (!response.ok) {
|
|
15592
|
-
if (
|
|
15603
|
+
if (data.details?.length > 0) {
|
|
15593
15604
|
return {
|
|
15594
15605
|
validationErrors: data.details,
|
|
15595
15606
|
error: data.error || "Validation failed",
|
|
@@ -15619,10 +15630,9 @@ class Registration {
|
|
|
15619
15630
|
}
|
|
15620
15631
|
}
|
|
15621
15632
|
async findRegistrations(options = {}, baseUrl = "https://hcs-10.hashgraphonline.com") {
|
|
15622
|
-
var _a;
|
|
15623
15633
|
try {
|
|
15624
15634
|
const queryParams = new URLSearchParams();
|
|
15625
|
-
|
|
15635
|
+
options.tags?.forEach((tag) => queryParams.append("tags", tag));
|
|
15626
15636
|
if (options.accountId) {
|
|
15627
15637
|
queryParams.append("accountId", options.accountId);
|
|
15628
15638
|
}
|
|
@@ -27146,7 +27156,6 @@ var InboundTopicType = /* @__PURE__ */ ((InboundTopicType2) => {
|
|
|
27146
27156
|
return InboundTopicType2;
|
|
27147
27157
|
})(InboundTopicType || {});
|
|
27148
27158
|
async function inscribe(input, clientConfig, options, existingSDK) {
|
|
27149
|
-
var _a, _b;
|
|
27150
27159
|
const logger = Logger$1.getInstance({
|
|
27151
27160
|
module: "Inscriber",
|
|
27152
27161
|
...options.logging
|
|
@@ -27222,8 +27231,8 @@ async function inscribe(input, clientConfig, options, existingSDK) {
|
|
|
27222
27231
|
}
|
|
27223
27232
|
if (options.mode === "hashinal") {
|
|
27224
27233
|
request.metadataObject = options.metadata;
|
|
27225
|
-
request.creator =
|
|
27226
|
-
request.description =
|
|
27234
|
+
request.creator = options.metadata?.creator || clientConfig.accountId;
|
|
27235
|
+
request.description = options.metadata?.description;
|
|
27227
27236
|
if (options.jsonFileURL) {
|
|
27228
27237
|
request.jsonFileURL = options.jsonFileURL;
|
|
27229
27238
|
}
|
|
@@ -27272,7 +27281,6 @@ async function inscribe(input, clientConfig, options, existingSDK) {
|
|
|
27272
27281
|
}
|
|
27273
27282
|
}
|
|
27274
27283
|
async function inscribeWithSigner(input, signer, options, existingSDK) {
|
|
27275
|
-
var _a, _b;
|
|
27276
27284
|
const logger = Logger$1.getInstance({
|
|
27277
27285
|
module: "Inscriber",
|
|
27278
27286
|
...options.logging
|
|
@@ -27350,8 +27358,8 @@ async function inscribeWithSigner(input, signer, options, existingSDK) {
|
|
|
27350
27358
|
}
|
|
27351
27359
|
if (options.mode === "hashinal") {
|
|
27352
27360
|
request.metadataObject = options.metadata;
|
|
27353
|
-
request.creator =
|
|
27354
|
-
request.description =
|
|
27361
|
+
request.creator = options.metadata?.creator || accountId;
|
|
27362
|
+
request.description = options.metadata?.description;
|
|
27355
27363
|
if (options.jsonFileURL) {
|
|
27356
27364
|
request.jsonFileURL = options.jsonFileURL;
|
|
27357
27365
|
}
|
|
@@ -31700,15 +31708,15 @@ class HCS11Client {
|
|
|
31700
31708
|
version: "1.0",
|
|
31701
31709
|
type: 0,
|
|
31702
31710
|
display_name: displayName,
|
|
31703
|
-
alias: options
|
|
31704
|
-
bio: options
|
|
31705
|
-
socials: options
|
|
31706
|
-
profileImage: options
|
|
31707
|
-
language: options
|
|
31708
|
-
timezone: options
|
|
31709
|
-
properties: options
|
|
31710
|
-
inboundTopicId: options
|
|
31711
|
-
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
|
|
31712
31720
|
};
|
|
31713
31721
|
}
|
|
31714
31722
|
createAIAgentProfile(displayName, agentType, capabilities, model, options) {
|
|
@@ -31716,18 +31724,18 @@ class HCS11Client {
|
|
|
31716
31724
|
version: "1.0",
|
|
31717
31725
|
type: 1,
|
|
31718
31726
|
display_name: displayName,
|
|
31719
|
-
alias: options
|
|
31720
|
-
bio: options
|
|
31721
|
-
socials: options
|
|
31722
|
-
profileImage: options
|
|
31723
|
-
properties: options
|
|
31724
|
-
inboundTopicId: options
|
|
31725
|
-
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,
|
|
31726
31734
|
aiAgent: {
|
|
31727
31735
|
type: agentType,
|
|
31728
31736
|
capabilities,
|
|
31729
31737
|
model,
|
|
31730
|
-
creator: options
|
|
31738
|
+
creator: options?.creator
|
|
31731
31739
|
}
|
|
31732
31740
|
});
|
|
31733
31741
|
if (!validation.valid) {
|
|
@@ -31739,18 +31747,18 @@ class HCS11Client {
|
|
|
31739
31747
|
version: "1.0",
|
|
31740
31748
|
type: 1,
|
|
31741
31749
|
display_name: displayName,
|
|
31742
|
-
alias: options
|
|
31743
|
-
bio: options
|
|
31744
|
-
socials: options
|
|
31745
|
-
profileImage: options
|
|
31746
|
-
properties: options
|
|
31747
|
-
inboundTopicId: options
|
|
31748
|
-
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,
|
|
31749
31757
|
aiAgent: {
|
|
31750
31758
|
type: agentType,
|
|
31751
31759
|
capabilities,
|
|
31752
31760
|
model,
|
|
31753
|
-
creator: options
|
|
31761
|
+
creator: options?.creator
|
|
31754
31762
|
}
|
|
31755
31763
|
};
|
|
31756
31764
|
}
|
|
@@ -31760,13 +31768,12 @@ class HCS11Client {
|
|
|
31760
31768
|
return { valid: true, errors: [] };
|
|
31761
31769
|
}
|
|
31762
31770
|
const formattedErrors = result.error.errors.map((err) => {
|
|
31763
|
-
var _a;
|
|
31764
31771
|
const path = err.path.join(".");
|
|
31765
31772
|
let message = err.message;
|
|
31766
31773
|
if (err.code === "invalid_type") {
|
|
31767
31774
|
message = `Expected ${err.expected}, got ${err.received}`;
|
|
31768
31775
|
} else if (err.code === "invalid_enum_value") {
|
|
31769
|
-
const validOptions =
|
|
31776
|
+
const validOptions = err.options?.join(", ");
|
|
31770
31777
|
message = `Invalid value. Valid options are: ${validOptions}`;
|
|
31771
31778
|
} else if (err.code === "too_small" && err.type === "string") {
|
|
31772
31779
|
message = "Cannot be empty";
|
|
@@ -32185,11 +32192,10 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32185
32192
|
* @returns Object with topic IDs
|
|
32186
32193
|
*/
|
|
32187
32194
|
async createAgent(builder) {
|
|
32188
|
-
var _a;
|
|
32189
32195
|
const config = builder.build();
|
|
32190
32196
|
const outboundTopicId = await this.createTopic("hcs-10:0:60:1", true, true);
|
|
32191
32197
|
this.logger.info(`Created new outbound topic ID: ${outboundTopicId}`);
|
|
32192
|
-
const accountId =
|
|
32198
|
+
const accountId = this.client.operatorAccountId?.toString();
|
|
32193
32199
|
if (!accountId) {
|
|
32194
32200
|
throw new Error("Failed to retrieve operator account ID");
|
|
32195
32201
|
}
|
|
@@ -32355,10 +32361,7 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32355
32361
|
if (exemptAccountIds.length > 0) {
|
|
32356
32362
|
const uniqueExemptAccountIds = Array.from(new Set(exemptAccountIds));
|
|
32357
32363
|
const filteredExemptAccounts = uniqueExemptAccountIds.filter(
|
|
32358
|
-
(account) =>
|
|
32359
|
-
var _a;
|
|
32360
|
-
return account !== ((_a = this.client.operatorAccountId) == null ? void 0 : _a.toString());
|
|
32361
|
-
}
|
|
32364
|
+
(account) => account !== this.client.operatorAccountId?.toString()
|
|
32362
32365
|
);
|
|
32363
32366
|
let exemptKeys = [];
|
|
32364
32367
|
if (filteredExemptAccounts.length > 0) {
|
|
@@ -32389,12 +32392,11 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32389
32392
|
* @returns Response with connection details
|
|
32390
32393
|
*/
|
|
32391
32394
|
async handleConnectionRequest(inboundTopicId, requestingAccountId, connectionRequestId, connectionFeeConfig) {
|
|
32392
|
-
var _a;
|
|
32393
32395
|
const memo = `hcs-10:${inboundTopicId}:${connectionRequestId}`;
|
|
32394
32396
|
this.logger.info(
|
|
32395
32397
|
`Handling connection request ${connectionRequestId} from ${requestingAccountId}`
|
|
32396
32398
|
);
|
|
32397
|
-
const accountId =
|
|
32399
|
+
const accountId = this.getClient().operatorAccountId?.toString();
|
|
32398
32400
|
if (!accountId) {
|
|
32399
32401
|
throw new Error("Failed to retrieve operator account ID");
|
|
32400
32402
|
}
|
|
@@ -32448,7 +32450,6 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32448
32450
|
};
|
|
32449
32451
|
}
|
|
32450
32452
|
async confirmConnection(inboundTopicId, connectionTopicId, connectedAccountId, connectionId, operatorId, memo, submitKey) {
|
|
32451
|
-
var _a;
|
|
32452
32453
|
this.logger.info(`Confirming connection with ID ${connectionId}`);
|
|
32453
32454
|
const payload = {
|
|
32454
32455
|
p: "hcs-10",
|
|
@@ -32460,7 +32461,7 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32460
32461
|
m: memo
|
|
32461
32462
|
};
|
|
32462
32463
|
const result = await this.submitPayload(inboundTopicId, payload, submitKey);
|
|
32463
|
-
const sequenceNumber =
|
|
32464
|
+
const sequenceNumber = result.topicSequenceNumber?.toNumber();
|
|
32464
32465
|
if (!sequenceNumber) {
|
|
32465
32466
|
throw new ConnectionConfirmationError(
|
|
32466
32467
|
"Failed to confirm connection: sequence number is null"
|
|
@@ -32469,10 +32470,9 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32469
32470
|
return sequenceNumber;
|
|
32470
32471
|
}
|
|
32471
32472
|
async sendMessage(connectionTopicId, operatorId, data, memo, submitKey) {
|
|
32472
|
-
var _a;
|
|
32473
32473
|
const submissionCheck = await this.canSubmitToInboundTopic(
|
|
32474
32474
|
connectionTopicId,
|
|
32475
|
-
|
|
32475
|
+
this.client.operatorAccountId?.toString() || ""
|
|
32476
32476
|
);
|
|
32477
32477
|
const payload = {
|
|
32478
32478
|
p: "hcs-10",
|
|
@@ -32494,7 +32494,7 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32494
32494
|
contentBuffer,
|
|
32495
32495
|
fileName
|
|
32496
32496
|
);
|
|
32497
|
-
if (inscriptionResult
|
|
32497
|
+
if (inscriptionResult?.topic_id) {
|
|
32498
32498
|
payload.data = `hcs://1/${inscriptionResult.topic_id}`;
|
|
32499
32499
|
this.logger.info(
|
|
32500
32500
|
`Large message inscribed with topic ID: ${inscriptionResult.topic_id}`
|
|
@@ -32552,10 +32552,9 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32552
32552
|
return topicId;
|
|
32553
32553
|
}
|
|
32554
32554
|
async submitMessage(topicId, message, submitKey) {
|
|
32555
|
-
var _a;
|
|
32556
32555
|
const submissionCheck = await this.canSubmitToInboundTopic(
|
|
32557
32556
|
topicId,
|
|
32558
|
-
|
|
32557
|
+
this.client.operatorAccountId?.toString() || ""
|
|
32559
32558
|
);
|
|
32560
32559
|
return this.submitPayload(
|
|
32561
32560
|
topicId,
|
|
@@ -32598,7 +32597,6 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32598
32597
|
return receipt;
|
|
32599
32598
|
}
|
|
32600
32599
|
async submitConnectionRequest(inboundTopicId, requestingAccountId, operatorId, memo) {
|
|
32601
|
-
var _a;
|
|
32602
32600
|
const submissionCheck = await this.canSubmitToInboundTopic(
|
|
32603
32601
|
inboundTopicId,
|
|
32604
32602
|
requestingAccountId
|
|
@@ -32625,7 +32623,7 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32625
32623
|
const outboundTopic = await this.retrieveOutboundConnectTopic(
|
|
32626
32624
|
requestingAccountId
|
|
32627
32625
|
);
|
|
32628
|
-
const responseSequenceNumber =
|
|
32626
|
+
const responseSequenceNumber = response.topicSequenceNumber?.toNumber();
|
|
32629
32627
|
if (!responseSequenceNumber) {
|
|
32630
32628
|
throw new Error("Failed to get response sequence number");
|
|
32631
32629
|
}
|
|
@@ -32767,7 +32765,6 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32767
32765
|
* @returns Object with canSubmit, requiresFee, and optional reason
|
|
32768
32766
|
*/
|
|
32769
32767
|
async canSubmitToInboundTopic(topicId, userAccountId) {
|
|
32770
|
-
var _a, _b, _c, _d;
|
|
32771
32768
|
try {
|
|
32772
32769
|
const topicInfo = await this.mirrorNode.getTopicInfo(topicId);
|
|
32773
32770
|
if (!topicInfo) {
|
|
@@ -32777,7 +32774,7 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32777
32774
|
reason: "Topic does not exist"
|
|
32778
32775
|
};
|
|
32779
32776
|
}
|
|
32780
|
-
if (!
|
|
32777
|
+
if (!topicInfo.submit_key?.key) {
|
|
32781
32778
|
return { canSubmit: true, requiresFee: false };
|
|
32782
32779
|
}
|
|
32783
32780
|
try {
|
|
@@ -32802,7 +32799,7 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32802
32799
|
`Key validation error: ${error instanceof Error ? error.message : String(error)}`
|
|
32803
32800
|
);
|
|
32804
32801
|
}
|
|
32805
|
-
if (
|
|
32802
|
+
if (topicInfo.fee_schedule_key?.key && topicInfo.custom_fees?.fixed_fees?.length > 0) {
|
|
32806
32803
|
return {
|
|
32807
32804
|
canSubmit: true,
|
|
32808
32805
|
requiresFee: true,
|
|
@@ -32877,9 +32874,9 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32877
32874
|
async registerAgentWithGuardedRegistry(accountId, inboundTopicId, network = this.network, options) {
|
|
32878
32875
|
try {
|
|
32879
32876
|
this.logger.info("Registering agent with guarded registry");
|
|
32880
|
-
const maxAttempts =
|
|
32881
|
-
const delayMs =
|
|
32882
|
-
const progressCallback = options
|
|
32877
|
+
const maxAttempts = options?.maxAttempts ?? 60;
|
|
32878
|
+
const delayMs = options?.delayMs ?? 2e3;
|
|
32879
|
+
const progressCallback = options?.progressCallback;
|
|
32883
32880
|
if (progressCallback) {
|
|
32884
32881
|
progressCallback({
|
|
32885
32882
|
stage: "preparing",
|
|
@@ -33125,27 +33122,39 @@ class AgentBuilder {
|
|
|
33125
33122
|
return this.config;
|
|
33126
33123
|
}
|
|
33127
33124
|
}
|
|
33125
|
+
const isBrowser$1 = typeof window !== "undefined";
|
|
33128
33126
|
class BrowserHCSClient extends HCS10BaseClient {
|
|
33129
33127
|
constructor(config) {
|
|
33130
33128
|
super({
|
|
33131
33129
|
network: config.network,
|
|
33132
33130
|
logLevel: config.logLevel
|
|
33133
33131
|
});
|
|
33134
|
-
this.
|
|
33132
|
+
this.hcs11Client = null;
|
|
33135
33133
|
this.hwc = config.hwc;
|
|
33134
|
+
this.guardedRegistryBaseUrl = config.guardedRegistryBaseUrl || "https://moonscape.tech";
|
|
33136
33135
|
this.logger = Logger$1.getInstance({
|
|
33137
33136
|
level: config.logLevel || "info",
|
|
33138
33137
|
module: "HCS-Browser"
|
|
33139
33138
|
});
|
|
33140
|
-
|
|
33141
|
-
|
|
33142
|
-
|
|
33143
|
-
|
|
33144
|
-
|
|
33145
|
-
|
|
33146
|
-
|
|
33147
|
-
|
|
33148
|
-
|
|
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
|
+
}
|
|
33149
33158
|
}
|
|
33150
33159
|
async sendMessage(connectionTopicId, operatorId, data, memo) {
|
|
33151
33160
|
this.logger.info("Sending message");
|
|
@@ -33169,7 +33178,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33169
33178
|
contentBuffer,
|
|
33170
33179
|
fileName
|
|
33171
33180
|
);
|
|
33172
|
-
if (inscriptionResult
|
|
33181
|
+
if (inscriptionResult?.topic_id) {
|
|
33173
33182
|
payload.data = `hcs://1/${inscriptionResult.topic_id}`;
|
|
33174
33183
|
this.logger.info(
|
|
33175
33184
|
`Large message inscribed with topic ID: ${inscriptionResult.topic_id}`
|
|
@@ -33187,7 +33196,6 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33187
33196
|
await this.submitPayload(connectionTopicId, payload);
|
|
33188
33197
|
}
|
|
33189
33198
|
async submitConnectionRequest(inboundTopicId, requestingAccountId, operatorId, memo) {
|
|
33190
|
-
var _a, _b;
|
|
33191
33199
|
this.logger.info("Submitting connection request");
|
|
33192
33200
|
const connectionRequestMessage = {
|
|
33193
33201
|
p: "hcs-10",
|
|
@@ -33206,7 +33214,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33206
33214
|
const outboundTopic = await this.retrieveOutboundConnectTopic(
|
|
33207
33215
|
requestingAccountId
|
|
33208
33216
|
);
|
|
33209
|
-
if (!
|
|
33217
|
+
if (!outboundTopic?.outboundTopic) {
|
|
33210
33218
|
this.logger.error(
|
|
33211
33219
|
`Failed to retrieve outbound topic for account ID: ${requestingAccountId}`
|
|
33212
33220
|
);
|
|
@@ -33217,7 +33225,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33217
33225
|
this.logger.info(
|
|
33218
33226
|
`Retrieved outbound topic ID: ${outboundTopic.outboundTopic} for account ID: ${requestingAccountId}`
|
|
33219
33227
|
);
|
|
33220
|
-
const responseSequenceNumber =
|
|
33228
|
+
const responseSequenceNumber = response?.result?.topicSequenceNumber?.toNumber();
|
|
33221
33229
|
if (!responseSequenceNumber) {
|
|
33222
33230
|
throw new Error("Failed to get response sequence number");
|
|
33223
33231
|
}
|
|
@@ -33277,7 +33285,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33277
33285
|
throw new Error(receipt.error);
|
|
33278
33286
|
}
|
|
33279
33287
|
const result = receipt.result;
|
|
33280
|
-
if (!
|
|
33288
|
+
if (!result?.topicId) {
|
|
33281
33289
|
this.logger.error("Failed to create topic: topicId is null");
|
|
33282
33290
|
throw new Error("Failed to create topic: topicId is null");
|
|
33283
33291
|
}
|
|
@@ -33298,7 +33306,6 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33298
33306
|
};
|
|
33299
33307
|
}
|
|
33300
33308
|
async confirmConnection(inboundTopicId, connectionTopicId, connectedAccountId, connectionId, operatorId, memo) {
|
|
33301
|
-
var _a;
|
|
33302
33309
|
this.logger.info("Confirming connection");
|
|
33303
33310
|
const payload = {
|
|
33304
33311
|
p: "hcs-10",
|
|
@@ -33313,7 +33320,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33313
33320
|
inboundTopicId,
|
|
33314
33321
|
payload
|
|
33315
33322
|
);
|
|
33316
|
-
if (!
|
|
33323
|
+
if (!transactionResponse?.result?.topicSequenceNumber) {
|
|
33317
33324
|
this.logger.error(
|
|
33318
33325
|
"Failed to confirm connection: sequence number is null"
|
|
33319
33326
|
);
|
|
@@ -33420,7 +33427,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33420
33427
|
}
|
|
33421
33428
|
async createAndRegisterAgent(name, description, capabilities, metadata, pfpBuffer, pfpFileName, network, existingPfpTopicId, options) {
|
|
33422
33429
|
try {
|
|
33423
|
-
const progressCallback = options
|
|
33430
|
+
const progressCallback = options?.progressCallback;
|
|
33424
33431
|
const reportProgress = (stage, message, percent, details) => {
|
|
33425
33432
|
if (progressCallback) {
|
|
33426
33433
|
try {
|
|
@@ -33469,8 +33476,8 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33469
33476
|
progress.details
|
|
33470
33477
|
);
|
|
33471
33478
|
},
|
|
33472
|
-
maxAttempts: options
|
|
33473
|
-
delayMs: options
|
|
33479
|
+
maxAttempts: options?.maxAttempts,
|
|
33480
|
+
delayMs: options?.delayMs
|
|
33474
33481
|
}
|
|
33475
33482
|
);
|
|
33476
33483
|
if (!registrationResult.success) {
|
|
@@ -33499,9 +33506,9 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33499
33506
|
async registerAgentWithGuardedRegistry(accountId, inboundTopicId, network = this.network, options) {
|
|
33500
33507
|
try {
|
|
33501
33508
|
this.logger.info("Registering agent with guarded registry");
|
|
33502
|
-
const maxAttempts =
|
|
33503
|
-
const delayMs =
|
|
33504
|
-
const progressCallback = options
|
|
33509
|
+
const maxAttempts = options?.maxAttempts ?? 60;
|
|
33510
|
+
const delayMs = options?.delayMs ?? 2e3;
|
|
33511
|
+
const progressCallback = options?.progressCallback;
|
|
33505
33512
|
const reportProgress = (stage, message, percent, details) => {
|
|
33506
33513
|
if (progressCallback) {
|
|
33507
33514
|
try {
|
|
@@ -33578,6 +33585,13 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33578
33585
|
}
|
|
33579
33586
|
async storeHCS11Profile(agentName, agentDescription, inboundTopicId, outboundTopicId, capabilities = [], metadata = {}, pfpBuffer, pfpFileName, existingPfpTopicId) {
|
|
33580
33587
|
try {
|
|
33588
|
+
if (!this.hcs11Client) {
|
|
33589
|
+
return {
|
|
33590
|
+
profileTopicId: "",
|
|
33591
|
+
success: false,
|
|
33592
|
+
error: "HCS11Client is not available in this environment"
|
|
33593
|
+
};
|
|
33594
|
+
}
|
|
33581
33595
|
let pfpTopicId = existingPfpTopicId;
|
|
33582
33596
|
if (!pfpTopicId && pfpBuffer && pfpFileName) {
|
|
33583
33597
|
const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName);
|
|
@@ -33718,7 +33732,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33718
33732
|
};
|
|
33719
33733
|
}
|
|
33720
33734
|
const result = transactionResponse.result;
|
|
33721
|
-
if (!
|
|
33735
|
+
if (!result?.topicId) {
|
|
33722
33736
|
this.logger.error("Failed to create topic: topicId is null");
|
|
33723
33737
|
return {
|
|
33724
33738
|
success: false,
|
|
@@ -33794,6 +33808,13 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33794
33808
|
*/
|
|
33795
33809
|
async inscribePfp(buffer2, fileName) {
|
|
33796
33810
|
try {
|
|
33811
|
+
if (!this.hcs11Client) {
|
|
33812
|
+
return {
|
|
33813
|
+
pfpTopicId: "",
|
|
33814
|
+
success: false,
|
|
33815
|
+
error: "HCS11Client is not available in this environment"
|
|
33816
|
+
};
|
|
33817
|
+
}
|
|
33797
33818
|
this.logger.info("Inscribing profile picture using HCS-11 client");
|
|
33798
33819
|
const imageResult = await this.hcs11Client.inscribeImage(
|
|
33799
33820
|
buffer2,
|
|
@@ -33826,6 +33847,8 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33826
33847
|
}
|
|
33827
33848
|
}
|
|
33828
33849
|
}
|
|
33850
|
+
const isBrowser = typeof window !== "undefined";
|
|
33851
|
+
const isServer = !isBrowser;
|
|
33829
33852
|
export {
|
|
33830
33853
|
AIAgentCapability,
|
|
33831
33854
|
AIAgentType,
|
|
@@ -33854,6 +33877,8 @@ export {
|
|
|
33854
33877
|
capabilityNameToCapabilityMap,
|
|
33855
33878
|
inscribe,
|
|
33856
33879
|
inscribeWithSigner,
|
|
33880
|
+
isBrowser,
|
|
33881
|
+
isServer,
|
|
33857
33882
|
retrieveInscription,
|
|
33858
33883
|
sleep
|
|
33859
33884
|
};
|