@hashgraphonline/standards-sdk 0.0.52 → 0.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/hcs-10/base-client.d.ts +40 -45
- package/dist/es/hcs-10/base-client.d.ts.map +1 -1
- package/dist/es/hcs-10/browser.d.ts +8 -10
- package/dist/es/hcs-10/browser.d.ts.map +1 -1
- package/dist/es/hcs-10/sdk.d.ts +67 -13
- package/dist/es/hcs-10/sdk.d.ts.map +1 -1
- package/dist/es/hcs-10/types.d.ts +0 -7
- package/dist/es/hcs-10/types.d.ts.map +1 -1
- package/dist/es/hcs-11/index.d.ts +1 -1
- package/dist/es/hcs-11/index.d.ts.map +1 -1
- package/dist/es/inscribe/types.d.ts +1 -1
- package/dist/es/inscribe/types.d.ts.map +1 -1
- package/dist/es/services/mirror-node.d.ts.map +1 -1
- package/dist/es/standards-sdk.es.js +2 -1
- package/dist/es/standards-sdk.es10.js +138 -123
- package/dist/es/standards-sdk.es10.js.map +1 -1
- package/dist/es/standards-sdk.es100.js +3 -4
- package/dist/es/standards-sdk.es100.js.map +1 -1
- package/dist/es/standards-sdk.es101.js +16 -39
- package/dist/es/standards-sdk.es101.js.map +1 -1
- package/dist/es/standards-sdk.es102.js +5 -40
- package/dist/es/standards-sdk.es102.js.map +1 -1
- package/dist/es/standards-sdk.es103.js +37 -35
- package/dist/es/standards-sdk.es103.js.map +1 -1
- package/dist/es/standards-sdk.es104.js +34 -72
- package/dist/es/standards-sdk.es104.js.map +1 -1
- package/dist/es/standards-sdk.es105.js +37 -3
- package/dist/es/standards-sdk.es105.js.map +1 -1
- package/dist/es/standards-sdk.es106.js +78 -2
- package/dist/es/standards-sdk.es106.js.map +1 -1
- package/dist/es/standards-sdk.es107.js +3 -2
- package/dist/es/standards-sdk.es107.js.map +1 -1
- package/dist/es/standards-sdk.es108.js +2 -34
- package/dist/es/standards-sdk.es108.js.map +1 -1
- package/dist/es/standards-sdk.es109.js +2 -33
- package/dist/es/standards-sdk.es109.js.map +1 -1
- package/dist/es/standards-sdk.es110.js +34 -9
- package/dist/es/standards-sdk.es110.js.map +1 -1
- package/dist/es/standards-sdk.es111.js +31 -32
- package/dist/es/standards-sdk.es111.js.map +1 -1
- package/dist/es/standards-sdk.es112.js +12 -0
- package/dist/es/standards-sdk.es112.js.map +1 -0
- package/dist/es/standards-sdk.es113.js +37 -0
- package/dist/es/standards-sdk.es113.js.map +1 -0
- package/dist/es/standards-sdk.es12.js +3 -2
- package/dist/es/standards-sdk.es12.js.map +1 -1
- package/dist/es/standards-sdk.es13.js +1 -1
- package/dist/es/standards-sdk.es16.js +2 -1
- package/dist/es/standards-sdk.es16.js.map +1 -1
- package/dist/es/standards-sdk.es17.js +6 -3
- package/dist/es/standards-sdk.es17.js.map +1 -1
- package/dist/es/standards-sdk.es18.js.map +1 -1
- package/dist/es/standards-sdk.es19.js +1767 -3
- package/dist/es/standards-sdk.es19.js.map +1 -1
- package/dist/es/standards-sdk.es20.js +3 -4167
- package/dist/es/standards-sdk.es20.js.map +1 -1
- package/dist/es/standards-sdk.es21.js +4086 -960
- package/dist/es/standards-sdk.es21.js.map +1 -1
- package/dist/es/standards-sdk.es22.js +1041 -36
- package/dist/es/standards-sdk.es22.js.map +1 -1
- package/dist/es/standards-sdk.es23.js +5 -48
- package/dist/es/standards-sdk.es23.js.map +1 -1
- package/dist/es/standards-sdk.es24.js +36 -6624
- package/dist/es/standards-sdk.es24.js.map +1 -1
- package/dist/es/standards-sdk.es25.js +48 -5
- package/dist/es/standards-sdk.es25.js.map +1 -1
- package/dist/es/standards-sdk.es26.js +6627 -2
- package/dist/es/standards-sdk.es26.js.map +1 -1
- package/dist/es/standards-sdk.es27.js +2 -101
- package/dist/es/standards-sdk.es27.js.map +1 -1
- package/dist/es/standards-sdk.es28.js +419 -2
- package/dist/es/standards-sdk.es28.js.map +1 -1
- package/dist/es/standards-sdk.es29.js +2 -16
- package/dist/es/standards-sdk.es29.js.map +1 -1
- package/dist/es/standards-sdk.es30.js +120 -4
- package/dist/es/standards-sdk.es30.js.map +1 -1
- package/dist/es/standards-sdk.es31.js +101 -2282
- package/dist/es/standards-sdk.es31.js.map +1 -1
- package/dist/es/standards-sdk.es32.js +2 -2
- package/dist/es/standards-sdk.es32.js.map +1 -1
- package/dist/es/standards-sdk.es33.js +15 -418
- package/dist/es/standards-sdk.es33.js.map +1 -1
- package/dist/es/standards-sdk.es34.js +409 -2
- package/dist/es/standards-sdk.es34.js.map +1 -1
- package/dist/es/standards-sdk.es35.js +2282 -120
- package/dist/es/standards-sdk.es35.js.map +1 -1
- package/dist/es/standards-sdk.es36.js +164 -2
- package/dist/es/standards-sdk.es36.js.map +1 -1
- package/dist/es/standards-sdk.es37.js +0 -25
- package/dist/es/standards-sdk.es37.js.map +1 -1
- package/dist/es/standards-sdk.es38.js +2 -362
- package/dist/es/standards-sdk.es38.js.map +1 -1
- package/dist/es/standards-sdk.es39.js +3 -6
- package/dist/es/standards-sdk.es39.js.map +1 -1
- package/dist/es/standards-sdk.es4.js +1 -1
- package/dist/es/standards-sdk.es40.js +185 -169
- package/dist/es/standards-sdk.es40.js.map +1 -1
- package/dist/es/standards-sdk.es41.js +437 -80
- package/dist/es/standards-sdk.es41.js.map +1 -1
- package/dist/es/standards-sdk.es42.js +21 -110
- package/dist/es/standards-sdk.es42.js.map +1 -1
- package/dist/es/standards-sdk.es43.js +130 -43
- package/dist/es/standards-sdk.es43.js.map +1 -1
- package/dist/es/standards-sdk.es44.js +17 -9
- package/dist/es/standards-sdk.es44.js.map +1 -1
- package/dist/es/standards-sdk.es45.js +22 -90
- package/dist/es/standards-sdk.es45.js.map +1 -1
- package/dist/es/standards-sdk.es46.js +28 -3
- package/dist/es/standards-sdk.es46.js.map +1 -1
- package/dist/es/standards-sdk.es47.js +21 -2
- package/dist/es/standards-sdk.es47.js.map +1 -1
- package/dist/es/standards-sdk.es48.js +36 -104
- package/dist/es/standards-sdk.es48.js.map +1 -1
- package/dist/es/standards-sdk.es49.js +15 -71
- package/dist/es/standards-sdk.es49.js.map +1 -1
- package/dist/es/standards-sdk.es5.js +410 -134
- package/dist/es/standards-sdk.es5.js.map +1 -1
- package/dist/es/standards-sdk.es50.js +60 -5
- package/dist/es/standards-sdk.es50.js.map +1 -1
- package/dist/es/standards-sdk.es51.js +1288 -4
- package/dist/es/standards-sdk.es51.js.map +1 -1
- package/dist/es/standards-sdk.es52.js +131 -204
- package/dist/es/standards-sdk.es52.js.map +1 -1
- package/dist/es/standards-sdk.es53.js +89 -56
- package/dist/es/standards-sdk.es53.js.map +1 -1
- package/dist/es/standards-sdk.es54.js +84 -69
- package/dist/es/standards-sdk.es54.js.map +1 -1
- package/dist/es/standards-sdk.es55.js +27 -190
- package/dist/es/standards-sdk.es55.js.map +1 -1
- package/dist/es/standards-sdk.es56.js +5 -437
- package/dist/es/standards-sdk.es56.js.map +1 -1
- package/dist/es/standards-sdk.es57.js +155 -21
- package/dist/es/standards-sdk.es57.js.map +1 -1
- package/dist/es/standards-sdk.es58.js +21 -137
- package/dist/es/standards-sdk.es58.js.map +1 -1
- package/dist/es/standards-sdk.es59.js +788 -13
- package/dist/es/standards-sdk.es59.js.map +1 -1
- package/dist/es/standards-sdk.es60.js +167 -22
- package/dist/es/standards-sdk.es60.js.map +1 -1
- package/dist/es/standards-sdk.es61.js +137 -23
- package/dist/es/standards-sdk.es61.js.map +1 -1
- package/dist/es/standards-sdk.es62.js +358 -15
- package/dist/es/standards-sdk.es62.js.map +1 -1
- package/dist/es/standards-sdk.es63.js +5 -43
- package/dist/es/standards-sdk.es63.js.map +1 -1
- package/dist/es/standards-sdk.es64.js +174 -13
- package/dist/es/standards-sdk.es64.js.map +1 -1
- package/dist/es/standards-sdk.es65.js +76 -56
- package/dist/es/standards-sdk.es65.js.map +1 -1
- package/dist/es/standards-sdk.es66.js +104 -1279
- package/dist/es/standards-sdk.es66.js.map +1 -1
- package/dist/es/standards-sdk.es67.js +42 -138
- package/dist/es/standards-sdk.es67.js.map +1 -1
- package/dist/es/standards-sdk.es68.js +10 -91
- package/dist/es/standards-sdk.es68.js.map +1 -1
- package/dist/es/standards-sdk.es69.js +89 -76
- package/dist/es/standards-sdk.es69.js.map +1 -1
- package/dist/es/standards-sdk.es70.js +3 -31
- package/dist/es/standards-sdk.es70.js.map +1 -1
- package/dist/es/standards-sdk.es71.js +2 -6
- package/dist/es/standards-sdk.es71.js.map +1 -1
- package/dist/es/standards-sdk.es72.js +99 -145
- package/dist/es/standards-sdk.es72.js.map +1 -1
- package/dist/es/standards-sdk.es73.js +71 -20
- package/dist/es/standards-sdk.es73.js.map +1 -1
- package/dist/es/standards-sdk.es74.js +5 -792
- package/dist/es/standards-sdk.es74.js.map +1 -1
- package/dist/es/standards-sdk.es75.js +4 -142
- package/dist/es/standards-sdk.es75.js.map +1 -1
- package/dist/es/standards-sdk.es76.js +209 -162
- package/dist/es/standards-sdk.es76.js.map +1 -1
- package/dist/es/standards-sdk.es77.js +56 -30
- package/dist/es/standards-sdk.es77.js.map +1 -1
- package/dist/es/standards-sdk.es78.js +69 -63
- package/dist/es/standards-sdk.es78.js.map +1 -1
- package/dist/es/standards-sdk.es79.js +17 -46
- package/dist/es/standards-sdk.es79.js.map +1 -1
- package/dist/es/standards-sdk.es8.js +143 -180
- package/dist/es/standards-sdk.es8.js.map +1 -1
- package/dist/es/standards-sdk.es80.js +25 -8
- package/dist/es/standards-sdk.es80.js.map +1 -1
- package/dist/es/standards-sdk.es81.js +24 -63
- package/dist/es/standards-sdk.es81.js.map +1 -1
- package/dist/es/standards-sdk.es82.js +38 -6
- package/dist/es/standards-sdk.es82.js.map +1 -1
- package/dist/es/standards-sdk.es83.js +30 -13
- package/dist/es/standards-sdk.es83.js.map +1 -1
- package/dist/es/standards-sdk.es84.js +63 -7
- package/dist/es/standards-sdk.es84.js.map +1 -1
- package/dist/es/standards-sdk.es85.js +47 -42
- package/dist/es/standards-sdk.es85.js.map +1 -1
- package/dist/es/standards-sdk.es86.js +10 -2
- package/dist/es/standards-sdk.es86.js.map +1 -1
- package/dist/es/standards-sdk.es87.js +58 -129
- package/dist/es/standards-sdk.es87.js.map +1 -1
- package/dist/es/standards-sdk.es88.js +5 -171
- package/dist/es/standards-sdk.es88.js.map +1 -1
- package/dist/es/standards-sdk.es89.js +14 -20
- package/dist/es/standards-sdk.es89.js.map +1 -1
- package/dist/es/standards-sdk.es9.js +1 -1
- package/dist/es/standards-sdk.es90.js +7 -27
- package/dist/es/standards-sdk.es90.js.map +1 -1
- package/dist/es/standards-sdk.es91.js +45 -26
- package/dist/es/standards-sdk.es91.js.map +1 -1
- package/dist/es/standards-sdk.es92.js +2 -38
- package/dist/es/standards-sdk.es92.js.map +1 -1
- package/dist/es/standards-sdk.es93.js +134 -30
- package/dist/es/standards-sdk.es93.js.map +1 -1
- package/dist/es/standards-sdk.es94.js +171 -14
- package/dist/es/standards-sdk.es94.js.map +1 -1
- package/dist/es/standards-sdk.es95.js +13 -4
- package/dist/es/standards-sdk.es95.js.map +1 -1
- package/dist/es/standards-sdk.es96.js +13 -4
- package/dist/es/standards-sdk.es96.js.map +1 -1
- package/dist/es/standards-sdk.es97.js +31 -12
- package/dist/es/standards-sdk.es97.js.map +1 -1
- package/dist/es/standards-sdk.es98.js +15 -13
- package/dist/es/standards-sdk.es98.js.map +1 -1
- package/dist/es/standards-sdk.es99.js +3 -15
- package/dist/es/standards-sdk.es99.js.map +1 -1
- package/dist/umd/hcs-10/base-client.d.ts +40 -45
- package/dist/umd/hcs-10/base-client.d.ts.map +1 -1
- package/dist/umd/hcs-10/browser.d.ts +8 -10
- package/dist/umd/hcs-10/browser.d.ts.map +1 -1
- package/dist/umd/hcs-10/sdk.d.ts +67 -13
- package/dist/umd/hcs-10/sdk.d.ts.map +1 -1
- package/dist/umd/hcs-10/types.d.ts +0 -7
- package/dist/umd/hcs-10/types.d.ts.map +1 -1
- package/dist/umd/hcs-11/index.d.ts +1 -1
- package/dist/umd/hcs-11/index.d.ts.map +1 -1
- package/dist/umd/inscribe/types.d.ts +1 -1
- package/dist/umd/inscribe/types.d.ts.map +1 -1
- package/dist/umd/services/mirror-node.d.ts.map +1 -1
- package/dist/umd/standards-sdk.umd.js +23 -19
- package/dist/umd/standards-sdk.umd.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
import Buffer from "./standards-sdk.es19.js";
|
|
1
2
|
import { HederaMirrorNode } from "./standards-sdk.es17.js";
|
|
2
3
|
import { Logger } from "./standards-sdk.es13.js";
|
|
3
|
-
import "./standards-sdk.es22.js";
|
|
4
4
|
import { Registration } from "./standards-sdk.es9.js";
|
|
5
5
|
import { HCS11Client } from "./standards-sdk.es12.js";
|
|
6
6
|
import { PublicKey } from "@hashgraph/sdk";
|
|
7
|
-
import
|
|
7
|
+
import "./standards-sdk.es24.js";
|
|
8
|
+
import axios from "./standards-sdk.es25.js";
|
|
9
|
+
var Hcs10MemoType = /* @__PURE__ */ ((Hcs10MemoType2) => {
|
|
10
|
+
Hcs10MemoType2["INBOUND"] = "inbound";
|
|
11
|
+
Hcs10MemoType2["OUTBOUND"] = "outbound";
|
|
12
|
+
Hcs10MemoType2["CONNECTION"] = "connection";
|
|
13
|
+
return Hcs10MemoType2;
|
|
14
|
+
})(Hcs10MemoType || {});
|
|
8
15
|
class HCS10BaseClient extends Registration {
|
|
9
16
|
constructor(config) {
|
|
10
17
|
super();
|
|
@@ -18,7 +25,51 @@ class HCS10BaseClient extends Registration {
|
|
|
18
25
|
config.network,
|
|
19
26
|
this.logger
|
|
20
27
|
);
|
|
21
|
-
this.feeAmount = config.feeAmount ||
|
|
28
|
+
this.feeAmount = config.feeAmount || 1e-3;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get a stream of messages from a connection topic
|
|
32
|
+
* @param topicId The connection topic ID to get messages from
|
|
33
|
+
* @returns A stream of filtered messages valid for connection topics
|
|
34
|
+
*/
|
|
35
|
+
async getMessageStream(topicId) {
|
|
36
|
+
try {
|
|
37
|
+
const messages = await this.mirrorNode.getTopicMessages(topicId);
|
|
38
|
+
const validOps = ["message", "close_connection"];
|
|
39
|
+
const filteredMessages = messages.filter((msg) => {
|
|
40
|
+
if (msg.p !== "hcs-10" || !validOps.includes(msg.op)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if (msg.op === "message") {
|
|
44
|
+
if (!msg.data) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
if (!msg.operator_id) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
if (!this.isValidOperatorId(msg.operator_id)) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (msg.op === "close_connection") {
|
|
55
|
+
if (!msg.operator_id) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
if (!this.isValidOperatorId(msg.operator_id)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
messages: filteredMessages
|
|
66
|
+
};
|
|
67
|
+
} catch (error) {
|
|
68
|
+
if (this.logger) {
|
|
69
|
+
this.logger.error(`Error fetching messages: ${error.message}`);
|
|
70
|
+
}
|
|
71
|
+
return { messages: [] };
|
|
72
|
+
}
|
|
22
73
|
}
|
|
23
74
|
/**
|
|
24
75
|
* Checks if a user can submit to a topic and determines if a fee is required
|
|
@@ -26,7 +77,7 @@ class HCS10BaseClient extends Registration {
|
|
|
26
77
|
* @param userAccountId The account ID of the user attempting to submit
|
|
27
78
|
* @returns Object with canSubmit, requiresFee, and optional reason
|
|
28
79
|
*/
|
|
29
|
-
async
|
|
80
|
+
async canSubmitToTopic(topicId, userAccountId) {
|
|
30
81
|
try {
|
|
31
82
|
const topicInfo = await this.mirrorNode.getTopicInfo(topicId);
|
|
32
83
|
if (!topicInfo) {
|
|
@@ -57,11 +108,9 @@ class HCS10BaseClient extends Registration {
|
|
|
57
108
|
}
|
|
58
109
|
}
|
|
59
110
|
} catch (error) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
this.logger.error(`Key validation error: ${errorMessage}`);
|
|
111
|
+
this.logger.error(
|
|
112
|
+
`Key validation error: ${error instanceof Error ? error.message : String(error)}`
|
|
113
|
+
);
|
|
65
114
|
}
|
|
66
115
|
if (topicInfo.fee_schedule_key?.key && topicInfo.custom_fees?.fixed_fees?.length > 0) {
|
|
67
116
|
return {
|
|
@@ -76,10 +125,7 @@ class HCS10BaseClient extends Registration {
|
|
|
76
125
|
reason: "User does not have submit permission for this topic"
|
|
77
126
|
};
|
|
78
127
|
} catch (error) {
|
|
79
|
-
|
|
80
|
-
if (error instanceof Error) {
|
|
81
|
-
errorMessage = error.message;
|
|
82
|
-
}
|
|
128
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
83
129
|
this.logger.error(`Topic submission validation error: ${errorMessage}`);
|
|
84
130
|
return {
|
|
85
131
|
canSubmit: false,
|
|
@@ -88,148 +134,6 @@ class HCS10BaseClient extends Registration {
|
|
|
88
134
|
};
|
|
89
135
|
}
|
|
90
136
|
}
|
|
91
|
-
/**
|
|
92
|
-
* The primary method for an agent to send a message to another agent.
|
|
93
|
-
* @param {string} connectionTopicId The ID of the connection topic to send the message to
|
|
94
|
-
* @param {string} operatorId The operator ID (agentInboundTopicId@accountId) of the message sender in the operatorId format e.g. "0.0.123333@0.0.12345"
|
|
95
|
-
* @param {string} data The content of the message
|
|
96
|
-
* @param {string} memo An optional memo for the message
|
|
97
|
-
* @param {object} options Optional configuration for the message submission
|
|
98
|
-
* @param {PrivateKey} submitKey The private key of the account submitting the message
|
|
99
|
-
* @returns A promise that resolves to the transaction receipt of the message submission
|
|
100
|
-
*/
|
|
101
|
-
async sendMessage(connectionTopicId, operatorId, data, memo, options, submitKey) {
|
|
102
|
-
const { accountId } = this.getAccountAndSigner();
|
|
103
|
-
const submissionCheck = await this.canSubmitToInboundTopic(
|
|
104
|
-
connectionTopicId,
|
|
105
|
-
accountId
|
|
106
|
-
);
|
|
107
|
-
if (!submissionCheck.canSubmit) {
|
|
108
|
-
throw new Error(
|
|
109
|
-
`Cannot submit to topic ${connectionTopicId}: ${submissionCheck.reason || "Unknown reason"}`
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
const payload = {
|
|
113
|
-
p: "hcs-10",
|
|
114
|
-
op: "message",
|
|
115
|
-
operator_id: operatorId,
|
|
116
|
-
data,
|
|
117
|
-
m: memo
|
|
118
|
-
};
|
|
119
|
-
const payloadString = JSON.stringify(payload);
|
|
120
|
-
const isLargePayload = Buffer.from(payloadString).length > 1e3;
|
|
121
|
-
if (isLargePayload) {
|
|
122
|
-
this.logger.info(
|
|
123
|
-
"Message payload exceeds 1000 bytes, storing via inscription"
|
|
124
|
-
);
|
|
125
|
-
try {
|
|
126
|
-
const contentBuffer = Buffer.from(data);
|
|
127
|
-
const fileFormat = "json";
|
|
128
|
-
const fileName = `message-content-${Date.now()}.${fileFormat}`;
|
|
129
|
-
const inscriptionResult = await this.inscribeFile(
|
|
130
|
-
contentBuffer,
|
|
131
|
-
fileName,
|
|
132
|
-
options
|
|
133
|
-
);
|
|
134
|
-
if (inscriptionResult?.topic_id) {
|
|
135
|
-
payload.data = `hcs://1/${inscriptionResult.topic_id}`;
|
|
136
|
-
this.logger.info(
|
|
137
|
-
`Large message inscribed with topic ID: ${inscriptionResult.topic_id}`
|
|
138
|
-
);
|
|
139
|
-
} else {
|
|
140
|
-
throw new Error("Failed to inscribe large message content");
|
|
141
|
-
}
|
|
142
|
-
} catch (error) {
|
|
143
|
-
this.logger.error("Error inscribing large message:", error);
|
|
144
|
-
let errorMessage = "Unknown error";
|
|
145
|
-
if (error instanceof Error) {
|
|
146
|
-
errorMessage = error.message;
|
|
147
|
-
}
|
|
148
|
-
throw new Error(`Failed to handle large message: ${errorMessage}`);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
this.logger.info("Submitting message to connection topic", payload);
|
|
152
|
-
return await this.submitPayload(
|
|
153
|
-
connectionTopicId,
|
|
154
|
-
payload,
|
|
155
|
-
submitKey,
|
|
156
|
-
submissionCheck.requiresFee
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Get a stream of messages from a connection topic
|
|
161
|
-
* @param topicId The connection topic ID to get messages from
|
|
162
|
-
* @returns A stream of filtered messages valid for connection topics
|
|
163
|
-
*/
|
|
164
|
-
async getMessageStream(topicId) {
|
|
165
|
-
try {
|
|
166
|
-
const messages = await this.mirrorNode.getTopicMessages(topicId);
|
|
167
|
-
const validOps = ["message", "close_connection"];
|
|
168
|
-
const filteredMessages = messages.filter((msg) => {
|
|
169
|
-
if (msg.p !== "hcs-10" || !validOps.includes(msg.op)) {
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
|
-
if (msg.op === "message") {
|
|
173
|
-
if (!msg.data) {
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
if (!msg.operator_id) {
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
179
|
-
if (!this.isValidOperatorId(msg.operator_id)) {
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
if (msg.op === "close_connection") {
|
|
184
|
-
if (!msg.operator_id) {
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
if (!this.isValidOperatorId(msg.operator_id)) {
|
|
188
|
-
return false;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return true;
|
|
192
|
-
});
|
|
193
|
-
return {
|
|
194
|
-
messages: filteredMessages
|
|
195
|
-
};
|
|
196
|
-
} catch (error) {
|
|
197
|
-
if (this.logger) {
|
|
198
|
-
this.logger.error(`Error fetching messages: ${error.message}`);
|
|
199
|
-
}
|
|
200
|
-
return { messages: [] };
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Validates if an operator_id follows the correct format (agentTopicId@accountId)
|
|
205
|
-
* @param operatorId The operator ID to validate
|
|
206
|
-
* @returns True if the format is valid, false otherwise
|
|
207
|
-
*/
|
|
208
|
-
isValidOperatorId(operatorId) {
|
|
209
|
-
if (!operatorId) {
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
212
|
-
const parts = operatorId.split("@");
|
|
213
|
-
if (parts.length !== 2) {
|
|
214
|
-
return false;
|
|
215
|
-
}
|
|
216
|
-
const agentTopicId = parts[0];
|
|
217
|
-
const accountId = parts[1];
|
|
218
|
-
if (!agentTopicId) {
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
|
-
if (!accountId) {
|
|
222
|
-
return false;
|
|
223
|
-
}
|
|
224
|
-
const hederaIdPattern = /^[0-9]+\.[0-9]+\.[0-9]+$/;
|
|
225
|
-
if (!hederaIdPattern.test(accountId)) {
|
|
226
|
-
return false;
|
|
227
|
-
}
|
|
228
|
-
if (!hederaIdPattern.test(agentTopicId)) {
|
|
229
|
-
return false;
|
|
230
|
-
}
|
|
231
|
-
return true;
|
|
232
|
-
}
|
|
233
137
|
/**
|
|
234
138
|
* Get all messages from a topic
|
|
235
139
|
* @param topicId The topic ID to get messages from
|
|
@@ -264,27 +168,6 @@ class HCS10BaseClient extends Registration {
|
|
|
264
168
|
return { messages: [] };
|
|
265
169
|
}
|
|
266
170
|
}
|
|
267
|
-
async checkRegistrationStatus(transactionId, network, baseUrl) {
|
|
268
|
-
try {
|
|
269
|
-
const response = await fetch(`${baseUrl}/api/request-confirm`, {
|
|
270
|
-
method: "POST",
|
|
271
|
-
headers: {
|
|
272
|
-
"Content-Type": "application/json",
|
|
273
|
-
"X-Network": network
|
|
274
|
-
},
|
|
275
|
-
body: JSON.stringify({ transaction_id: transactionId })
|
|
276
|
-
});
|
|
277
|
-
if (!response.ok) {
|
|
278
|
-
throw new Error(
|
|
279
|
-
`Failed to confirm registration: ${response.statusText}`
|
|
280
|
-
);
|
|
281
|
-
}
|
|
282
|
-
return await response.json();
|
|
283
|
-
} catch (error) {
|
|
284
|
-
this.logger.error(`Error checking registration status: ${error}`);
|
|
285
|
-
throw error;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
171
|
async requestAccount(account) {
|
|
289
172
|
try {
|
|
290
173
|
return await this.mirrorNode.requestAccount(account);
|
|
@@ -407,9 +290,6 @@ class HCS10BaseClient extends Registration {
|
|
|
407
290
|
return false;
|
|
408
291
|
}
|
|
409
292
|
}
|
|
410
|
-
clearCache() {
|
|
411
|
-
HCS10Cache.getInstance().clear();
|
|
412
|
-
}
|
|
413
293
|
/**
|
|
414
294
|
* Gets message content, resolving any HRL references if needed
|
|
415
295
|
* @param data The message data which might be an HRL reference
|
|
@@ -470,6 +350,88 @@ class HCS10BaseClient extends Registration {
|
|
|
470
350
|
};
|
|
471
351
|
return await this.submitPayload(outboundTopicId, payload);
|
|
472
352
|
}
|
|
353
|
+
clearCache() {
|
|
354
|
+
HCS10Cache.getInstance().clear();
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Generates a standard HCS-10 memo string.
|
|
358
|
+
* @param type The type of topic memo ('inbound', 'outbound', 'connection').
|
|
359
|
+
* @param options Configuration options for the memo.
|
|
360
|
+
* @returns The formatted memo string.
|
|
361
|
+
* @protected
|
|
362
|
+
*/
|
|
363
|
+
_generateHcs10Memo(type, options) {
|
|
364
|
+
const ttl = options.ttl ?? 60;
|
|
365
|
+
switch (type) {
|
|
366
|
+
case "inbound":
|
|
367
|
+
if (!options.accountId) {
|
|
368
|
+
throw new Error("accountId is required for inbound memo");
|
|
369
|
+
}
|
|
370
|
+
return `hcs-10:0:${ttl}:0:${options.accountId}`;
|
|
371
|
+
case "outbound":
|
|
372
|
+
return `hcs-10:0:${ttl}:1`;
|
|
373
|
+
case "connection":
|
|
374
|
+
if (!options.inboundTopicId || options.connectionId === void 0) {
|
|
375
|
+
throw new Error(
|
|
376
|
+
"inboundTopicId and connectionId are required for connection memo"
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
return `hcs-10:1:${ttl}:2:${options.inboundTopicId}:${options.connectionId}`;
|
|
380
|
+
default:
|
|
381
|
+
throw new Error(`Invalid HCS-10 memo type: ${type}`);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
async checkRegistrationStatus(transactionId, network, baseUrl) {
|
|
385
|
+
try {
|
|
386
|
+
const response = await fetch(`${baseUrl}/api/request-confirm`, {
|
|
387
|
+
method: "POST",
|
|
388
|
+
headers: {
|
|
389
|
+
"Content-Type": "application/json",
|
|
390
|
+
"X-Network": network
|
|
391
|
+
},
|
|
392
|
+
body: JSON.stringify({ transaction_id: transactionId })
|
|
393
|
+
});
|
|
394
|
+
if (!response.ok) {
|
|
395
|
+
throw new Error(
|
|
396
|
+
`Failed to confirm registration: ${response.statusText}`
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
return await response.json();
|
|
400
|
+
} catch (error) {
|
|
401
|
+
this.logger.error(`Error checking registration status: ${error}`);
|
|
402
|
+
throw error;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Validates if an operator_id follows the correct format (agentTopicId@accountId)
|
|
407
|
+
* @param operatorId The operator ID to validate
|
|
408
|
+
* @returns True if the format is valid, false otherwise
|
|
409
|
+
*/
|
|
410
|
+
isValidOperatorId(operatorId) {
|
|
411
|
+
if (!operatorId) {
|
|
412
|
+
return false;
|
|
413
|
+
}
|
|
414
|
+
const parts = operatorId.split("@");
|
|
415
|
+
if (parts.length !== 2) {
|
|
416
|
+
return false;
|
|
417
|
+
}
|
|
418
|
+
const agentTopicId = parts[0];
|
|
419
|
+
const accountId = parts[1];
|
|
420
|
+
if (!agentTopicId) {
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
if (!accountId) {
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
const hederaIdPattern = /^[0-9]+\.[0-9]+\.[0-9]+$/;
|
|
427
|
+
if (!hederaIdPattern.test(accountId)) {
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
if (!hederaIdPattern.test(agentTopicId)) {
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
return true;
|
|
434
|
+
}
|
|
473
435
|
}
|
|
474
436
|
class HCS10Cache {
|
|
475
437
|
constructor() {
|
|
@@ -505,6 +467,7 @@ class HCS10Cache {
|
|
|
505
467
|
}
|
|
506
468
|
export {
|
|
507
469
|
HCS10BaseClient,
|
|
508
|
-
HCS10Cache
|
|
470
|
+
HCS10Cache,
|
|
471
|
+
Hcs10MemoType
|
|
509
472
|
};
|
|
510
473
|
//# sourceMappingURL=standards-sdk.es8.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es8.js","sources":["../../src/hcs-10/base-client.ts"],"sourcesContent":["import { HederaMirrorNode } from '../services/mirror-node';\nimport { Logger, LogLevel } from '../utils/logger';\nimport axios from 'axios';\nimport { Registration } from './registrations';\nimport { HCS11Client } from '../hcs-11';\nimport { AccountResponse, NetworkType } from '../services/types';\nimport { TopicInfo } from '../services/types';\nimport { TransactionReceipt, PrivateKey, PublicKey } from '@hashgraph/sdk';\nimport { RetrievedInscriptionResult } from '@kiloscribe/inscription-sdk';\nimport { InscriptionProgressCallback, InscriptionProgressData } from './types';\nimport { PayloadSizeError } from './errors';\n\nexport interface HCS10Config {\n network: 'mainnet' | 'testnet';\n logLevel?: LogLevel;\n prettyPrint?: boolean;\n}\n\nexport interface HCSMessage {\n p: 'hcs-10';\n op:\n | 'connection_request'\n | 'connection_created'\n | 'message'\n | 'close_connection';\n data: string;\n created?: Date;\n consensus_timestamp?: string;\n m?: string;\n payer: string;\n outbound_topic_id?: string;\n connection_request_id?: number;\n confirmed_request_id?: number;\n connection_topic_id?: string;\n connected_account_id?: string;\n requesting_account_id?: string;\n connection_id?: number;\n sequence_number: number;\n operator_id?: string;\n reason?: string;\n close_method?: string;\n}\n\nexport interface ProfileResponse {\n profile: any;\n topicInfo?: TopicInfo;\n success: boolean;\n error?: string;\n}\n\nexport abstract class HCS10BaseClient extends Registration {\n protected network: string;\n protected logger: Logger;\n protected mirrorNode: HederaMirrorNode;\n protected feeAmount: number;\n\n constructor(config: HCS10Config & { feeAmount?: number }) {\n super();\n this.network = config.network;\n this.logger = Logger.getInstance({\n level: config.logLevel || 'info',\n module: 'HCS10-BaseClient',\n prettyPrint: config.prettyPrint,\n });\n this.mirrorNode = new HederaMirrorNode(\n config.network as NetworkType,\n this.logger\n );\n this.feeAmount = config.feeAmount || 5;\n }\n\n abstract getAccountAndSigner(): { accountId: string; signer: any };\n\n abstract submitPayload(\n topicId: string,\n payload: object | string,\n submitKey?: PrivateKey,\n requiresFee?: boolean\n ): Promise<TransactionReceipt>;\n\n abstract inscribeFile(\n buffer: Buffer,\n fileName: string,\n options?: {\n progressCallback?: InscriptionProgressCallback;\n waitMaxAttempts?: number;\n waitIntervalMs?: number;\n }\n ): Promise<RetrievedInscriptionResult>;\n\n /**\n * Checks if a user can submit to a topic and determines if a fee is required\n * @param topicId The topic ID to check\n * @param userAccountId The account ID of the user attempting to submit\n * @returns Object with canSubmit, requiresFee, and optional reason\n */\n async canSubmitToInboundTopic(\n topicId: string,\n userAccountId: string\n ): Promise<{ canSubmit: boolean; requiresFee: boolean; reason?: string }> {\n try {\n const topicInfo = await this.mirrorNode.getTopicInfo(topicId);\n\n if (!topicInfo) {\n return {\n canSubmit: false,\n requiresFee: false,\n reason: 'Topic does not exist',\n };\n }\n\n if (!topicInfo.submit_key?.key) {\n return { canSubmit: true, requiresFee: false };\n }\n\n try {\n const userPublicKey = await this.mirrorNode.getPublicKey(userAccountId);\n\n if (topicInfo.submit_key._type === 'ProtobufEncoded') {\n const keyBytes = Buffer.from(topicInfo.submit_key.key, 'hex');\n const hasAccess = await this.mirrorNode.checkKeyListAccess(\n keyBytes,\n userPublicKey\n );\n\n if (hasAccess) {\n return { canSubmit: true, requiresFee: false };\n }\n } else {\n const topicSubmitKey = PublicKey.fromString(topicInfo.submit_key.key);\n if (userPublicKey.toString() === topicSubmitKey.toString()) {\n return { canSubmit: true, requiresFee: false };\n }\n }\n } catch (error) {\n let errorMessage = String(error);\n if (error instanceof Error) {\n errorMessage = error.message;\n }\n this.logger.error(`Key validation error: ${errorMessage}`);\n }\n\n if (\n topicInfo.fee_schedule_key?.key &&\n topicInfo.custom_fees?.fixed_fees?.length > 0\n ) {\n return {\n canSubmit: true,\n requiresFee: true,\n reason: 'Requires fee payment via HIP-991',\n };\n }\n\n return {\n canSubmit: false,\n requiresFee: false,\n reason: 'User does not have submit permission for this topic',\n };\n } catch (error) {\n let errorMessage = String(error);\n if (error instanceof Error) {\n errorMessage = error.message;\n }\n this.logger.error(`Topic submission validation error: ${errorMessage}`);\n return {\n canSubmit: false,\n requiresFee: false,\n reason: `Error: ${errorMessage}`,\n };\n }\n }\n\n /**\n * The primary method for an agent to send a message to another agent.\n * @param {string} connectionTopicId The ID of the connection topic to send the message to\n * @param {string} operatorId The operator ID (agentInboundTopicId@accountId) of the message sender in the operatorId format e.g. \"0.0.123333@0.0.12345\"\n * @param {string} data The content of the message\n * @param {string} memo An optional memo for the message\n * @param {object} options Optional configuration for the message submission\n * @param {PrivateKey} submitKey The private key of the account submitting the message\n * @returns A promise that resolves to the transaction receipt of the message submission\n */\n async sendMessage(\n connectionTopicId: string,\n operatorId: string,\n data: string,\n memo?: string,\n options?: {\n progressCallback?: InscriptionProgressCallback;\n waitMaxAttempts?: number;\n waitIntervalMs?: number;\n },\n submitKey?: PrivateKey\n ): Promise<TransactionReceipt> {\n const { accountId } = this.getAccountAndSigner();\n const submissionCheck = await this.canSubmitToInboundTopic(\n connectionTopicId,\n accountId\n );\n\n if (!submissionCheck.canSubmit) {\n throw new Error(\n `Cannot submit to topic ${connectionTopicId}: ${\n submissionCheck.reason || 'Unknown reason'\n }`\n );\n }\n\n const payload = {\n p: 'hcs-10',\n op: 'message',\n operator_id: operatorId,\n data,\n m: memo,\n };\n\n const payloadString = JSON.stringify(payload);\n const isLargePayload = Buffer.from(payloadString).length > 1000;\n\n if (isLargePayload) {\n this.logger.info(\n 'Message payload exceeds 1000 bytes, storing via inscription'\n );\n try {\n const contentBuffer = Buffer.from(data);\n const fileFormat = 'json';\n const fileName = `message-content-${Date.now()}.${fileFormat}`;\n const inscriptionResult = await this.inscribeFile(\n contentBuffer,\n fileName,\n options\n );\n\n if (inscriptionResult?.topic_id) {\n payload.data = `hcs://1/${inscriptionResult.topic_id}`;\n this.logger.info(\n `Large message inscribed with topic ID: ${inscriptionResult.topic_id}`\n );\n } else {\n throw new Error('Failed to inscribe large message content');\n }\n } catch (error) {\n this.logger.error('Error inscribing large message:', error);\n let errorMessage = 'Unknown error';\n if (error instanceof Error) {\n errorMessage = error.message;\n }\n throw new Error(`Failed to handle large message: ${errorMessage}`);\n }\n }\n\n this.logger.info('Submitting message to connection topic', payload);\n return await this.submitPayload(\n connectionTopicId,\n payload,\n submitKey,\n submissionCheck.requiresFee\n );\n }\n\n /**\n * Get a stream of messages from a connection topic\n * @param topicId The connection topic ID to get messages from\n * @returns A stream of filtered messages valid for connection topics\n */\n public async getMessageStream(\n topicId: string\n ): Promise<{ messages: HCSMessage[] }> {\n try {\n const messages = await this.mirrorNode.getTopicMessages(topicId);\n const validOps = ['message', 'close_connection'];\n\n const filteredMessages = messages.filter((msg) => {\n if (msg.p !== 'hcs-10' || !validOps.includes(msg.op)) {\n return false;\n }\n\n if (msg.op === 'message') {\n if (!msg.data) {\n return false;\n }\n\n if (!msg.operator_id) {\n return false;\n }\n\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n }\n\n if (msg.op === 'close_connection') {\n if (!msg.operator_id) {\n return false;\n }\n\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n }\n\n return true;\n });\n\n return {\n messages: filteredMessages,\n };\n } catch (error: any) {\n if (this.logger) {\n this.logger.error(`Error fetching messages: ${error.message}`);\n }\n return { messages: [] };\n }\n }\n\n /**\n * Validates if an operator_id follows the correct format (agentTopicId@accountId)\n * @param operatorId The operator ID to validate\n * @returns True if the format is valid, false otherwise\n */\n protected isValidOperatorId(operatorId: string): boolean {\n if (!operatorId) {\n return false;\n }\n\n const parts = operatorId.split('@');\n\n if (parts.length !== 2) {\n return false;\n }\n\n const agentTopicId = parts[0];\n const accountId = parts[1];\n\n if (!agentTopicId) {\n return false;\n }\n\n if (!accountId) {\n return false;\n }\n\n const hederaIdPattern = /^[0-9]+\\.[0-9]+\\.[0-9]+$/;\n\n if (!hederaIdPattern.test(accountId)) {\n return false;\n }\n\n if (!hederaIdPattern.test(agentTopicId)) {\n return false;\n }\n\n return true;\n }\n\n /**\n * Get all messages from a topic\n * @param topicId The topic ID to get messages from\n * @returns All messages from the topic\n */\n public async getMessages(\n topicId: string\n ): Promise<{ messages: HCSMessage[] }> {\n try {\n const messages = await this.mirrorNode.getTopicMessages(topicId);\n\n const validatedMessages = messages.filter((msg) => {\n if (msg.p !== 'hcs-10') {\n return false;\n }\n\n if (msg.op === 'message') {\n if (!msg.data) {\n return false;\n }\n\n if (msg.operator_id) {\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n }\n }\n\n return true;\n });\n\n return {\n messages: validatedMessages,\n };\n } catch (error: any) {\n if (this.logger) {\n this.logger.error(`Error fetching messages: ${error.message}`);\n }\n return { messages: [] };\n }\n }\n\n protected async checkRegistrationStatus(\n transactionId: string,\n network: string,\n baseUrl: string\n ): Promise<{ status: 'pending' | 'success' | 'failed' }> {\n try {\n const response = await fetch(`${baseUrl}/api/request-confirm`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Network': network,\n },\n body: JSON.stringify({ transaction_id: transactionId }),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to confirm registration: ${response.statusText}`\n );\n }\n\n return await response.json();\n } catch (error) {\n this.logger.error(`Error checking registration status: ${error}`);\n throw error;\n }\n }\n\n public async requestAccount(account: string): Promise<AccountResponse> {\n try {\n return await this.mirrorNode.requestAccount(account);\n } catch (e) {\n this.logger.error('Failed to fetch account', e);\n throw e;\n }\n }\n\n public async getAccountMemo(accountId: string): Promise<string | null> {\n return await this.mirrorNode.getAccountMemo(accountId);\n }\n\n public async retrieveProfile(accountId: string): Promise<ProfileResponse> {\n this.logger.info(`Retrieving profile for account: ${accountId}`);\n\n try {\n const hcs11Client = new HCS11Client({\n network: this.network as 'mainnet' | 'testnet',\n auth: {\n operatorId: '0.0.0', // Read-only operations only\n },\n logLevel: 'info',\n });\n\n const profileResult = await hcs11Client.fetchProfileByAccountId(\n accountId,\n this.network\n );\n\n if (!profileResult?.success) {\n this.logger.error(\n `Failed to retrieve profile for account ID: ${accountId}`,\n profileResult?.error\n );\n return {\n profile: null,\n success: false,\n error:\n profileResult?.error ||\n `Failed to retrieve profile for account ID: ${accountId}`,\n };\n }\n\n const profile = profileResult.profile;\n let topicInfo = null;\n\n if (\n profileResult.topicInfo?.inboundTopic &&\n profileResult.topicInfo?.outboundTopic &&\n profileResult.topicInfo?.profileTopicId\n ) {\n topicInfo = {\n inboundTopic: profileResult.topicInfo.inboundTopic,\n outboundTopic: profileResult.topicInfo.outboundTopic,\n profileTopicId: profileResult.topicInfo.profileTopicId,\n };\n\n const cacheKey = `${accountId}-${this.network}`;\n HCS10Cache.getInstance().set(cacheKey, topicInfo);\n }\n\n return {\n profile,\n topicInfo,\n success: true,\n };\n } catch (error) {\n this.logger.error('Failed to retrieve profile:', error);\n return {\n profile: null,\n success: false,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n }\n\n async retrieveOutboundConnectTopic(accountId: string): Promise<TopicInfo> {\n this.logger.info(`Retrieving topics for account: ${accountId}`);\n\n try {\n const profileResponse = await this.retrieveProfile(accountId);\n\n if (!profileResponse?.success) {\n throw new Error(profileResponse.error || 'Failed to retrieve profile');\n }\n\n const profile = profileResponse.profile;\n\n if (!profile.inboundTopicId || !profile.outboundTopicId) {\n throw new Error(\n `Invalid HCS-11 profile for HCS-10 agent: missing inboundTopicId or outboundTopicId`\n );\n }\n\n const topicInfo = {\n inboundTopic: profile.inboundTopicId,\n outboundTopic: profile.outboundTopicId,\n profileTopicId: profile.profileTopicId,\n };\n\n const cacheKey = `${accountId}-${this.network}`;\n HCS10Cache.getInstance().set(cacheKey, topicInfo);\n return topicInfo;\n } catch (error) {\n this.logger.error('Failed to retrieve topic info:', error);\n throw error;\n }\n }\n\n public async retrieveOutboundMessages(\n agentAccountId: string\n ): Promise<HCSMessage[]> {\n try {\n const topicInfo = await this.retrieveOutboundConnectTopic(agentAccountId);\n if (!topicInfo) {\n this.logger.warn(\n `No outbound connect topic found for agentAccountId: ${agentAccountId}`\n );\n return [];\n }\n const response = await this.getMessages(topicInfo.outboundTopic);\n return response.messages.filter(\n (msg) =>\n msg.p === 'hcs-10' &&\n (msg.op === 'connection_request' ||\n msg.op === 'connection_created' ||\n msg.op === 'message')\n );\n } catch (error) {\n this.logger.error('Failed to retrieve outbound messages:', error);\n return [];\n }\n }\n\n async hasConnectionCreated(\n agentAccountId: string,\n connectionId: number\n ): Promise<boolean> {\n try {\n const outBoundTopic = await this.retrieveOutboundConnectTopic(\n agentAccountId\n );\n const messages = await this.retrieveOutboundMessages(\n outBoundTopic.outboundTopic\n );\n return messages.some(\n (msg) =>\n msg.op === 'connection_created' && msg.connection_id === connectionId\n );\n } catch (error) {\n this.logger.error('Failed to check connection created:', error);\n return false;\n }\n }\n\n clearCache(): void {\n HCS10Cache.getInstance().clear();\n }\n\n /**\n * Gets message content, resolving any HRL references if needed\n * @param data The message data which might be an HRL reference\n * @returns The resolved content\n */\n async getMessageContent(data: string): Promise<string> {\n const hrlPattern = /^hcs:\\/\\/(\\d+)\\/([0-9.]+)$/;\n const match = data.match(hrlPattern);\n\n if (!match) {\n return data;\n }\n\n const [_, standard, topicId] = match;\n\n this.logger.info(\n `Resolving HRL reference: standard=${standard}, topicId=${topicId}`\n );\n\n try {\n const cdnUrl = `https://kiloscribe.com/api/inscription-cdn/${topicId}?network=${this.network}`;\n const response = await axios.get(cdnUrl);\n\n if (!response.data) {\n throw new Error(`Failed to fetch content from topic: ${topicId}`);\n }\n\n return (\n response.data.content ||\n response.data.text ||\n JSON.stringify(response.data)\n );\n } catch (error) {\n this.logger.error(\n `Error resolving HRL reference: ${\n error instanceof Error ? error.message : 'Unknown error'\n }`\n );\n throw new Error(\n `Failed to resolve HRL reference: ${\n error instanceof Error ? error.message : 'Unknown error'\n }`\n );\n }\n }\n\n /**\n * Records an outbound connection confirmation\n * @param outboundTopicId The ID of the outbound topic\n * @param connectionRequestId The ID of the connection request\n * @param confirmedRequestId The ID of the confirmed request\n * @param connectionTopicId The ID of the connection topic\n * @param operatorId The operator ID of the message sender\n * @param memo An optional memo for the message\n */\n async recordOutboundConnectionConfirmation({\n outboundTopicId,\n connectionRequestId,\n confirmedRequestId,\n connectionTopicId,\n operatorId,\n memo,\n }: {\n outboundTopicId: string;\n connectionRequestId: number;\n confirmedRequestId: number;\n connectionTopicId: string;\n operatorId: string;\n memo: string;\n }): Promise<TransactionReceipt> {\n const payload = {\n p: 'hcs-10',\n op: 'connection_created',\n connection_topic_id: connectionTopicId,\n outbound_topic_id: outboundTopicId,\n confirmed_request_id: confirmedRequestId,\n connection_request_id: connectionRequestId,\n operator_id: operatorId,\n m: memo,\n };\n // Calls the abstract submitPayload, letting the subclass handle implementation\n return await this.submitPayload(outboundTopicId, payload);\n }\n}\n\nexport class HCS10Cache {\n private static instance: HCS10Cache;\n private cache: Map<string, TopicInfo>;\n private cacheExpiry: Map<string, number>;\n private readonly CACHE_TTL = 3600000;\n\n private constructor() {\n this.cache = new Map();\n this.cacheExpiry = new Map();\n }\n\n static getInstance(): HCS10Cache {\n if (!HCS10Cache.instance) {\n HCS10Cache.instance = new HCS10Cache();\n }\n return HCS10Cache.instance;\n }\n\n set(key: string, value: TopicInfo): void {\n this.cache.set(key, value);\n this.cacheExpiry.set(key, Date.now() + this.CACHE_TTL);\n }\n\n get(key: string): TopicInfo | undefined {\n const expiry = this.cacheExpiry.get(key);\n if (expiry && expiry > Date.now()) {\n return this.cache.get(key);\n }\n if (expiry) {\n this.cache.delete(key);\n this.cacheExpiry.delete(key);\n }\n return undefined;\n }\n\n clear(): void {\n this.cache.clear();\n this.cacheExpiry.clear();\n }\n}\n"],"names":[],"mappings":";;;;;;;AAkDO,MAAe,wBAAwB,aAAa;AAAA,EAMzD,YAAY,QAA8C;AAClD,UAAA;AACN,SAAK,UAAU,OAAO;AACjB,SAAA,SAAS,OAAO,YAAY;AAAA,MAC/B,OAAO,OAAO,YAAY;AAAA,MAC1B,QAAQ;AAAA,MACR,aAAa,OAAO;AAAA,IAAA,CACrB;AACD,SAAK,aAAa,IAAI;AAAA,MACpB,OAAO;AAAA,MACP,KAAK;AAAA,IACP;AACK,SAAA,YAAY,OAAO,aAAa;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA4BvC,MAAM,wBACJ,SACA,eACwE;AACpE,QAAA;AACF,YAAM,YAAY,MAAM,KAAK,WAAW,aAAa,OAAO;AAE5D,UAAI,CAAC,WAAW;AACP,eAAA;AAAA,UACL,WAAW;AAAA,UACX,aAAa;AAAA,UACb,QAAQ;AAAA,QACV;AAAA,MAAA;AAGE,UAAA,CAAC,UAAU,YAAY,KAAK;AAC9B,eAAO,EAAE,WAAW,MAAM,aAAa,MAAM;AAAA,MAAA;AAG3C,UAAA;AACF,cAAM,gBAAgB,MAAM,KAAK,WAAW,aAAa,aAAa;AAElE,YAAA,UAAU,WAAW,UAAU,mBAAmB;AACpD,gBAAM,WAAW,OAAO,KAAK,UAAU,WAAW,KAAK,KAAK;AACtD,gBAAA,YAAY,MAAM,KAAK,WAAW;AAAA,YACtC;AAAA,YACA;AAAA,UACF;AAEA,cAAI,WAAW;AACb,mBAAO,EAAE,WAAW,MAAM,aAAa,MAAM;AAAA,UAAA;AAAA,QAC/C,OACK;AACL,gBAAM,iBAAiB,UAAU,WAAW,UAAU,WAAW,GAAG;AACpE,cAAI,cAAc,SAAA,MAAe,eAAe,YAAY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uB;AAAA,MACvB,aAAa;AAAA,MACb,GAAG;AAAA,IACL;AAEA,WAAO,MAAM,KAAK,cAAc,iBAAiB,OAAO;AAAA,EAAA;AAE5D;AAEO,MAAM,WAAW;AAAA,EAMd,cAAc;AAFtB,SAAiB,YAAY;AAGtB,SAAA,4BAAY,IAAI;AAChB,SAAA,kCAAkB,IAAI;AAAA,EAAA;AAAA,EAG7B,OAAO,cAA0B;AAC3B,QAAA,CAAC,WAAW,UAAU;AACb,iBAAA,WAAW,IAAI,WAAW;AAAA,IAAA;AAEvC,WAAO,WAAW;AAAA,EAAA;AAAA,EAGpB,IAAI,KAAa,OAAwB;AAClC,SAAA,MAAM,IAAI,KAAK,KAAK;AACzB,SAAK,YAAY,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,SAAS;AAAA,EAAA;AAAA,EAGvD,IAAI,KAAoC;AACtC,UAAM,SAAS,KAAK,YAAY,IAAI,GAAG;AACvC,QAAI,UAAU,SAAS,KAAK,IAAA,GAAO;AAC1B,aAAA,KAAK,MAAM,IAAI,GAAG;AAAA,IAAA;AAE3B,QAAI,QAAQ;AACL,WAAA,MAAM,OAAO,GAAG;AAChB,WAAA,YAAY,OAAO,GAAG;AAAA,IAAA;AAEtB,WAAA;AAAA,EAAA;AAAA,EAGT,QAAc;AACZ,SAAK,MAAM,MAAM;AACjB,SAAK,YAAY,MAAM;AAAA,EAAA;AAE3B;"}
|
|
1
|
+
{"version":3,"file":"standards-sdk.es8.js","sources":["../../src/hcs-10/base-client.ts"],"sourcesContent":["import { HederaMirrorNode } from '../services/mirror-node';\nimport { Logger, LogLevel } from '../utils/logger';\nimport { Registration } from './registrations';\nimport { HCS11Client } from '../hcs-11';\nimport { AccountResponse, NetworkType } from '../services/types';\nimport { TopicInfo } from '../services/types';\nimport { TransactionReceipt, PrivateKey, PublicKey } from '@hashgraph/sdk';\nimport axios from 'axios';\n\nexport enum Hcs10MemoType {\n INBOUND = 'inbound',\n OUTBOUND = 'outbound',\n CONNECTION = 'connection',\n}\n\nexport interface HCS10Config {\n network: 'mainnet' | 'testnet';\n logLevel?: LogLevel;\n prettyPrint?: boolean;\n feeAmount?: number;\n}\n\nexport interface HCSMessage {\n p: 'hcs-10';\n op:\n | 'connection_request'\n | 'connection_created'\n | 'message'\n | 'close_connection';\n data: string;\n created?: Date;\n consensus_timestamp?: string;\n m?: string;\n payer: string;\n outbound_topic_id?: string;\n connection_request_id?: number;\n confirmed_request_id?: number;\n connection_topic_id?: string;\n connected_account_id?: string;\n requesting_account_id?: string;\n connection_id?: number;\n sequence_number: number;\n operator_id?: string;\n reason?: string;\n close_method?: string;\n}\n\nexport interface ProfileResponse {\n profile: any;\n topicInfo?: TopicInfo;\n success: boolean;\n error?: string;\n}\n\nexport abstract class HCS10BaseClient extends Registration {\n protected network: string;\n protected logger: Logger;\n protected mirrorNode: HederaMirrorNode;\n protected feeAmount: number;\n\n constructor(config: HCS10Config) {\n super();\n this.network = config.network;\n this.logger = Logger.getInstance({\n level: config.logLevel || 'info',\n module: 'HCS10-BaseClient',\n prettyPrint: config.prettyPrint,\n });\n this.mirrorNode = new HederaMirrorNode(\n config.network as NetworkType,\n this.logger\n );\n this.feeAmount = config.feeAmount || 0.001;\n }\n\n abstract submitPayload(\n topicId: string,\n payload: object | string,\n submitKey?: PrivateKey,\n requiresFee?: boolean\n ): Promise<TransactionReceipt>;\n\n abstract getAccountAndSigner(): { accountId: string; signer: any };\n\n /**\n * Get a stream of messages from a connection topic\n * @param topicId The connection topic ID to get messages from\n * @returns A stream of filtered messages valid for connection topics\n */\n public async getMessageStream(\n topicId: string\n ): Promise<{ messages: HCSMessage[] }> {\n try {\n const messages = await this.mirrorNode.getTopicMessages(topicId);\n const validOps = ['message', 'close_connection'];\n\n const filteredMessages = messages.filter((msg) => {\n if (msg.p !== 'hcs-10' || !validOps.includes(msg.op)) {\n return false;\n }\n\n if (msg.op === 'message') {\n if (!msg.data) {\n return false;\n }\n\n if (!msg.operator_id) {\n return false;\n }\n\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n }\n\n if (msg.op === 'close_connection') {\n if (!msg.operator_id) {\n return false;\n }\n\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n }\n\n return true;\n });\n\n return {\n messages: filteredMessages,\n };\n } catch (error: any) {\n if (this.logger) {\n this.logger.error(`Error fetching messages: ${error.message}`);\n }\n return { messages: [] };\n }\n }\n\n /**\n * Checks if a user can submit to a topic and determines if a fee is required\n * @param topicId The topic ID to check\n * @param userAccountId The account ID of the user attempting to submit\n * @returns Object with canSubmit, requiresFee, and optional reason\n */\n public async canSubmitToTopic(\n topicId: string,\n userAccountId: string\n ): Promise<{ canSubmit: boolean; requiresFee: boolean; reason?: string }> {\n try {\n const topicInfo = await this.mirrorNode.getTopicInfo(topicId);\n\n if (!topicInfo) {\n return {\n canSubmit: false,\n requiresFee: false,\n reason: 'Topic does not exist',\n };\n }\n\n if (!topicInfo.submit_key?.key) {\n return { canSubmit: true, requiresFee: false };\n }\n\n try {\n const userPublicKey = await this.mirrorNode.getPublicKey(userAccountId);\n\n if (topicInfo.submit_key._type === 'ProtobufEncoded') {\n const keyBytes = Buffer.from(topicInfo.submit_key.key, 'hex');\n const hasAccess = await this.mirrorNode.checkKeyListAccess(\n keyBytes,\n userPublicKey\n );\n\n if (hasAccess) {\n return { canSubmit: true, requiresFee: false };\n }\n } else {\n const topicSubmitKey = PublicKey.fromString(topicInfo.submit_key.key);\n if (userPublicKey.toString() === topicSubmitKey.toString()) {\n return { canSubmit: true, requiresFee: false };\n }\n }\n } catch (error) {\n this.logger.error(\n `Key validation error: ${\n error instanceof Error ? error.message : String(error)\n }`\n );\n }\n\n if (\n topicInfo.fee_schedule_key?.key &&\n topicInfo.custom_fees?.fixed_fees?.length > 0\n ) {\n return {\n canSubmit: true,\n requiresFee: true,\n reason: 'Requires fee payment via HIP-991',\n };\n }\n\n return {\n canSubmit: false,\n requiresFee: false,\n reason: 'User does not have submit permission for this topic',\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n this.logger.error(`Topic submission validation error: ${errorMessage}`);\n return {\n canSubmit: false,\n requiresFee: false,\n reason: `Error: ${errorMessage}`,\n };\n }\n }\n\n /**\n * Get all messages from a topic\n * @param topicId The topic ID to get messages from\n * @returns All messages from the topic\n */\n public async getMessages(\n topicId: string\n ): Promise<{ messages: HCSMessage[] }> {\n try {\n const messages = await this.mirrorNode.getTopicMessages(topicId);\n\n const validatedMessages = messages.filter((msg) => {\n if (msg.p !== 'hcs-10') {\n return false;\n }\n\n if (msg.op === 'message') {\n if (!msg.data) {\n return false;\n }\n\n if (msg.operator_id) {\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n }\n }\n\n return true;\n });\n\n return {\n messages: validatedMessages,\n };\n } catch (error: any) {\n if (this.logger) {\n this.logger.error(`Error fetching messages: ${error.message}`);\n }\n return { messages: [] };\n }\n }\n\n public async requestAccount(account: string): Promise<AccountResponse> {\n try {\n return await this.mirrorNode.requestAccount(account);\n } catch (e) {\n this.logger.error('Failed to fetch account', e);\n throw e;\n }\n }\n\n public async getAccountMemo(accountId: string): Promise<string | null> {\n return await this.mirrorNode.getAccountMemo(accountId);\n }\n\n public async retrieveProfile(accountId: string): Promise<ProfileResponse> {\n this.logger.info(`Retrieving profile for account: ${accountId}`);\n\n try {\n const hcs11Client = new HCS11Client({\n network: this.network as 'mainnet' | 'testnet',\n auth: {\n operatorId: '0.0.0', // Read-only operations only\n },\n logLevel: 'info',\n });\n\n const profileResult = await hcs11Client.fetchProfileByAccountId(\n accountId,\n this.network\n );\n\n if (!profileResult?.success) {\n this.logger.error(\n `Failed to retrieve profile for account ID: ${accountId}`,\n profileResult?.error\n );\n return {\n profile: null,\n success: false,\n error:\n profileResult?.error ||\n `Failed to retrieve profile for account ID: ${accountId}`,\n };\n }\n\n const profile = profileResult.profile;\n let topicInfo = null;\n\n if (\n profileResult.topicInfo?.inboundTopic &&\n profileResult.topicInfo?.outboundTopic &&\n profileResult.topicInfo?.profileTopicId\n ) {\n topicInfo = {\n inboundTopic: profileResult.topicInfo.inboundTopic,\n outboundTopic: profileResult.topicInfo.outboundTopic,\n profileTopicId: profileResult.topicInfo.profileTopicId,\n };\n\n const cacheKey = `${accountId}-${this.network}`;\n HCS10Cache.getInstance().set(cacheKey, topicInfo);\n }\n\n return {\n profile,\n topicInfo,\n success: true,\n };\n } catch (error) {\n this.logger.error('Failed to retrieve profile:', error);\n return {\n profile: null,\n success: false,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n }\n\n public async retrieveOutboundConnectTopic(\n accountId: string\n ): Promise<TopicInfo> {\n this.logger.info(`Retrieving topics for account: ${accountId}`);\n\n try {\n const profileResponse = await this.retrieveProfile(accountId);\n\n if (!profileResponse?.success) {\n throw new Error(profileResponse.error || 'Failed to retrieve profile');\n }\n\n const profile = profileResponse.profile;\n\n if (!profile.inboundTopicId || !profile.outboundTopicId) {\n throw new Error(\n `Invalid HCS-11 profile for HCS-10 agent: missing inboundTopicId or outboundTopicId`\n );\n }\n\n const topicInfo = {\n inboundTopic: profile.inboundTopicId,\n outboundTopic: profile.outboundTopicId,\n profileTopicId: profile.profileTopicId,\n };\n\n const cacheKey = `${accountId}-${this.network}`;\n HCS10Cache.getInstance().set(cacheKey, topicInfo);\n return topicInfo;\n } catch (error) {\n this.logger.error('Failed to retrieve topic info:', error);\n throw error;\n }\n }\n\n public async retrieveOutboundMessages(\n agentAccountId: string\n ): Promise<HCSMessage[]> {\n try {\n const topicInfo = await this.retrieveOutboundConnectTopic(agentAccountId);\n if (!topicInfo) {\n this.logger.warn(\n `No outbound connect topic found for agentAccountId: ${agentAccountId}`\n );\n return [];\n }\n const response = await this.getMessages(topicInfo.outboundTopic);\n return response.messages.filter(\n (msg) =>\n msg.p === 'hcs-10' &&\n (msg.op === 'connection_request' ||\n msg.op === 'connection_created' ||\n msg.op === 'message')\n );\n } catch (error) {\n this.logger.error('Failed to retrieve outbound messages:', error);\n return [];\n }\n }\n\n public async hasConnectionCreated(\n agentAccountId: string,\n connectionId: number\n ): Promise<boolean> {\n try {\n const outBoundTopic = await this.retrieveOutboundConnectTopic(\n agentAccountId\n );\n const messages = await this.retrieveOutboundMessages(\n outBoundTopic.outboundTopic\n );\n return messages.some(\n (msg) =>\n msg.op === 'connection_created' && msg.connection_id === connectionId\n );\n } catch (error) {\n this.logger.error('Failed to check connection created:', error);\n return false;\n }\n }\n\n /**\n * Gets message content, resolving any HRL references if needed\n * @param data The message data which might be an HRL reference\n * @returns The resolved content\n */\n async getMessageContent(data: string): Promise<string> {\n const hrlPattern = /^hcs:\\/\\/(\\d+)\\/([0-9.]+)$/;\n const match = data.match(hrlPattern);\n\n if (!match) {\n return data;\n }\n\n const [_, standard, topicId] = match;\n\n this.logger.info(\n `Resolving HRL reference: standard=${standard}, topicId=${topicId}`\n );\n\n try {\n const cdnUrl = `https://kiloscribe.com/api/inscription-cdn/${topicId}?network=${this.network}`;\n const response = await axios.get(cdnUrl);\n\n if (!response.data) {\n throw new Error(`Failed to fetch content from topic: ${topicId}`);\n }\n\n return (\n response.data.content ||\n response.data.text ||\n JSON.stringify(response.data)\n );\n } catch (error) {\n this.logger.error(\n `Error resolving HRL reference: ${\n error instanceof Error ? error.message : 'Unknown error'\n }`\n );\n throw new Error(\n `Failed to resolve HRL reference: ${\n error instanceof Error ? error.message : 'Unknown error'\n }`\n );\n }\n }\n\n /**\n * Records an outbound connection confirmation\n * @param outboundTopicId The ID of the outbound topic\n * @param connectionRequestId The ID of the connection request\n * @param confirmedRequestId The ID of the confirmed request\n * @param connectionTopicId The ID of the connection topic\n * @param operatorId The operator ID of the message sender\n * @param memo An optional memo for the message\n */\n public async recordOutboundConnectionConfirmation({\n outboundTopicId,\n connectionRequestId,\n confirmedRequestId,\n connectionTopicId,\n operatorId,\n memo,\n }: {\n outboundTopicId: string;\n connectionRequestId: number;\n confirmedRequestId: number;\n connectionTopicId: string;\n operatorId: string;\n memo: string;\n }): Promise<TransactionReceipt> {\n const payload = {\n p: 'hcs-10',\n op: 'connection_created',\n connection_topic_id: connectionTopicId,\n outbound_topic_id: outboundTopicId,\n confirmed_request_id: confirmedRequestId,\n connection_request_id: connectionRequestId,\n operator_id: operatorId,\n m: memo,\n };\n return await this.submitPayload(outboundTopicId, payload);\n }\n\n clearCache(): void {\n HCS10Cache.getInstance().clear();\n }\n\n /**\n * Generates a standard HCS-10 memo string.\n * @param type The type of topic memo ('inbound', 'outbound', 'connection').\n * @param options Configuration options for the memo.\n * @returns The formatted memo string.\n * @protected\n */\n protected _generateHcs10Memo(\n type: Hcs10MemoType,\n options: {\n ttl?: number;\n accountId?: string;\n inboundTopicId?: string;\n connectionId?: number;\n }\n ): string {\n const ttl = options.ttl ?? 60; // Default TTL to 60 if not provided\n\n switch (type) {\n case Hcs10MemoType.INBOUND:\n if (!options.accountId) {\n throw new Error('accountId is required for inbound memo');\n }\n return `hcs-10:0:${ttl}:0:${options.accountId}`;\n case Hcs10MemoType.OUTBOUND:\n return `hcs-10:0:${ttl}:1`;\n case Hcs10MemoType.CONNECTION:\n if (!options.inboundTopicId || options.connectionId === undefined) {\n throw new Error(\n 'inboundTopicId and connectionId are required for connection memo'\n );\n }\n return `hcs-10:1:${ttl}:2:${options.inboundTopicId}:${options.connectionId}`;\n default:\n throw new Error(`Invalid HCS-10 memo type: ${type}`);\n }\n }\n\n protected async checkRegistrationStatus(\n transactionId: string,\n network: string,\n baseUrl: string\n ): Promise<{ status: 'pending' | 'success' | 'failed' }> {\n try {\n const response = await fetch(`${baseUrl}/api/request-confirm`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Network': network,\n },\n body: JSON.stringify({ transaction_id: transactionId }),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to confirm registration: ${response.statusText}`\n );\n }\n\n return await response.json();\n } catch (error) {\n this.logger.error(`Error checking registration status: ${error}`);\n throw error;\n }\n }\n\n /**\n * Validates if an operator_id follows the correct format (agentTopicId@accountId)\n * @param operatorId The operator ID to validate\n * @returns True if the format is valid, false otherwise\n */\n protected isValidOperatorId(operatorId: string): boolean {\n if (!operatorId) {\n return false;\n }\n\n const parts = operatorId.split('@');\n\n if (parts.length !== 2) {\n return false;\n }\n\n const agentTopicId = parts[0];\n const accountId = parts[1];\n\n if (!agentTopicId) {\n return false;\n }\n\n if (!accountId) {\n return false;\n }\n\n const hederaIdPattern = /^[0-9]+\\.[0-9]+\\.[0-9]+$/;\n\n if (!hederaIdPattern.test(accountId)) {\n return false;\n }\n\n if (!hederaIdPattern.test(agentTopicId)) {\n return false;\n }\n\n return true;\n }\n}\n\nexport class HCS10Cache {\n private static instance: HCS10Cache;\n private cache: Map<string, TopicInfo>;\n private cacheExpiry: Map<string, number>;\n private readonly CACHE_TTL = 3600000;\n\n private constructor() {\n this.cache = new Map();\n this.cacheExpiry = new Map();\n }\n\n static getInstance(): HCS10Cache {\n if (!HCS10Cache.instance) {\n HCS10Cache.instance = new HCS10Cache();\n }\n return HCS10Cache.instance;\n }\n\n set(key: string, value: TopicInfo): void {\n this.cache.set(key, value);\n this.cacheExpiry.set(key, Date.now() + this.CACHE_TTL);\n }\n\n get(key: string): TopicInfo | undefined {\n const expiry = this.cacheExpiry.get(key);\n if (expiry && expiry > Date.now()) {\n return this.cache.get(key);\n }\n if (expiry) {\n this.cache.delete(key);\n this.cacheExpiry.delete(key);\n }\n return undefined;\n }\n\n clear(): void {\n this.cache.clear();\n this.cacheExpiry.clear();\n }\n}\n"],"names":["Hcs10MemoType"],"mappings":";;;;;;;;AASY,IAAA,kCAAAA,mBAAL;AACLA,iBAAA,SAAU,IAAA;AACVA,iBAAA,UAAW,IAAA;AACXA,iBAAA,YAAa,IAAA;AAHHA,SAAAA;AAAA,GAAA,iBAAA,CAAA,CAAA;AA6CL,MAAe,wBAAwB,aAAa;AAAA,EAMzD,YAAY,QAAqB;AACzB,UAAA;AACN,SAAK,UAAU,OAAO;AACjB,SAAA,SAAS,OAAO,YAAY;AAAA,MAC/B,OAAO,OAAO,YA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B,QAAI,CAAC,gBAAgB,KAAK,SAAS,GAAG;AAC7B,aAAA;AAAA,IAAA;AAGT,QAAI,CAAC,gBAAgB,KAAK,YAAY,GAAG;AAChC,aAAA;AAAA,IAAA;AAGF,WAAA;AAAA,EAAA;AAEX;AAEO,MAAM,WAAW;AAAA,EAMd,cAAc;AAFtB,SAAiB,YAAY;AAGtB,SAAA,4BAAY,IAAI;AAChB,SAAA,kCAAkB,IAAI;AAAA,EAAA;AAAA,EAG7B,OAAO,cAA0B;AAC3B,QAAA,CAAC,WAAW,UAAU;AACb,iBAAA,WAAW,IAAI,WAAW;AAAA,IAAA;AAEvC,WAAO,WAAW;AAAA,EAAA;AAAA,EAGpB,IAAI,KAAa,OAAwB;AAClC,SAAA,MAAM,IAAI,KAAK,KAAK;AACzB,SAAK,YAAY,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,SAAS;AAAA,EAAA;AAAA,EAGvD,IAAI,KAAoC;AACtC,UAAM,SAAS,KAAK,YAAY,IAAI,GAAG;AACvC,QAAI,UAAU,SAAS,KAAK,IAAA,GAAO;AAC1B,aAAA,KAAK,MAAM,IAAI,GAAG;AAAA,IAAA;AAE3B,QAAI,QAAQ;AACL,WAAA,MAAM,OAAO,GAAG;AAChB,WAAA,YAAY,OAAO,GAAG;AAAA,IAAA;AAEtB,WAAA;AAAA,EAAA;AAAA,EAGT,QAAc;AACZ,SAAK,MAAM,MAAM;AACjB,SAAK,YAAY,MAAM;AAAA,EAAA;AAE3B;"}
|
|
@@ -1,13 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
function number(n) {
|
|
2
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
3
|
+
throw new Error(`Wrong positive integer: ${n}`);
|
|
4
|
+
}
|
|
5
|
+
function bytes(b, ...lengths) {
|
|
6
|
+
if (!(b instanceof Uint8Array))
|
|
7
|
+
throw new Error("Expected Uint8Array");
|
|
8
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
9
|
+
throw new Error(`Expected Uint8Array of length ${lengths}, not of length=${b.length}`);
|
|
10
|
+
}
|
|
11
|
+
function exists(instance, checkFinished = true) {
|
|
12
|
+
if (instance.destroyed)
|
|
13
|
+
throw new Error("Hash instance has been destroyed");
|
|
14
|
+
if (checkFinished && instance.finished)
|
|
15
|
+
throw new Error("Hash#digest() has already been called");
|
|
16
|
+
}
|
|
17
|
+
function output(out, instance) {
|
|
18
|
+
bytes(out);
|
|
19
|
+
const min = instance.outputLen;
|
|
20
|
+
if (out.length < min) {
|
|
21
|
+
throw new Error(`digestInto() expects output buffer of length at least ${min}`);
|
|
7
22
|
}
|
|
8
|
-
return requestedURL;
|
|
9
23
|
}
|
|
10
24
|
export {
|
|
11
|
-
|
|
25
|
+
bytes,
|
|
26
|
+
exists,
|
|
27
|
+
number,
|
|
28
|
+
output
|
|
12
29
|
};
|
|
13
30
|
//# sourceMappingURL=standards-sdk.es80.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es80.js","sources":["../../node_modules/
|
|
1
|
+
{"version":3,"file":"standards-sdk.es80.js","sources":["../../node_modules/@noble/hashes/esm/_assert.js"],"sourcesContent":["function number(n) {\n if (!Number.isSafeInteger(n) || n < 0)\n throw new Error(`Wrong positive integer: ${n}`);\n}\nfunction bool(b) {\n if (typeof b !== 'boolean')\n throw new Error(`Expected boolean, not ${b}`);\n}\nfunction bytes(b, ...lengths) {\n if (!(b instanceof Uint8Array))\n throw new Error('Expected Uint8Array');\n if (lengths.length > 0 && !lengths.includes(b.length))\n throw new Error(`Expected Uint8Array of length ${lengths}, not of length=${b.length}`);\n}\nfunction hash(hash) {\n if (typeof hash !== 'function' || typeof hash.create !== 'function')\n throw new Error('Hash should be wrapped by utils.wrapConstructor');\n number(hash.outputLen);\n number(hash.blockLen);\n}\nfunction exists(instance, checkFinished = true) {\n if (instance.destroyed)\n throw new Error('Hash instance has been destroyed');\n if (checkFinished && instance.finished)\n throw new Error('Hash#digest() has already been called');\n}\nfunction output(out, instance) {\n bytes(out);\n const min = instance.outputLen;\n if (out.length < min) {\n throw new Error(`digestInto() expects output buffer of length at least ${min}`);\n }\n}\nexport { number, bool, bytes, hash, exists, output };\nconst assert = { number, bool, bytes, hash, exists, output };\nexport default assert;\n//# sourceMappingURL=_assert.js.map"],"names":[],"mappings":"AAAA,SAAS,OAAO,GAAG;AACf,MAAI,CAAC,OAAO,cAAc,CAAC,KAAK,IAAI;AAChC,UAAM,IAAI,MAAM,2BAA2B,CAAC,EAAE;AACtD;AAKA,SAAS,MAAM,MAAM,SAAS;AAC1B,MAAI,EAAE,aAAa;AACf,UAAM,IAAI,MAAM,qBAAqB;AACzC,MAAI,QAAQ,SAAS,KAAK,CAAC,QAAQ,SAAS,EAAE,MAAM;AAChD,UAAM,IAAI,MAAM,iCAAiC,OAAO,mBAAmB,EAAE,MAAM,EAAE;AAC7F;AAOA,SAAS,OAAO,UAAU,gBAAgB,MAAM;AAC5C,MAAI,SAAS;AACT,UAAM,IAAI,MAAM,kCAAkC;AACtD,MAAI,iBAAiB,SAAS;AAC1B,UAAM,IAAI,MAAM,uCAAuC;AAC/D;AACA,SAAS,OAAO,KAAK,UAAU;AAC3B,QAAM,GAAG;AACT,QAAM,MAAM,SAAS;AACrB,MAAI,IAAI,SAAS,KAAK;AAClB,UAAM,IAAI,MAAM,yDAAyD,GAAG,EAAE;AAAA,EACtF;AACA;","x_google_ignoreList":[0]}
|