@hashgraphonline/standards-sdk 0.0.32 → 0.0.34
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-11/index.d.ts +2 -3
- 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 +156 -128
- package/dist/es/standards-sdk.es.js.map +1 -1
- package/dist/umd/hcs-11/index.d.ts +2 -3
- 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 +5 -5
- 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";
|
|
@@ -31861,7 +31868,10 @@ class HCS11Client {
|
|
|
31861
31868
|
network: this.network
|
|
31862
31869
|
},
|
|
31863
31870
|
inscriptionOptions
|
|
31864
|
-
) :
|
|
31871
|
+
) : (
|
|
31872
|
+
// @ts-ignore
|
|
31873
|
+
await inscribeWithSigner(input, this.auth.signer, inscriptionOptions)
|
|
31874
|
+
);
|
|
31865
31875
|
if (!inscriptionResponse.confirmed || !inscriptionResponse.inscription.topic_id) {
|
|
31866
31876
|
return {
|
|
31867
31877
|
profileTopicId: "",
|
|
@@ -32185,11 +32195,10 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32185
32195
|
* @returns Object with topic IDs
|
|
32186
32196
|
*/
|
|
32187
32197
|
async createAgent(builder) {
|
|
32188
|
-
var _a;
|
|
32189
32198
|
const config = builder.build();
|
|
32190
32199
|
const outboundTopicId = await this.createTopic("hcs-10:0:60:1", true, true);
|
|
32191
32200
|
this.logger.info(`Created new outbound topic ID: ${outboundTopicId}`);
|
|
32192
|
-
const accountId =
|
|
32201
|
+
const accountId = this.client.operatorAccountId?.toString();
|
|
32193
32202
|
if (!accountId) {
|
|
32194
32203
|
throw new Error("Failed to retrieve operator account ID");
|
|
32195
32204
|
}
|
|
@@ -32355,10 +32364,7 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32355
32364
|
if (exemptAccountIds.length > 0) {
|
|
32356
32365
|
const uniqueExemptAccountIds = Array.from(new Set(exemptAccountIds));
|
|
32357
32366
|
const filteredExemptAccounts = uniqueExemptAccountIds.filter(
|
|
32358
|
-
(account) =>
|
|
32359
|
-
var _a;
|
|
32360
|
-
return account !== ((_a = this.client.operatorAccountId) == null ? void 0 : _a.toString());
|
|
32361
|
-
}
|
|
32367
|
+
(account) => account !== this.client.operatorAccountId?.toString()
|
|
32362
32368
|
);
|
|
32363
32369
|
let exemptKeys = [];
|
|
32364
32370
|
if (filteredExemptAccounts.length > 0) {
|
|
@@ -32389,12 +32395,11 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32389
32395
|
* @returns Response with connection details
|
|
32390
32396
|
*/
|
|
32391
32397
|
async handleConnectionRequest(inboundTopicId, requestingAccountId, connectionRequestId, connectionFeeConfig) {
|
|
32392
|
-
var _a;
|
|
32393
32398
|
const memo = `hcs-10:${inboundTopicId}:${connectionRequestId}`;
|
|
32394
32399
|
this.logger.info(
|
|
32395
32400
|
`Handling connection request ${connectionRequestId} from ${requestingAccountId}`
|
|
32396
32401
|
);
|
|
32397
|
-
const accountId =
|
|
32402
|
+
const accountId = this.getClient().operatorAccountId?.toString();
|
|
32398
32403
|
if (!accountId) {
|
|
32399
32404
|
throw new Error("Failed to retrieve operator account ID");
|
|
32400
32405
|
}
|
|
@@ -32448,7 +32453,6 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32448
32453
|
};
|
|
32449
32454
|
}
|
|
32450
32455
|
async confirmConnection(inboundTopicId, connectionTopicId, connectedAccountId, connectionId, operatorId, memo, submitKey) {
|
|
32451
|
-
var _a;
|
|
32452
32456
|
this.logger.info(`Confirming connection with ID ${connectionId}`);
|
|
32453
32457
|
const payload = {
|
|
32454
32458
|
p: "hcs-10",
|
|
@@ -32460,7 +32464,7 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32460
32464
|
m: memo
|
|
32461
32465
|
};
|
|
32462
32466
|
const result = await this.submitPayload(inboundTopicId, payload, submitKey);
|
|
32463
|
-
const sequenceNumber =
|
|
32467
|
+
const sequenceNumber = result.topicSequenceNumber?.toNumber();
|
|
32464
32468
|
if (!sequenceNumber) {
|
|
32465
32469
|
throw new ConnectionConfirmationError(
|
|
32466
32470
|
"Failed to confirm connection: sequence number is null"
|
|
@@ -32469,10 +32473,9 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32469
32473
|
return sequenceNumber;
|
|
32470
32474
|
}
|
|
32471
32475
|
async sendMessage(connectionTopicId, operatorId, data, memo, submitKey) {
|
|
32472
|
-
var _a;
|
|
32473
32476
|
const submissionCheck = await this.canSubmitToInboundTopic(
|
|
32474
32477
|
connectionTopicId,
|
|
32475
|
-
|
|
32478
|
+
this.client.operatorAccountId?.toString() || ""
|
|
32476
32479
|
);
|
|
32477
32480
|
const payload = {
|
|
32478
32481
|
p: "hcs-10",
|
|
@@ -32494,7 +32497,7 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32494
32497
|
contentBuffer,
|
|
32495
32498
|
fileName
|
|
32496
32499
|
);
|
|
32497
|
-
if (inscriptionResult
|
|
32500
|
+
if (inscriptionResult?.topic_id) {
|
|
32498
32501
|
payload.data = `hcs://1/${inscriptionResult.topic_id}`;
|
|
32499
32502
|
this.logger.info(
|
|
32500
32503
|
`Large message inscribed with topic ID: ${inscriptionResult.topic_id}`
|
|
@@ -32552,10 +32555,9 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32552
32555
|
return topicId;
|
|
32553
32556
|
}
|
|
32554
32557
|
async submitMessage(topicId, message, submitKey) {
|
|
32555
|
-
var _a;
|
|
32556
32558
|
const submissionCheck = await this.canSubmitToInboundTopic(
|
|
32557
32559
|
topicId,
|
|
32558
|
-
|
|
32560
|
+
this.client.operatorAccountId?.toString() || ""
|
|
32559
32561
|
);
|
|
32560
32562
|
return this.submitPayload(
|
|
32561
32563
|
topicId,
|
|
@@ -32598,7 +32600,6 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32598
32600
|
return receipt;
|
|
32599
32601
|
}
|
|
32600
32602
|
async submitConnectionRequest(inboundTopicId, requestingAccountId, operatorId, memo) {
|
|
32601
|
-
var _a;
|
|
32602
32603
|
const submissionCheck = await this.canSubmitToInboundTopic(
|
|
32603
32604
|
inboundTopicId,
|
|
32604
32605
|
requestingAccountId
|
|
@@ -32625,7 +32626,7 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32625
32626
|
const outboundTopic = await this.retrieveOutboundConnectTopic(
|
|
32626
32627
|
requestingAccountId
|
|
32627
32628
|
);
|
|
32628
|
-
const responseSequenceNumber =
|
|
32629
|
+
const responseSequenceNumber = response.topicSequenceNumber?.toNumber();
|
|
32629
32630
|
if (!responseSequenceNumber) {
|
|
32630
32631
|
throw new Error("Failed to get response sequence number");
|
|
32631
32632
|
}
|
|
@@ -32767,7 +32768,6 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32767
32768
|
* @returns Object with canSubmit, requiresFee, and optional reason
|
|
32768
32769
|
*/
|
|
32769
32770
|
async canSubmitToInboundTopic(topicId, userAccountId) {
|
|
32770
|
-
var _a, _b, _c, _d;
|
|
32771
32771
|
try {
|
|
32772
32772
|
const topicInfo = await this.mirrorNode.getTopicInfo(topicId);
|
|
32773
32773
|
if (!topicInfo) {
|
|
@@ -32777,7 +32777,7 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32777
32777
|
reason: "Topic does not exist"
|
|
32778
32778
|
};
|
|
32779
32779
|
}
|
|
32780
|
-
if (!
|
|
32780
|
+
if (!topicInfo.submit_key?.key) {
|
|
32781
32781
|
return { canSubmit: true, requiresFee: false };
|
|
32782
32782
|
}
|
|
32783
32783
|
try {
|
|
@@ -32802,7 +32802,7 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32802
32802
|
`Key validation error: ${error instanceof Error ? error.message : String(error)}`
|
|
32803
32803
|
);
|
|
32804
32804
|
}
|
|
32805
|
-
if (
|
|
32805
|
+
if (topicInfo.fee_schedule_key?.key && topicInfo.custom_fees?.fixed_fees?.length > 0) {
|
|
32806
32806
|
return {
|
|
32807
32807
|
canSubmit: true,
|
|
32808
32808
|
requiresFee: true,
|
|
@@ -32877,9 +32877,9 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
32877
32877
|
async registerAgentWithGuardedRegistry(accountId, inboundTopicId, network = this.network, options) {
|
|
32878
32878
|
try {
|
|
32879
32879
|
this.logger.info("Registering agent with guarded registry");
|
|
32880
|
-
const maxAttempts =
|
|
32881
|
-
const delayMs =
|
|
32882
|
-
const progressCallback = options
|
|
32880
|
+
const maxAttempts = options?.maxAttempts ?? 60;
|
|
32881
|
+
const delayMs = options?.delayMs ?? 2e3;
|
|
32882
|
+
const progressCallback = options?.progressCallback;
|
|
32883
32883
|
if (progressCallback) {
|
|
32884
32884
|
progressCallback({
|
|
32885
32885
|
stage: "preparing",
|
|
@@ -33125,27 +33125,39 @@ class AgentBuilder {
|
|
|
33125
33125
|
return this.config;
|
|
33126
33126
|
}
|
|
33127
33127
|
}
|
|
33128
|
+
const isBrowser$1 = typeof window !== "undefined";
|
|
33128
33129
|
class BrowserHCSClient extends HCS10BaseClient {
|
|
33129
33130
|
constructor(config) {
|
|
33130
33131
|
super({
|
|
33131
33132
|
network: config.network,
|
|
33132
33133
|
logLevel: config.logLevel
|
|
33133
33134
|
});
|
|
33134
|
-
this.
|
|
33135
|
+
this.hcs11Client = null;
|
|
33135
33136
|
this.hwc = config.hwc;
|
|
33137
|
+
this.guardedRegistryBaseUrl = config.guardedRegistryBaseUrl || "https://moonscape.tech";
|
|
33136
33138
|
this.logger = Logger$1.getInstance({
|
|
33137
33139
|
level: config.logLevel || "info",
|
|
33138
33140
|
module: "HCS-Browser"
|
|
33139
33141
|
});
|
|
33140
|
-
|
|
33141
|
-
|
|
33142
|
-
|
|
33143
|
-
|
|
33144
|
-
|
|
33145
|
-
|
|
33146
|
-
|
|
33147
|
-
|
|
33148
|
-
|
|
33142
|
+
if (isBrowser$1) {
|
|
33143
|
+
try {
|
|
33144
|
+
const { accountId, signer } = this.getAccountAndSigner();
|
|
33145
|
+
this.hcs11Client = new HCS11Client({
|
|
33146
|
+
network: config.network,
|
|
33147
|
+
auth: {
|
|
33148
|
+
operatorId: accountId,
|
|
33149
|
+
signer
|
|
33150
|
+
},
|
|
33151
|
+
logLevel: config.logLevel
|
|
33152
|
+
});
|
|
33153
|
+
} catch (err) {
|
|
33154
|
+
this.logger.warn(`Failed to initialize HCS11Client: ${err}`);
|
|
33155
|
+
}
|
|
33156
|
+
} else {
|
|
33157
|
+
this.logger.error(
|
|
33158
|
+
"BrowserHCSClient initialized in server environment - browser-specific features will not be available. Use HCS10Client instead."
|
|
33159
|
+
);
|
|
33160
|
+
}
|
|
33149
33161
|
}
|
|
33150
33162
|
async sendMessage(connectionTopicId, operatorId, data, memo) {
|
|
33151
33163
|
this.logger.info("Sending message");
|
|
@@ -33169,7 +33181,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33169
33181
|
contentBuffer,
|
|
33170
33182
|
fileName
|
|
33171
33183
|
);
|
|
33172
|
-
if (inscriptionResult
|
|
33184
|
+
if (inscriptionResult?.topic_id) {
|
|
33173
33185
|
payload.data = `hcs://1/${inscriptionResult.topic_id}`;
|
|
33174
33186
|
this.logger.info(
|
|
33175
33187
|
`Large message inscribed with topic ID: ${inscriptionResult.topic_id}`
|
|
@@ -33187,7 +33199,6 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33187
33199
|
await this.submitPayload(connectionTopicId, payload);
|
|
33188
33200
|
}
|
|
33189
33201
|
async submitConnectionRequest(inboundTopicId, requestingAccountId, operatorId, memo) {
|
|
33190
|
-
var _a, _b;
|
|
33191
33202
|
this.logger.info("Submitting connection request");
|
|
33192
33203
|
const connectionRequestMessage = {
|
|
33193
33204
|
p: "hcs-10",
|
|
@@ -33206,7 +33217,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33206
33217
|
const outboundTopic = await this.retrieveOutboundConnectTopic(
|
|
33207
33218
|
requestingAccountId
|
|
33208
33219
|
);
|
|
33209
|
-
if (!
|
|
33220
|
+
if (!outboundTopic?.outboundTopic) {
|
|
33210
33221
|
this.logger.error(
|
|
33211
33222
|
`Failed to retrieve outbound topic for account ID: ${requestingAccountId}`
|
|
33212
33223
|
);
|
|
@@ -33217,7 +33228,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33217
33228
|
this.logger.info(
|
|
33218
33229
|
`Retrieved outbound topic ID: ${outboundTopic.outboundTopic} for account ID: ${requestingAccountId}`
|
|
33219
33230
|
);
|
|
33220
|
-
const responseSequenceNumber =
|
|
33231
|
+
const responseSequenceNumber = response?.result?.topicSequenceNumber?.toNumber();
|
|
33221
33232
|
if (!responseSequenceNumber) {
|
|
33222
33233
|
throw new Error("Failed to get response sequence number");
|
|
33223
33234
|
}
|
|
@@ -33277,7 +33288,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33277
33288
|
throw new Error(receipt.error);
|
|
33278
33289
|
}
|
|
33279
33290
|
const result = receipt.result;
|
|
33280
|
-
if (!
|
|
33291
|
+
if (!result?.topicId) {
|
|
33281
33292
|
this.logger.error("Failed to create topic: topicId is null");
|
|
33282
33293
|
throw new Error("Failed to create topic: topicId is null");
|
|
33283
33294
|
}
|
|
@@ -33298,7 +33309,6 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33298
33309
|
};
|
|
33299
33310
|
}
|
|
33300
33311
|
async confirmConnection(inboundTopicId, connectionTopicId, connectedAccountId, connectionId, operatorId, memo) {
|
|
33301
|
-
var _a;
|
|
33302
33312
|
this.logger.info("Confirming connection");
|
|
33303
33313
|
const payload = {
|
|
33304
33314
|
p: "hcs-10",
|
|
@@ -33313,7 +33323,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33313
33323
|
inboundTopicId,
|
|
33314
33324
|
payload
|
|
33315
33325
|
);
|
|
33316
|
-
if (!
|
|
33326
|
+
if (!transactionResponse?.result?.topicSequenceNumber) {
|
|
33317
33327
|
this.logger.error(
|
|
33318
33328
|
"Failed to confirm connection: sequence number is null"
|
|
33319
33329
|
);
|
|
@@ -33420,7 +33430,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33420
33430
|
}
|
|
33421
33431
|
async createAndRegisterAgent(name, description, capabilities, metadata, pfpBuffer, pfpFileName, network, existingPfpTopicId, options) {
|
|
33422
33432
|
try {
|
|
33423
|
-
const progressCallback = options
|
|
33433
|
+
const progressCallback = options?.progressCallback;
|
|
33424
33434
|
const reportProgress = (stage, message, percent, details) => {
|
|
33425
33435
|
if (progressCallback) {
|
|
33426
33436
|
try {
|
|
@@ -33469,8 +33479,8 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33469
33479
|
progress.details
|
|
33470
33480
|
);
|
|
33471
33481
|
},
|
|
33472
|
-
maxAttempts: options
|
|
33473
|
-
delayMs: options
|
|
33482
|
+
maxAttempts: options?.maxAttempts,
|
|
33483
|
+
delayMs: options?.delayMs
|
|
33474
33484
|
}
|
|
33475
33485
|
);
|
|
33476
33486
|
if (!registrationResult.success) {
|
|
@@ -33499,9 +33509,9 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33499
33509
|
async registerAgentWithGuardedRegistry(accountId, inboundTopicId, network = this.network, options) {
|
|
33500
33510
|
try {
|
|
33501
33511
|
this.logger.info("Registering agent with guarded registry");
|
|
33502
|
-
const maxAttempts =
|
|
33503
|
-
const delayMs =
|
|
33504
|
-
const progressCallback = options
|
|
33512
|
+
const maxAttempts = options?.maxAttempts ?? 60;
|
|
33513
|
+
const delayMs = options?.delayMs ?? 2e3;
|
|
33514
|
+
const progressCallback = options?.progressCallback;
|
|
33505
33515
|
const reportProgress = (stage, message, percent, details) => {
|
|
33506
33516
|
if (progressCallback) {
|
|
33507
33517
|
try {
|
|
@@ -33578,6 +33588,13 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33578
33588
|
}
|
|
33579
33589
|
async storeHCS11Profile(agentName, agentDescription, inboundTopicId, outboundTopicId, capabilities = [], metadata = {}, pfpBuffer, pfpFileName, existingPfpTopicId) {
|
|
33580
33590
|
try {
|
|
33591
|
+
if (!this.hcs11Client) {
|
|
33592
|
+
return {
|
|
33593
|
+
profileTopicId: "",
|
|
33594
|
+
success: false,
|
|
33595
|
+
error: "HCS11Client is not available in this environment"
|
|
33596
|
+
};
|
|
33597
|
+
}
|
|
33581
33598
|
let pfpTopicId = existingPfpTopicId;
|
|
33582
33599
|
if (!pfpTopicId && pfpBuffer && pfpFileName) {
|
|
33583
33600
|
const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName);
|
|
@@ -33718,7 +33735,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33718
33735
|
};
|
|
33719
33736
|
}
|
|
33720
33737
|
const result = transactionResponse.result;
|
|
33721
|
-
if (!
|
|
33738
|
+
if (!result?.topicId) {
|
|
33722
33739
|
this.logger.error("Failed to create topic: topicId is null");
|
|
33723
33740
|
return {
|
|
33724
33741
|
success: false,
|
|
@@ -33794,6 +33811,13 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33794
33811
|
*/
|
|
33795
33812
|
async inscribePfp(buffer2, fileName) {
|
|
33796
33813
|
try {
|
|
33814
|
+
if (!this.hcs11Client) {
|
|
33815
|
+
return {
|
|
33816
|
+
pfpTopicId: "",
|
|
33817
|
+
success: false,
|
|
33818
|
+
error: "HCS11Client is not available in this environment"
|
|
33819
|
+
};
|
|
33820
|
+
}
|
|
33797
33821
|
this.logger.info("Inscribing profile picture using HCS-11 client");
|
|
33798
33822
|
const imageResult = await this.hcs11Client.inscribeImage(
|
|
33799
33823
|
buffer2,
|
|
@@ -33826,6 +33850,8 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
33826
33850
|
}
|
|
33827
33851
|
}
|
|
33828
33852
|
}
|
|
33853
|
+
const isBrowser = typeof window !== "undefined";
|
|
33854
|
+
const isServer = !isBrowser;
|
|
33829
33855
|
export {
|
|
33830
33856
|
AIAgentCapability,
|
|
33831
33857
|
AIAgentType,
|
|
@@ -33854,6 +33880,8 @@ export {
|
|
|
33854
33880
|
capabilityNameToCapabilityMap,
|
|
33855
33881
|
inscribe,
|
|
33856
33882
|
inscribeWithSigner,
|
|
33883
|
+
isBrowser,
|
|
33884
|
+
isServer,
|
|
33857
33885
|
retrieveInscription,
|
|
33858
33886
|
sleep
|
|
33859
33887
|
};
|