@hashgraphonline/standards-sdk 0.0.63 → 0.0.65
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/fees/fee-config-builder.d.ts.map +1 -0
- package/dist/es/fees/index.d.ts +3 -0
- package/dist/es/fees/index.d.ts.map +1 -0
- package/dist/es/fees/types.d.ts +24 -0
- package/dist/es/fees/types.d.ts.map +1 -0
- package/dist/es/hcs-10/base-client.d.ts +1 -1
- package/dist/es/hcs-10/base-client.d.ts.map +1 -1
- package/dist/es/hcs-10/browser.d.ts +20 -35
- package/dist/es/hcs-10/browser.d.ts.map +1 -1
- package/dist/es/hcs-10/index.d.ts +4 -6
- package/dist/es/hcs-10/index.d.ts.map +1 -1
- package/dist/es/hcs-10/registrations.d.ts.map +1 -1
- package/dist/es/hcs-10/sdk.d.ts +16 -8
- package/dist/es/hcs-10/sdk.d.ts.map +1 -1
- package/dist/es/hcs-10/types.d.ts +2 -62
- package/dist/es/hcs-10/types.d.ts.map +1 -1
- package/dist/es/hcs-11/agent-builder.d.ts +53 -0
- package/dist/es/hcs-11/agent-builder.d.ts.map +1 -0
- package/dist/es/hcs-11/client.d.ts +82 -0
- package/dist/es/hcs-11/client.d.ts.map +1 -0
- package/dist/es/hcs-11/index.d.ts +4 -190
- package/dist/es/hcs-11/index.d.ts.map +1 -1
- package/dist/es/hcs-11/person-builder.d.ts +29 -0
- package/dist/es/hcs-11/person-builder.d.ts.map +1 -0
- package/dist/es/hcs-11/types.d.ts +165 -0
- package/dist/es/hcs-11/types.d.ts.map +1 -0
- package/dist/es/index.d.ts +1 -0
- package/dist/es/index.d.ts.map +1 -1
- package/dist/es/services/mirror-node.d.ts +2 -1
- package/dist/es/services/mirror-node.d.ts.map +1 -1
- package/dist/es/services/types.d.ts +0 -1
- package/dist/es/services/types.d.ts.map +1 -1
- package/dist/es/standards-sdk.es.js +9 -7
- package/dist/es/standards-sdk.es.js.map +1 -1
- package/dist/es/standards-sdk.es10.js +114 -1046
- package/dist/es/standards-sdk.es10.js.map +1 -1
- package/dist/es/standards-sdk.es100.js +13 -36
- package/dist/es/standards-sdk.es100.js.map +1 -1
- package/dist/es/standards-sdk.es101.js +36 -10
- package/dist/es/standards-sdk.es101.js.map +1 -1
- package/dist/es/standards-sdk.es102.js +10 -53
- package/dist/es/standards-sdk.es102.js.map +1 -1
- package/dist/es/standards-sdk.es103.js +47 -1275
- package/dist/es/standards-sdk.es103.js.map +1 -1
- package/dist/es/standards-sdk.es104.js +1282 -25
- package/dist/es/standards-sdk.es104.js.map +1 -1
- package/dist/es/standards-sdk.es105.js +31 -5
- package/dist/es/standards-sdk.es105.js.map +1 -1
- package/dist/es/standards-sdk.es106.js +5 -158
- package/dist/es/standards-sdk.es106.js.map +1 -1
- package/dist/es/standards-sdk.es107.js +147 -781
- package/dist/es/standards-sdk.es107.js.map +1 -1
- package/dist/es/standards-sdk.es108.js +785 -166
- package/dist/es/standards-sdk.es108.js.map +1 -1
- package/dist/es/standards-sdk.es109.js +2 -2
- package/dist/es/standards-sdk.es11.js +80 -71
- package/dist/es/standards-sdk.es11.js.map +1 -1
- package/dist/es/standards-sdk.es110.js +169 -16
- package/dist/es/standards-sdk.es110.js.map +1 -1
- package/dist/es/standards-sdk.es111.js +19 -25
- package/dist/es/standards-sdk.es111.js.map +1 -1
- package/dist/es/standards-sdk.es112.js +24 -23
- package/dist/es/standards-sdk.es112.js.map +1 -1
- package/dist/es/standards-sdk.es113.js +23 -35
- package/dist/es/standards-sdk.es113.js.map +1 -1
- package/dist/es/standards-sdk.es114.js +41 -0
- package/dist/es/standards-sdk.es114.js.map +1 -0
- package/dist/es/standards-sdk.es12.js +650 -7
- package/dist/es/standards-sdk.es12.js.map +1 -1
- package/dist/es/standards-sdk.es13.js +10 -664
- package/dist/es/standards-sdk.es13.js.map +1 -1
- package/dist/es/standards-sdk.es14.js +4 -1
- package/dist/es/standards-sdk.es14.js.map +1 -1
- package/dist/es/standards-sdk.es17.js +1 -1
- package/dist/es/standards-sdk.es18.js +3 -3
- package/dist/es/standards-sdk.es18.js.map +1 -1
- package/dist/es/standards-sdk.es19.js +82 -1754
- package/dist/es/standards-sdk.es19.js.map +1 -1
- package/dist/es/standards-sdk.es20.js +5 -3
- package/dist/es/standards-sdk.es20.js.map +1 -1
- package/dist/es/standards-sdk.es21.js +1703 -4103
- package/dist/es/standards-sdk.es21.js.map +1 -1
- package/dist/es/standards-sdk.es22.js +3 -36
- package/dist/es/standards-sdk.es22.js.map +1 -1
- package/dist/es/standards-sdk.es23.js +4167 -48
- package/dist/es/standards-sdk.es23.js.map +1 -1
- package/dist/es/standards-sdk.es24.js +2 -2
- package/dist/es/standards-sdk.es25.js +36 -2
- package/dist/es/standards-sdk.es25.js.map +1 -1
- package/dist/es/standards-sdk.es26.js +46 -1039
- package/dist/es/standards-sdk.es26.js.map +1 -1
- package/dist/es/standards-sdk.es27.js +2 -5
- package/dist/es/standards-sdk.es27.js.map +1 -1
- package/dist/es/standards-sdk.es28.js +1034 -94
- package/dist/es/standards-sdk.es28.js.map +1 -1
- package/dist/es/standards-sdk.es29.js +419 -2
- package/dist/es/standards-sdk.es29.js.map +1 -1
- package/dist/es/standards-sdk.es30.js +2 -16
- package/dist/es/standards-sdk.es30.js.map +1 -1
- package/dist/es/standards-sdk.es31.js +106 -395
- package/dist/es/standards-sdk.es31.js.map +1 -1
- package/dist/es/standards-sdk.es32.js +3 -2282
- package/dist/es/standards-sdk.es32.js.map +1 -1
- package/dist/es/standards-sdk.es34.js +3 -363
- package/dist/es/standards-sdk.es34.js.map +1 -1
- package/dist/es/standards-sdk.es35.js +100 -5
- package/dist/es/standards-sdk.es35.js.map +1 -1
- package/dist/es/standards-sdk.es36.js +2 -179
- package/dist/es/standards-sdk.es36.js.map +1 -1
- package/dist/es/standards-sdk.es37.js +15 -80
- package/dist/es/standards-sdk.es37.js.map +1 -1
- package/dist/es/standards-sdk.es38.js +400 -105
- package/dist/es/standards-sdk.es38.js.map +1 -1
- package/dist/es/standards-sdk.es39.js +2282 -52
- 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 +364 -10
- package/dist/es/standards-sdk.es40.js.map +1 -1
- package/dist/es/standards-sdk.es41.js +5 -96
- package/dist/es/standards-sdk.es41.js.map +1 -1
- package/dist/es/standards-sdk.es42.js +178 -3
- package/dist/es/standards-sdk.es42.js.map +1 -1
- package/dist/es/standards-sdk.es43.js +81 -2
- package/dist/es/standards-sdk.es43.js.map +1 -1
- package/dist/es/standards-sdk.es44.js +104 -103
- package/dist/es/standards-sdk.es44.js.map +1 -1
- package/dist/es/standards-sdk.es45.js +49 -71
- package/dist/es/standards-sdk.es45.js.map +1 -1
- package/dist/es/standards-sdk.es46.js +9 -5
- package/dist/es/standards-sdk.es46.js.map +1 -1
- package/dist/es/standards-sdk.es47.js +96 -4
- package/dist/es/standards-sdk.es47.js.map +1 -1
- package/dist/es/standards-sdk.es48.js +3 -220
- package/dist/es/standards-sdk.es48.js.map +1 -1
- package/dist/es/standards-sdk.es49.js +2 -58
- package/dist/es/standards-sdk.es49.js.map +1 -1
- package/dist/es/standards-sdk.es5.js +393 -891
- package/dist/es/standards-sdk.es5.js.map +1 -1
- package/dist/es/standards-sdk.es50.js +112 -68
- package/dist/es/standards-sdk.es50.js.map +1 -1
- package/dist/es/standards-sdk.es51.js +74 -3
- package/dist/es/standards-sdk.es51.js.map +1 -1
- package/dist/es/standards-sdk.es52.js +5 -31
- package/dist/es/standards-sdk.es52.js.map +1 -1
- package/dist/es/standards-sdk.es53.js +4 -62
- package/dist/es/standards-sdk.es53.js.map +1 -1
- package/dist/es/standards-sdk.es54.js +217 -46
- package/dist/es/standards-sdk.es54.js.map +1 -1
- package/dist/es/standards-sdk.es55.js +57 -9
- package/dist/es/standards-sdk.es55.js.map +1 -1
- package/dist/es/standards-sdk.es56.js +68 -64
- package/dist/es/standards-sdk.es56.js.map +1 -1
- package/dist/es/standards-sdk.es57.js +32 -6
- package/dist/es/standards-sdk.es57.js.map +1 -1
- package/dist/es/standards-sdk.es58.js +61 -13
- package/dist/es/standards-sdk.es58.js.map +1 -1
- package/dist/es/standards-sdk.es59.js +50 -7
- package/dist/es/standards-sdk.es59.js.map +1 -1
- package/dist/es/standards-sdk.es60.js +10 -45
- package/dist/es/standards-sdk.es60.js.map +1 -1
- package/dist/es/standards-sdk.es61.js +65 -2
- package/dist/es/standards-sdk.es61.js.map +1 -1
- package/dist/es/standards-sdk.es62.js +5 -135
- package/dist/es/standards-sdk.es62.js.map +1 -1
- package/dist/es/standards-sdk.es63.js +13 -170
- package/dist/es/standards-sdk.es63.js.map +1 -1
- package/dist/es/standards-sdk.es64.js +4 -10
- package/dist/es/standards-sdk.es64.js.map +1 -1
- package/dist/es/standards-sdk.es65.js +45 -13
- package/dist/es/standards-sdk.es65.js.map +1 -1
- package/dist/es/standards-sdk.es66.js +2 -4
- package/dist/es/standards-sdk.es66.js.map +1 -1
- package/dist/es/standards-sdk.es67.js +134 -30
- package/dist/es/standards-sdk.es67.js.map +1 -1
- package/dist/es/standards-sdk.es68.js +171 -14
- package/dist/es/standards-sdk.es68.js.map +1 -1
- package/dist/es/standards-sdk.es69.js +13 -4
- package/dist/es/standards-sdk.es69.js.map +1 -1
- package/dist/es/standards-sdk.es7.js +959 -94
- package/dist/es/standards-sdk.es7.js.map +1 -1
- package/dist/es/standards-sdk.es70.js +13 -4
- package/dist/es/standards-sdk.es70.js.map +1 -1
- package/dist/es/standards-sdk.es71.js +31 -15
- package/dist/es/standards-sdk.es71.js.map +1 -1
- package/dist/es/standards-sdk.es72.js +14 -4
- package/dist/es/standards-sdk.es72.js.map +1 -1
- package/dist/es/standards-sdk.es73.js +4 -39
- package/dist/es/standards-sdk.es73.js.map +1 -1
- package/dist/es/standards-sdk.es74.js +4 -40
- package/dist/es/standards-sdk.es74.js.map +1 -1
- package/dist/es/standards-sdk.es75.js +15 -36
- package/dist/es/standards-sdk.es75.js.map +1 -1
- package/dist/es/standards-sdk.es76.js +5 -78
- package/dist/es/standards-sdk.es76.js.map +1 -1
- package/dist/es/standards-sdk.es77.js +39 -3
- package/dist/es/standards-sdk.es77.js.map +1 -1
- package/dist/es/standards-sdk.es78.js +40 -2
- package/dist/es/standards-sdk.es78.js.map +1 -1
- package/dist/es/standards-sdk.es79.js +37 -2
- package/dist/es/standards-sdk.es79.js.map +1 -1
- package/dist/es/standards-sdk.es8.js +1049 -393
- package/dist/es/standards-sdk.es8.js.map +1 -1
- package/dist/es/standards-sdk.es80.js +67 -408
- package/dist/es/standards-sdk.es80.js.map +1 -1
- package/dist/es/standards-sdk.es81.js +3 -2
- package/dist/es/standards-sdk.es81.js.map +1 -1
- package/dist/es/standards-sdk.es82.js +2 -120
- package/dist/es/standards-sdk.es82.js.map +1 -1
- package/dist/es/standards-sdk.es83.js +2 -34
- package/dist/es/standards-sdk.es83.js.map +1 -1
- package/dist/es/standards-sdk.es84.js +30 -29
- package/dist/es/standards-sdk.es84.js.map +1 -1
- package/dist/es/standards-sdk.es85.js +33 -9
- package/dist/es/standards-sdk.es85.js.map +1 -1
- package/dist/es/standards-sdk.es86.js +9 -34
- package/dist/es/standards-sdk.es86.js.map +1 -1
- package/dist/es/standards-sdk.es87.js +34 -2
- package/dist/es/standards-sdk.es87.js.map +1 -1
- package/dist/es/standards-sdk.es88.js +2 -84
- package/dist/es/standards-sdk.es88.js.map +1 -1
- package/dist/es/standards-sdk.es89.js +82 -21
- package/dist/es/standards-sdk.es89.js.map +1 -1
- package/dist/es/standards-sdk.es9.js +2 -2
- package/dist/es/standards-sdk.es9.js.map +1 -1
- package/dist/es/standards-sdk.es90.js +21 -146
- package/dist/es/standards-sdk.es90.js.map +1 -1
- package/dist/es/standards-sdk.es91.js +130 -73
- package/dist/es/standards-sdk.es91.js.map +1 -1
- package/dist/es/standards-sdk.es92.js +81 -185
- package/dist/es/standards-sdk.es92.js.map +1 -1
- package/dist/es/standards-sdk.es93.js +163 -406
- package/dist/es/standards-sdk.es93.js.map +1 -1
- package/dist/es/standards-sdk.es94.js +432 -19
- package/dist/es/standards-sdk.es94.js.map +1 -1
- package/dist/es/standards-sdk.es95.js +16 -130
- package/dist/es/standards-sdk.es95.js.map +1 -1
- package/dist/es/standards-sdk.es96.js +131 -10
- package/dist/es/standards-sdk.es96.js.map +1 -1
- package/dist/es/standards-sdk.es97.js +11 -22
- package/dist/es/standards-sdk.es97.js.map +1 -1
- package/dist/es/standards-sdk.es98.js +22 -22
- package/dist/es/standards-sdk.es98.js.map +1 -1
- package/dist/es/standards-sdk.es99.js +21 -13
- package/dist/es/standards-sdk.es99.js.map +1 -1
- package/dist/es/utils/logger.d.ts +1 -0
- package/dist/es/utils/logger.d.ts.map +1 -1
- package/dist/es/utils/types.d.ts +2 -0
- package/dist/es/utils/types.d.ts.map +1 -0
- package/dist/umd/fees/fee-config-builder.d.ts.map +1 -0
- package/dist/umd/fees/index.d.ts +3 -0
- package/dist/umd/fees/index.d.ts.map +1 -0
- package/dist/umd/fees/types.d.ts +24 -0
- package/dist/umd/fees/types.d.ts.map +1 -0
- package/dist/umd/hcs-10/base-client.d.ts +1 -1
- package/dist/umd/hcs-10/base-client.d.ts.map +1 -1
- package/dist/umd/hcs-10/browser.d.ts +20 -35
- package/dist/umd/hcs-10/browser.d.ts.map +1 -1
- package/dist/umd/hcs-10/index.d.ts +4 -6
- package/dist/umd/hcs-10/index.d.ts.map +1 -1
- package/dist/umd/hcs-10/registrations.d.ts.map +1 -1
- package/dist/umd/hcs-10/sdk.d.ts +16 -8
- package/dist/umd/hcs-10/sdk.d.ts.map +1 -1
- package/dist/umd/hcs-10/types.d.ts +2 -62
- package/dist/umd/hcs-10/types.d.ts.map +1 -1
- package/dist/umd/hcs-11/agent-builder.d.ts +53 -0
- package/dist/umd/hcs-11/agent-builder.d.ts.map +1 -0
- package/dist/umd/hcs-11/client.d.ts +82 -0
- package/dist/umd/hcs-11/client.d.ts.map +1 -0
- package/dist/umd/hcs-11/index.d.ts +4 -190
- package/dist/umd/hcs-11/index.d.ts.map +1 -1
- package/dist/umd/hcs-11/person-builder.d.ts +29 -0
- package/dist/umd/hcs-11/person-builder.d.ts.map +1 -0
- package/dist/umd/hcs-11/types.d.ts +165 -0
- package/dist/umd/hcs-11/types.d.ts.map +1 -0
- package/dist/umd/index.d.ts +1 -0
- package/dist/umd/index.d.ts.map +1 -1
- package/dist/umd/services/mirror-node.d.ts +2 -1
- package/dist/umd/services/mirror-node.d.ts.map +1 -1
- package/dist/umd/services/types.d.ts +0 -1
- package/dist/umd/services/types.d.ts.map +1 -1
- package/dist/umd/standards-sdk.umd.js +7 -7
- package/dist/umd/standards-sdk.umd.js.map +1 -1
- package/dist/umd/utils/logger.d.ts +1 -0
- package/dist/umd/utils/logger.d.ts.map +1 -1
- package/dist/umd/utils/types.d.ts +2 -0
- package/dist/umd/utils/types.d.ts.map +1 -0
- package/package.json +6 -4
- package/dist/es/hcs-10/agent-builder.d.ts +0 -45
- package/dist/es/hcs-10/agent-builder.d.ts.map +0 -1
- package/dist/es/hcs-10/fee-config-builder.d.ts.map +0 -1
- package/dist/umd/hcs-10/agent-builder.d.ts +0 -45
- package/dist/umd/hcs-10/agent-builder.d.ts.map +0 -1
- package/dist/umd/hcs-10/fee-config-builder.d.ts.map +0 -1
- /package/dist/es/{hcs-10 → fees}/fee-config-builder.d.ts +0 -0
- /package/dist/umd/{hcs-10 → fees}/fee-config-builder.d.ts +0 -0
|
@@ -1,987 +1,489 @@
|
|
|
1
|
-
import Buffer from "./standards-sdk.
|
|
2
|
-
import { Client, PrivateKey, AccountCreateTransaction, Hbar, CustomFixedFee, AccountId, KeyList, TopicCreateTransaction, PublicKey, TopicMessageSubmitTransaction, TopicId, Transaction } from "@hashgraph/sdk";
|
|
3
|
-
import { AccountCreationError, TopicCreationError, ConnectionConfirmationError, PayloadSizeError } from "./standards-sdk.es6.js";
|
|
4
|
-
import { InscriptionSDK } from "./standards-sdk.es24.js";
|
|
1
|
+
import Buffer from "./standards-sdk.es21.js";
|
|
5
2
|
import { Logger } from "./standards-sdk.es14.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
|
|
3
|
+
import { Registration } from "./standards-sdk.es9.js";
|
|
4
|
+
import { HCS11Client } from "./standards-sdk.es12.js";
|
|
5
|
+
import { PublicKey } from "@hashgraph/sdk";
|
|
6
|
+
import "./standards-sdk.es25.js";
|
|
7
|
+
import { HederaMirrorNode } from "./standards-sdk.es18.js";
|
|
8
|
+
import axios from "./standards-sdk.es26.js";
|
|
9
|
+
var Hcs10MemoType = /* @__PURE__ */ ((Hcs10MemoType2) => {
|
|
10
|
+
Hcs10MemoType2["INBOUND"] = "inbound";
|
|
11
|
+
Hcs10MemoType2["OUTBOUND"] = "outbound";
|
|
12
|
+
Hcs10MemoType2["CONNECTION"] = "connection";
|
|
13
|
+
return Hcs10MemoType2;
|
|
14
|
+
})(Hcs10MemoType || {});
|
|
15
|
+
class HCS10BaseClient extends Registration {
|
|
12
16
|
constructor(config) {
|
|
13
|
-
super(
|
|
14
|
-
network: config.network,
|
|
15
|
-
logLevel: config.logLevel,
|
|
16
|
-
prettyPrint: config.prettyPrint,
|
|
17
|
-
feeAmount: config.feeAmount
|
|
18
|
-
});
|
|
19
|
-
this.client = config.network === "mainnet" ? Client.forMainnet() : Client.forTestnet();
|
|
20
|
-
this.operatorPrivateKey = PrivateKey.fromString(config.operatorPrivateKey);
|
|
17
|
+
super();
|
|
21
18
|
this.network = config.network;
|
|
22
|
-
this.client.setOperator(
|
|
23
|
-
config.operatorId,
|
|
24
|
-
this.operatorPrivateKey.toString()
|
|
25
|
-
);
|
|
26
19
|
this.logger = Logger.getInstance({
|
|
27
20
|
level: config.logLevel || "info",
|
|
28
|
-
module: "
|
|
29
|
-
|
|
30
|
-
this.guardedRegistryBaseUrl = config.guardedRegistryBaseUrl || "https://moonscape.tech";
|
|
31
|
-
this.hcs11Client = new HCS11Client({
|
|
32
|
-
network: config.network,
|
|
33
|
-
auth: {
|
|
34
|
-
operatorId: config.operatorId,
|
|
35
|
-
privateKey: config.operatorPrivateKey
|
|
36
|
-
},
|
|
37
|
-
logLevel: config.logLevel
|
|
21
|
+
module: "HCS10-BaseClient",
|
|
22
|
+
prettyPrint: config.prettyPrint
|
|
38
23
|
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Creates a new Hedera account
|
|
45
|
-
* @returns Object with account ID and private key
|
|
46
|
-
*/
|
|
47
|
-
async createAccount() {
|
|
48
|
-
this.logger.info("Creating new account");
|
|
49
|
-
const newKey = PrivateKey.generate();
|
|
50
|
-
const accountTransaction = new AccountCreateTransaction().setKey(newKey.publicKey).setInitialBalance(new Hbar(10));
|
|
51
|
-
this.logger.debug("Executing account creation transaction");
|
|
52
|
-
const accountResponse = await accountTransaction.execute(this.client);
|
|
53
|
-
const accountReceipt = await accountResponse.getReceipt(this.client);
|
|
54
|
-
const newAccountId = accountReceipt.accountId;
|
|
55
|
-
if (!newAccountId) {
|
|
56
|
-
this.logger.error("Account creation failed: accountId is null");
|
|
57
|
-
throw new AccountCreationError(
|
|
58
|
-
"Failed to create account: accountId is null"
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
this.logger.info(
|
|
62
|
-
`Account created successfully: ${newAccountId.toString()}`
|
|
24
|
+
this.mirrorNode = new HederaMirrorNode(
|
|
25
|
+
config.network,
|
|
26
|
+
this.logger
|
|
63
27
|
);
|
|
64
|
-
|
|
65
|
-
accountId: newAccountId.toString(),
|
|
66
|
-
privateKey: newKey.toString()
|
|
67
|
-
};
|
|
28
|
+
this.feeAmount = config.feeAmount || 1e-3;
|
|
68
29
|
}
|
|
69
30
|
/**
|
|
70
|
-
*
|
|
71
|
-
* @param
|
|
72
|
-
* @
|
|
73
|
-
* @param ttl Optional Time-To-Live for the topic memo, defaults to 60
|
|
74
|
-
* @param feeConfigBuilder Optional fee configuration builder for fee-based topics
|
|
75
|
-
* @returns The topic ID of the created inbound topic
|
|
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
|
|
76
34
|
*/
|
|
77
|
-
async
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
switch (topicType) {
|
|
85
|
-
case InboundTopicType.PUBLIC:
|
|
86
|
-
submitKey = false;
|
|
87
|
-
break;
|
|
88
|
-
case InboundTopicType.CONTROLLED:
|
|
89
|
-
submitKey = true;
|
|
90
|
-
break;
|
|
91
|
-
case InboundTopicType.FEE_BASED:
|
|
92
|
-
submitKey = true;
|
|
93
|
-
if (!feeConfigBuilder) {
|
|
94
|
-
throw new Error(
|
|
95
|
-
"Fee configuration builder is required for fee-based topics"
|
|
96
|
-
);
|
|
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;
|
|
97
42
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
);
|
|
128
|
-
let pfpTopicId = config.existingPfpTopicId || "";
|
|
129
|
-
if (!pfpTopicId && config.pfpBuffer && config.pfpBuffer.length > 0) {
|
|
130
|
-
this.logger.info("Inscribing new profile picture");
|
|
131
|
-
const pfpResult = await this.inscribePfp(
|
|
132
|
-
config.pfpBuffer,
|
|
133
|
-
config.pfpFileName
|
|
134
|
-
);
|
|
135
|
-
pfpTopicId = pfpResult.pfpTopicId;
|
|
136
|
-
this.logger.info(
|
|
137
|
-
`Profile picture inscribed with topic ID: ${pfpTopicId}`
|
|
138
|
-
);
|
|
139
|
-
} else if (config.existingPfpTopicId) {
|
|
140
|
-
this.logger.info(
|
|
141
|
-
`Using existing profile picture with topic ID: ${config.existingPfpTopicId}`
|
|
142
|
-
);
|
|
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: [] };
|
|
143
72
|
}
|
|
144
|
-
const profileResult = await this.storeHCS11Profile(
|
|
145
|
-
config.name,
|
|
146
|
-
config.description,
|
|
147
|
-
inboundTopicId,
|
|
148
|
-
outboundTopicId,
|
|
149
|
-
config.capabilities,
|
|
150
|
-
config.metadata,
|
|
151
|
-
config.pfpBuffer && config.pfpBuffer.length > 0 ? config.pfpBuffer : void 0,
|
|
152
|
-
config.pfpFileName,
|
|
153
|
-
config.existingPfpTopicId
|
|
154
|
-
);
|
|
155
|
-
const profileTopicId = profileResult.profileTopicId;
|
|
156
|
-
this.logger.info(`Profile stored with topic ID: ${profileTopicId}`);
|
|
157
|
-
return {
|
|
158
|
-
inboundTopicId,
|
|
159
|
-
outboundTopicId,
|
|
160
|
-
pfpTopicId,
|
|
161
|
-
profileTopicId
|
|
162
|
-
};
|
|
163
73
|
}
|
|
164
74
|
/**
|
|
165
|
-
*
|
|
166
|
-
* @param
|
|
167
|
-
* @param
|
|
168
|
-
* @returns
|
|
75
|
+
* Checks if a user can submit to a topic and determines if a fee is required
|
|
76
|
+
* @param topicId The topic ID to check
|
|
77
|
+
* @param userAccountId The account ID of the user attempting to submit
|
|
78
|
+
* @returns Object with canSubmit, requiresFee, and optional reason
|
|
169
79
|
*/
|
|
170
|
-
async
|
|
80
|
+
async canSubmitToTopic(topicId, userAccountId) {
|
|
171
81
|
try {
|
|
172
|
-
this.
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
82
|
+
const topicInfo = await this.mirrorNode.getTopicInfo(topicId);
|
|
83
|
+
if (!topicInfo) {
|
|
84
|
+
return {
|
|
85
|
+
canSubmit: false,
|
|
86
|
+
requiresFee: false,
|
|
87
|
+
reason: "Topic does not exist"
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (!topicInfo.submit_key?.key) {
|
|
91
|
+
return { canSubmit: true, requiresFee: false };
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const userPublicKey = await this.mirrorNode.getPublicKey(userAccountId);
|
|
95
|
+
if (topicInfo.submit_key._type === "ProtobufEncoded") {
|
|
96
|
+
const keyBytes = Buffer.from(topicInfo.submit_key.key, "hex");
|
|
97
|
+
const hasAccess = await this.mirrorNode.checkKeyListAccess(
|
|
98
|
+
keyBytes,
|
|
99
|
+
userPublicKey
|
|
100
|
+
);
|
|
101
|
+
if (hasAccess) {
|
|
102
|
+
return { canSubmit: true, requiresFee: false };
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
const topicSubmitKey = PublicKey.fromString(topicInfo.submit_key.key);
|
|
106
|
+
if (userPublicKey.toString() === topicSubmitKey.toString()) {
|
|
107
|
+
return { canSubmit: true, requiresFee: false };
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
} catch (error) {
|
|
178
111
|
this.logger.error(
|
|
179
|
-
`
|
|
180
|
-
);
|
|
181
|
-
throw new Error(
|
|
182
|
-
imageResult?.error || "Failed to inscribe profile picture"
|
|
112
|
+
`Key validation error: ${error instanceof Error ? error.message : String(error)}`
|
|
183
113
|
);
|
|
184
114
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
115
|
+
if (topicInfo.fee_schedule_key?.key && topicInfo.custom_fees?.fixed_fees?.length > 0) {
|
|
116
|
+
return {
|
|
117
|
+
canSubmit: true,
|
|
118
|
+
requiresFee: true,
|
|
119
|
+
reason: "Requires fee payment via HIP-991"
|
|
120
|
+
};
|
|
121
|
+
}
|
|
188
122
|
return {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
123
|
+
canSubmit: false,
|
|
124
|
+
requiresFee: false,
|
|
125
|
+
reason: "User does not have submit permission for this topic"
|
|
192
126
|
};
|
|
193
127
|
} catch (error) {
|
|
194
|
-
|
|
128
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
129
|
+
this.logger.error(`Topic submission validation error: ${errorMessage}`);
|
|
195
130
|
return {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
error: error.message
|
|
131
|
+
canSubmit: false,
|
|
132
|
+
requiresFee: false,
|
|
133
|
+
reason: `Error: ${errorMessage}`
|
|
200
134
|
};
|
|
201
135
|
}
|
|
202
136
|
}
|
|
203
137
|
/**
|
|
204
|
-
*
|
|
205
|
-
* @param
|
|
206
|
-
* @
|
|
207
|
-
* @param inboundTopicId Inbound topic ID
|
|
208
|
-
* @param outboundTopicId Outbound topic ID
|
|
209
|
-
* @param capabilities Agent capability tags
|
|
210
|
-
* @param metadata Additional metadata
|
|
211
|
-
* @param pfpBuffer Optional profile picture buffer
|
|
212
|
-
* @param pfpFileName Optional profile picture filename
|
|
213
|
-
* @returns Response with topic IDs and transaction ID
|
|
138
|
+
* Get all messages from a topic
|
|
139
|
+
* @param topicId The topic ID to get messages from
|
|
140
|
+
* @returns All messages from the topic
|
|
214
141
|
*/
|
|
215
|
-
async
|
|
142
|
+
async getMessages(topicId) {
|
|
216
143
|
try {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (!pfpResult.success) {
|
|
222
|
-
this.logger.error(
|
|
223
|
-
"Failed to inscribe profile picture, continuing without PFP"
|
|
224
|
-
);
|
|
225
|
-
} else {
|
|
226
|
-
pfpTopicId = pfpResult.pfpTopicId;
|
|
144
|
+
const messages = await this.mirrorNode.getTopicMessages(topicId);
|
|
145
|
+
const validatedMessages = messages.filter((msg) => {
|
|
146
|
+
if (msg.p !== "hcs-10") {
|
|
147
|
+
return false;
|
|
227
148
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
149
|
+
if (msg.op === "message") {
|
|
150
|
+
if (!msg.data) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
if (msg.operator_id) {
|
|
154
|
+
if (!this.isValidOperatorId(msg.operator_id)) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
});
|
|
161
|
+
return {
|
|
162
|
+
messages: validatedMessages
|
|
163
|
+
};
|
|
164
|
+
} catch (error) {
|
|
165
|
+
if (this.logger) {
|
|
166
|
+
this.logger.error(`Error fetching messages: ${error.message}`);
|
|
232
167
|
}
|
|
233
|
-
|
|
234
|
-
|
|
168
|
+
return { messages: [] };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
async requestAccount(account) {
|
|
172
|
+
try {
|
|
173
|
+
return await this.mirrorNode.requestAccount(account);
|
|
174
|
+
} catch (e) {
|
|
175
|
+
this.logger.error("Failed to fetch account", e);
|
|
176
|
+
throw e;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async getAccountMemo(accountId) {
|
|
180
|
+
return await this.mirrorNode.getAccountMemo(accountId);
|
|
181
|
+
}
|
|
182
|
+
async retrieveProfile(accountId) {
|
|
183
|
+
this.logger.info(`Retrieving profile for account: ${accountId}`);
|
|
184
|
+
try {
|
|
185
|
+
const hcs11Client = new HCS11Client({
|
|
186
|
+
network: this.network,
|
|
187
|
+
auth: {
|
|
188
|
+
operatorId: "0.0.0"
|
|
189
|
+
// Read-only operations only
|
|
190
|
+
},
|
|
191
|
+
logLevel: "info"
|
|
235
192
|
});
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
})) : void 0;
|
|
240
|
-
const profile = this.hcs11Client.createAIAgentProfile(
|
|
241
|
-
agentName,
|
|
242
|
-
agentType,
|
|
243
|
-
capabilities,
|
|
244
|
-
metadata.model || "unknown",
|
|
245
|
-
{
|
|
246
|
-
alias: agentName.toLowerCase().replace(/\s+/g, "_"),
|
|
247
|
-
bio: agentDescription,
|
|
248
|
-
profileImage: pfpTopicId ? `hcs://1/${pfpTopicId}` : void 0,
|
|
249
|
-
socials: formattedSocials,
|
|
250
|
-
properties: metadata.properties,
|
|
251
|
-
inboundTopicId,
|
|
252
|
-
outboundTopicId,
|
|
253
|
-
creator: metadata.creator
|
|
254
|
-
}
|
|
255
|
-
);
|
|
256
|
-
const profileResult = await this.hcs11Client.createAndInscribeProfile(
|
|
257
|
-
profile,
|
|
258
|
-
true
|
|
193
|
+
const profileResult = await hcs11Client.fetchProfileByAccountId(
|
|
194
|
+
accountId,
|
|
195
|
+
this.network
|
|
259
196
|
);
|
|
260
|
-
if (!profileResult
|
|
261
|
-
this.logger.error(
|
|
262
|
-
|
|
197
|
+
if (!profileResult?.success) {
|
|
198
|
+
this.logger.error(
|
|
199
|
+
`Failed to retrieve profile for account ID: ${accountId}`,
|
|
200
|
+
profileResult?.error
|
|
201
|
+
);
|
|
202
|
+
return {
|
|
203
|
+
profile: null,
|
|
204
|
+
success: false,
|
|
205
|
+
error: profileResult?.error || `Failed to retrieve profile for account ID: ${accountId}`
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
const profile = profileResult.profile;
|
|
209
|
+
let topicInfo = null;
|
|
210
|
+
if (profileResult.topicInfo?.inboundTopic && profileResult.topicInfo?.outboundTopic && profileResult.topicInfo?.profileTopicId) {
|
|
211
|
+
topicInfo = {
|
|
212
|
+
inboundTopic: profileResult.topicInfo.inboundTopic,
|
|
213
|
+
outboundTopic: profileResult.topicInfo.outboundTopic,
|
|
214
|
+
profileTopicId: profileResult.topicInfo.profileTopicId
|
|
215
|
+
};
|
|
216
|
+
const cacheKey = `${accountId}-${this.network}`;
|
|
217
|
+
HCS10Cache.getInstance().set(cacheKey, topicInfo);
|
|
263
218
|
}
|
|
264
|
-
this.logger.info(
|
|
265
|
-
`Profile inscribed with topic ID: ${profileResult.profileTopicId}, transaction ID: ${profileResult.transactionId}`
|
|
266
|
-
);
|
|
267
219
|
return {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
transactionId: profileResult.transactionId,
|
|
220
|
+
profile,
|
|
221
|
+
topicInfo,
|
|
271
222
|
success: true
|
|
272
223
|
};
|
|
273
224
|
} catch (error) {
|
|
274
|
-
this.logger.error(
|
|
225
|
+
this.logger.error("Failed to retrieve profile:", error);
|
|
275
226
|
return {
|
|
276
|
-
|
|
277
|
-
pfpTopicId: "",
|
|
278
|
-
transactionId: "",
|
|
227
|
+
profile: null,
|
|
279
228
|
success: false,
|
|
280
|
-
error: error.message
|
|
229
|
+
error: error instanceof Error ? error.message : String(error)
|
|
281
230
|
};
|
|
282
231
|
}
|
|
283
232
|
}
|
|
284
|
-
async
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
AccountId.fromString(feeConfig.feeCollectorAccountId)
|
|
291
|
-
);
|
|
292
|
-
let exemptAccountIds = [
|
|
293
|
-
...feeConfig.exemptAccounts || [],
|
|
294
|
-
...additionalExemptAccounts
|
|
295
|
-
];
|
|
296
|
-
console.log("exemptAccountIds", exemptAccountIds);
|
|
297
|
-
if (exemptAccountIds.length > 0) {
|
|
298
|
-
const uniqueExemptAccountIds = Array.from(new Set(exemptAccountIds));
|
|
299
|
-
const filteredExemptAccounts = uniqueExemptAccountIds.filter(
|
|
300
|
-
(account) => account !== this.client.operatorAccountId?.toString()
|
|
301
|
-
);
|
|
302
|
-
let exemptKeys = [];
|
|
303
|
-
if (filteredExemptAccounts.length > 0) {
|
|
304
|
-
try {
|
|
305
|
-
exemptKeys = await accountIdsToExemptKeys(
|
|
306
|
-
filteredExemptAccounts,
|
|
307
|
-
this.network,
|
|
308
|
-
this.logger
|
|
309
|
-
);
|
|
310
|
-
} catch (error) {
|
|
311
|
-
this.logger.warn(
|
|
312
|
-
`Error getting exempt keys: ${error}, continuing without exempt keys`
|
|
313
|
-
);
|
|
314
|
-
}
|
|
233
|
+
async retrieveOutboundConnectTopic(accountId) {
|
|
234
|
+
this.logger.info(`Retrieving topics for account: ${accountId}`);
|
|
235
|
+
try {
|
|
236
|
+
const profileResponse = await this.retrieveProfile(accountId);
|
|
237
|
+
if (!profileResponse?.success) {
|
|
238
|
+
throw new Error(profileResponse.error || "Failed to retrieve profile");
|
|
315
239
|
}
|
|
316
|
-
|
|
317
|
-
|
|
240
|
+
const profile = profileResponse.profile;
|
|
241
|
+
if (!profile.inboundTopicId || !profile.outboundTopicId) {
|
|
242
|
+
throw new Error(
|
|
243
|
+
`Invalid HCS-11 profile for HCS-10 agent: missing inboundTopicId or outboundTopicId`
|
|
244
|
+
);
|
|
318
245
|
}
|
|
246
|
+
const topicInfo = {
|
|
247
|
+
inboundTopic: profile.inboundTopicId,
|
|
248
|
+
outboundTopic: profile.outboundTopicId,
|
|
249
|
+
profileTopicId: profile.profileTopicId
|
|
250
|
+
};
|
|
251
|
+
const cacheKey = `${accountId}-${this.network}`;
|
|
252
|
+
HCS10Cache.getInstance().set(cacheKey, topicInfo);
|
|
253
|
+
return topicInfo;
|
|
254
|
+
} catch (error) {
|
|
255
|
+
this.logger.error("Failed to retrieve topic info:", error);
|
|
256
|
+
throw error;
|
|
319
257
|
}
|
|
320
|
-
transaction.setFeeScheduleKey(this.client.operatorPublicKey).setCustomFees([customFee]);
|
|
321
258
|
}
|
|
322
|
-
|
|
323
|
-
* Handles a connection request from another account
|
|
324
|
-
* @param inboundTopicId Inbound topic ID
|
|
325
|
-
* @param requestingAccountId Requesting account ID
|
|
326
|
-
* @param connectionRequestId Connection request ID
|
|
327
|
-
* @param connectionFeeConfig Optional fee configuration for the connection topic
|
|
328
|
-
* @param ttl Optional ttl parameter with default
|
|
329
|
-
* @returns Response with connection details
|
|
330
|
-
*/
|
|
331
|
-
async handleConnectionRequest(inboundTopicId, requestingAccountId, connectionRequestId, connectionFeeConfig, ttl = 60) {
|
|
332
|
-
const memo = this._generateHcs10Memo(Hcs10MemoType.CONNECTION, {
|
|
333
|
-
ttl,
|
|
334
|
-
inboundTopicId,
|
|
335
|
-
connectionId: connectionRequestId
|
|
336
|
-
});
|
|
337
|
-
this.logger.info(
|
|
338
|
-
`Handling connection request ${connectionRequestId} from ${requestingAccountId}`
|
|
339
|
-
);
|
|
340
|
-
const accountId = this.getClient().operatorAccountId?.toString();
|
|
341
|
-
if (!accountId) {
|
|
342
|
-
throw new Error("Failed to retrieve operator account ID");
|
|
343
|
-
}
|
|
344
|
-
let requesterKey = await this.mirrorNode.getPublicKey(requestingAccountId);
|
|
345
|
-
const accountKey = await this.mirrorNode.getPublicKey(accountId);
|
|
346
|
-
if (!accountKey) {
|
|
347
|
-
throw new Error("Failed to retrieve public key");
|
|
348
|
-
}
|
|
349
|
-
const thresholdKey = new KeyList([accountKey, requesterKey], 1);
|
|
350
|
-
let connectionTopicId;
|
|
259
|
+
async retrieveOutboundMessages(agentAccountId) {
|
|
351
260
|
try {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
exemptAccounts: [...feeConfig.exemptAccounts || []]
|
|
357
|
-
};
|
|
358
|
-
connectionTopicId = await this.createTopic(
|
|
359
|
-
memo,
|
|
360
|
-
thresholdKey,
|
|
361
|
-
thresholdKey,
|
|
362
|
-
modifiedFeeConfig
|
|
363
|
-
);
|
|
364
|
-
} else {
|
|
365
|
-
connectionTopicId = await this.createTopic(
|
|
366
|
-
memo,
|
|
367
|
-
thresholdKey,
|
|
368
|
-
thresholdKey
|
|
261
|
+
const topicInfo = await this.retrieveOutboundConnectTopic(agentAccountId);
|
|
262
|
+
if (!topicInfo) {
|
|
263
|
+
this.logger.warn(
|
|
264
|
+
`No outbound connect topic found for agentAccountId: ${agentAccountId}`
|
|
369
265
|
);
|
|
266
|
+
return [];
|
|
370
267
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
throw new TopicCreationError(
|
|
375
|
-
`Failed to create connection topic: ${error}`
|
|
268
|
+
const response = await this.getMessages(topicInfo.outboundTopic);
|
|
269
|
+
return response.messages.filter(
|
|
270
|
+
(msg) => msg.p === "hcs-10" && (msg.op === "connection_request" || msg.op === "connection_created" || msg.op === "message")
|
|
376
271
|
);
|
|
272
|
+
} catch (error) {
|
|
273
|
+
this.logger.error("Failed to retrieve outbound messages:", error);
|
|
274
|
+
return [];
|
|
377
275
|
}
|
|
378
|
-
const operatorId = `${inboundTopicId}@${accountId}`;
|
|
379
|
-
const confirmedConnectionSequenceNumber = await this.confirmConnection(
|
|
380
|
-
inboundTopicId,
|
|
381
|
-
connectionTopicId,
|
|
382
|
-
requestingAccountId,
|
|
383
|
-
connectionRequestId,
|
|
384
|
-
"Connection accepted. Looking forward to collaborating!"
|
|
385
|
-
);
|
|
386
|
-
return {
|
|
387
|
-
connectionTopicId,
|
|
388
|
-
confirmedConnectionSequenceNumber,
|
|
389
|
-
operatorId
|
|
390
|
-
};
|
|
391
276
|
}
|
|
392
|
-
async
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
p: "hcs-10",
|
|
397
|
-
op: "connection_created",
|
|
398
|
-
connection_topic_id: connectionTopicId,
|
|
399
|
-
connected_account_id: connectedAccountId,
|
|
400
|
-
operator_id: operatorId,
|
|
401
|
-
connection_id: connectionId,
|
|
402
|
-
m: memo
|
|
403
|
-
};
|
|
404
|
-
const submissionCheck = await this.canSubmitToTopic(
|
|
405
|
-
inboundTopicId,
|
|
406
|
-
this.client.operatorAccountId?.toString() || ""
|
|
407
|
-
);
|
|
408
|
-
const result = await this.submitPayload(
|
|
409
|
-
inboundTopicId,
|
|
410
|
-
payload,
|
|
411
|
-
submitKey,
|
|
412
|
-
submissionCheck.requiresFee
|
|
413
|
-
);
|
|
414
|
-
const sequenceNumber = result.topicSequenceNumber?.toNumber();
|
|
415
|
-
if (!sequenceNumber) {
|
|
416
|
-
throw new ConnectionConfirmationError(
|
|
417
|
-
"Failed to confirm connection: sequence number is null"
|
|
277
|
+
async hasConnectionCreated(agentAccountId, connectionId) {
|
|
278
|
+
try {
|
|
279
|
+
const outBoundTopic = await this.retrieveOutboundConnectTopic(
|
|
280
|
+
agentAccountId
|
|
418
281
|
);
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
}
|
|
422
|
-
async sendMessage(connectionTopicId, data, memo, submitKey) {
|
|
423
|
-
const submissionCheck = await this.canSubmitToTopic(
|
|
424
|
-
connectionTopicId,
|
|
425
|
-
this.client.operatorAccountId?.toString() || ""
|
|
426
|
-
);
|
|
427
|
-
const operatorId = await this.getOperatorId();
|
|
428
|
-
const payload = {
|
|
429
|
-
p: "hcs-10",
|
|
430
|
-
op: "message",
|
|
431
|
-
operator_id: operatorId,
|
|
432
|
-
data,
|
|
433
|
-
m: memo
|
|
434
|
-
};
|
|
435
|
-
const payloadString = JSON.stringify(payload);
|
|
436
|
-
const isLargePayload = Buffer.from(payloadString).length > 1e3;
|
|
437
|
-
if (isLargePayload) {
|
|
438
|
-
this.logger.info(
|
|
439
|
-
"Message payload exceeds 1000 bytes, storing via inscription"
|
|
282
|
+
const messages = await this.retrieveOutboundMessages(
|
|
283
|
+
outBoundTopic.outboundTopic
|
|
440
284
|
);
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
);
|
|
448
|
-
if (inscriptionResult?.topic_id) {
|
|
449
|
-
payload.data = `hcs://1/${inscriptionResult.topic_id}`;
|
|
450
|
-
this.logger.info(
|
|
451
|
-
`Large message inscribed with topic ID: ${inscriptionResult.topic_id}`
|
|
452
|
-
);
|
|
453
|
-
} else {
|
|
454
|
-
throw new Error("Failed to inscribe large message content");
|
|
455
|
-
}
|
|
456
|
-
} catch (error) {
|
|
457
|
-
this.logger.error("Error inscribing large message:", error);
|
|
458
|
-
throw new Error(
|
|
459
|
-
`Failed to handle large message: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
460
|
-
);
|
|
461
|
-
}
|
|
285
|
+
return messages.some(
|
|
286
|
+
(msg) => msg.op === "connection_created" && msg.connection_id === connectionId
|
|
287
|
+
);
|
|
288
|
+
} catch (error) {
|
|
289
|
+
this.logger.error("Failed to check connection created:", error);
|
|
290
|
+
return false;
|
|
462
291
|
}
|
|
463
|
-
this.logger.info("Submitting message to connection topic", payload);
|
|
464
|
-
return await this.submitPayload(
|
|
465
|
-
connectionTopicId,
|
|
466
|
-
payload,
|
|
467
|
-
submitKey,
|
|
468
|
-
submissionCheck.requiresFee
|
|
469
|
-
);
|
|
470
292
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
transaction.setAutoRenewAccountId(this.client.operatorAccountId);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
293
|
+
/**
|
|
294
|
+
* Gets message content, resolving any HRL references if needed
|
|
295
|
+
* @param data The message data which might be an HRL reference
|
|
296
|
+
* @returns The resolved content
|
|
297
|
+
*/
|
|
298
|
+
async getMessageContent(data) {
|
|
299
|
+
const hrlPattern = /^hcs:\/\/(\d+)\/([0-9.]+)$/;
|
|
300
|
+
const match = data.match(hrlPattern);
|
|
301
|
+
if (!match) {
|
|
302
|
+
return data;
|
|
484
303
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
304
|
+
const [_, standard, topicId] = match;
|
|
305
|
+
this.logger.info(
|
|
306
|
+
`Resolving HRL reference: standard=${standard}, topicId=${topicId}`
|
|
307
|
+
);
|
|
308
|
+
try {
|
|
309
|
+
const cdnUrl = `https://kiloscribe.com/api/inscription-cdn/${topicId}?network=${this.network}`;
|
|
310
|
+
const response = await axios.get(cdnUrl);
|
|
311
|
+
if (!response.data) {
|
|
312
|
+
throw new Error(`Failed to fetch content from topic: ${topicId}`);
|
|
490
313
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
this.logger.debug("Executing topic creation transaction");
|
|
496
|
-
const txResponse = await transaction.execute(this.client);
|
|
497
|
-
const receipt = await txResponse.getReceipt(this.client);
|
|
498
|
-
if (!receipt.topicId) {
|
|
499
|
-
this.logger.error("Failed to create topic: topicId is null");
|
|
500
|
-
throw new Error("Failed to create topic: topicId is null");
|
|
501
|
-
}
|
|
502
|
-
const topicId = receipt.topicId.toString();
|
|
503
|
-
return topicId;
|
|
504
|
-
}
|
|
505
|
-
async submitPayload(topicId, payload, submitKey, requiresFee = false) {
|
|
506
|
-
const message = typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
507
|
-
const payloadSizeInBytes = Buffer.byteLength(message, "utf8");
|
|
508
|
-
if (payloadSizeInBytes > 1e3) {
|
|
509
|
-
throw new PayloadSizeError(
|
|
510
|
-
"Payload size exceeds 1000 bytes limit",
|
|
511
|
-
payloadSizeInBytes
|
|
314
|
+
return response.data.content || response.data.text || JSON.stringify(response.data);
|
|
315
|
+
} catch (error) {
|
|
316
|
+
this.logger.error(
|
|
317
|
+
`Error resolving HRL reference: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
512
318
|
);
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
if (requiresFee) {
|
|
516
|
-
this.logger.info(
|
|
517
|
-
"Topic requires fee payment, setting max transaction fee"
|
|
319
|
+
throw new Error(
|
|
320
|
+
`Failed to resolve HRL reference: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
518
321
|
);
|
|
519
|
-
transaction.setMaxTransactionFee(new Hbar(this.feeAmount));
|
|
520
|
-
transaction.setTransactionMemo("HIP-991 Fee Payment");
|
|
521
|
-
}
|
|
522
|
-
let transactionResponse;
|
|
523
|
-
if (submitKey) {
|
|
524
|
-
const frozenTransaction = transaction.freezeWith(this.client);
|
|
525
|
-
const signedTransaction = await frozenTransaction.sign(submitKey);
|
|
526
|
-
transactionResponse = await signedTransaction.execute(this.client);
|
|
527
|
-
} else {
|
|
528
|
-
transactionResponse = await transaction.execute(this.client);
|
|
529
322
|
}
|
|
530
|
-
const receipt = await transactionResponse.getReceipt(this.client);
|
|
531
|
-
if (!receipt) {
|
|
532
|
-
this.logger.error("Failed to submit message: receipt is null");
|
|
533
|
-
throw new Error("Failed to submit message: receipt is null");
|
|
534
|
-
}
|
|
535
|
-
this.logger.info("Message submitted successfully");
|
|
536
|
-
return receipt;
|
|
537
323
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
324
|
+
/**
|
|
325
|
+
* Records an outbound connection confirmation
|
|
326
|
+
* @param outboundTopicId The ID of the outbound topic
|
|
327
|
+
* @param connectionRequestId The ID of the connection request
|
|
328
|
+
* @param confirmedRequestId The ID of the confirmed request
|
|
329
|
+
* @param connectionTopicId The ID of the connection topic
|
|
330
|
+
* @param operatorId The operator ID of the message sender
|
|
331
|
+
* @param memo An optional memo for the message
|
|
332
|
+
*/
|
|
333
|
+
async recordOutboundConnectionConfirmation({
|
|
334
|
+
outboundTopicId,
|
|
335
|
+
connectionRequestId,
|
|
336
|
+
confirmedRequestId,
|
|
337
|
+
connectionTopicId,
|
|
338
|
+
operatorId,
|
|
339
|
+
memo
|
|
340
|
+
}) {
|
|
341
|
+
const payload = {
|
|
553
342
|
p: "hcs-10",
|
|
554
|
-
op: "
|
|
343
|
+
op: "connection_created",
|
|
344
|
+
connection_topic_id: connectionTopicId,
|
|
345
|
+
outbound_topic_id: outboundTopicId,
|
|
346
|
+
confirmed_request_id: confirmedRequestId,
|
|
347
|
+
connection_request_id: connectionRequestId,
|
|
555
348
|
operator_id: operatorId,
|
|
556
349
|
m: memo
|
|
557
350
|
};
|
|
558
|
-
|
|
559
|
-
const response = await this.submitPayload(
|
|
560
|
-
inboundTopicId,
|
|
561
|
-
connectionRequestMessage,
|
|
562
|
-
void 0,
|
|
563
|
-
requiresFee
|
|
564
|
-
);
|
|
565
|
-
this.logger.info(
|
|
566
|
-
`Submitted connection request to topic ID: ${inboundTopicId}`
|
|
567
|
-
);
|
|
568
|
-
const outboundTopic = await this.retrieveOutboundConnectTopic(accountId);
|
|
569
|
-
const responseSequenceNumber = response.topicSequenceNumber?.toNumber();
|
|
570
|
-
if (!responseSequenceNumber) {
|
|
571
|
-
throw new Error("Failed to get response sequence number");
|
|
572
|
-
}
|
|
573
|
-
await this.submitPayload(outboundTopic.outboundTopic, {
|
|
574
|
-
...connectionRequestMessage,
|
|
575
|
-
outbound_topic_id: outboundTopic.outboundTopic,
|
|
576
|
-
connection_request_id: responseSequenceNumber
|
|
577
|
-
});
|
|
578
|
-
return response;
|
|
351
|
+
return await this.submitPayload(outboundTopicId, payload);
|
|
579
352
|
}
|
|
580
|
-
async
|
|
581
|
-
this.
|
|
582
|
-
|
|
583
|
-
this.logger.error("Operator account ID is not set");
|
|
584
|
-
throw new Error("Operator account ID is not set");
|
|
585
|
-
}
|
|
586
|
-
if (!this.operatorPrivateKey) {
|
|
587
|
-
this.logger.error("Operator private key is not set");
|
|
588
|
-
throw new Error("Operator private key is not set");
|
|
353
|
+
async getOperatorId(disableCache) {
|
|
354
|
+
if (this.operatorId && !disableCache) {
|
|
355
|
+
return this.operatorId;
|
|
589
356
|
}
|
|
590
|
-
const
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
accountId: this.client.operatorAccountId.toString(),
|
|
594
|
-
privateKey: this.operatorPrivateKey.toString(),
|
|
595
|
-
network: this.network
|
|
596
|
-
});
|
|
597
|
-
const result = await sdk.inscribeAndExecute(
|
|
598
|
-
{
|
|
599
|
-
file: {
|
|
600
|
-
type: "base64",
|
|
601
|
-
base64: buffer.toString("base64"),
|
|
602
|
-
fileName,
|
|
603
|
-
mimeType
|
|
604
|
-
},
|
|
605
|
-
holderId: this.client.operatorAccountId.toString(),
|
|
606
|
-
mode: "file",
|
|
607
|
-
network: this.network
|
|
608
|
-
},
|
|
609
|
-
{
|
|
610
|
-
accountId: this.client.operatorAccountId.toString(),
|
|
611
|
-
privateKey: this.operatorPrivateKey.toString(),
|
|
612
|
-
network: this.network
|
|
613
|
-
}
|
|
614
|
-
);
|
|
615
|
-
if (!result.transactionId || !result.jobId) {
|
|
616
|
-
this.logger.error("Failed to inscribe, no transaction ID or job ID.");
|
|
617
|
-
throw new Error("Failed to inscribe, no transaction ID or job ID.");
|
|
357
|
+
const accountResponse = this.getAccountAndSigner();
|
|
358
|
+
if (!accountResponse.accountId) {
|
|
359
|
+
throw new Error("Operator ID not found");
|
|
618
360
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
);
|
|
361
|
+
const profile = await this.retrieveProfile(accountResponse.accountId);
|
|
362
|
+
if (!profile.success) {
|
|
363
|
+
throw new Error("Failed to retrieve profile");
|
|
623
364
|
}
|
|
624
|
-
const
|
|
625
|
-
|
|
365
|
+
const operatorId = `${profile.topicInfo?.inboundTopic}@${accountResponse.accountId}`;
|
|
366
|
+
this.operatorId = operatorId;
|
|
367
|
+
return operatorId;
|
|
626
368
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
* @param inboundTopicId Inbound topic ID
|
|
630
|
-
* @param connectionRequestId Connection request ID
|
|
631
|
-
* @param maxAttempts Maximum number of attempts
|
|
632
|
-
* @param delayMs Delay between attempts in milliseconds
|
|
633
|
-
* @returns Connection confirmation details
|
|
634
|
-
*/
|
|
635
|
-
async waitForConnectionConfirmation(inboundTopicId, connectionRequestId, maxAttempts = 60, delayMs = 2e3) {
|
|
636
|
-
this.logger.info(
|
|
637
|
-
`Waiting for connection confirmation on inbound topic ${inboundTopicId} for request ID ${connectionRequestId}`
|
|
638
|
-
);
|
|
639
|
-
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
640
|
-
this.logger.info(
|
|
641
|
-
`Attempt ${attempt + 1}/${maxAttempts} to find connection confirmation`
|
|
642
|
-
);
|
|
643
|
-
const messages = await this.mirrorNode.getTopicMessages(inboundTopicId);
|
|
644
|
-
const connectionCreatedMessages = messages.filter(
|
|
645
|
-
(m) => m.op === "connection_created"
|
|
646
|
-
);
|
|
647
|
-
this.logger.info(
|
|
648
|
-
`Found ${connectionCreatedMessages.length} connection_created messages`
|
|
649
|
-
);
|
|
650
|
-
if (connectionCreatedMessages.length > 0) {
|
|
651
|
-
for (const message of connectionCreatedMessages) {
|
|
652
|
-
if (Number(message.connection_id) === Number(connectionRequestId)) {
|
|
653
|
-
this.logger.info("Connection confirmation found");
|
|
654
|
-
return {
|
|
655
|
-
connectionTopicId: message.connection_topic_id,
|
|
656
|
-
sequence_number: Number(message.sequence_number),
|
|
657
|
-
confirmedBy: message.operator_id,
|
|
658
|
-
memo: message.m
|
|
659
|
-
};
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
if (attempt < maxAttempts - 1) {
|
|
664
|
-
this.logger.info(
|
|
665
|
-
`No matching confirmation found, waiting ${delayMs}ms before retrying...`
|
|
666
|
-
);
|
|
667
|
-
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
throw new Error(
|
|
671
|
-
`Connection confirmation not found after ${maxAttempts} attempts for request ID ${connectionRequestId}`
|
|
672
|
-
);
|
|
673
|
-
}
|
|
674
|
-
getAccountAndSigner() {
|
|
675
|
-
return {
|
|
676
|
-
accountId: this.client.operatorAccountId.toString(),
|
|
677
|
-
signer: this.operatorPrivateKey
|
|
678
|
-
};
|
|
369
|
+
clearCache() {
|
|
370
|
+
HCS10Cache.getInstance().clear();
|
|
679
371
|
}
|
|
680
372
|
/**
|
|
681
|
-
*
|
|
682
|
-
*
|
|
683
|
-
*
|
|
684
|
-
*
|
|
685
|
-
*
|
|
686
|
-
* 3. Creates an agent on the client.
|
|
687
|
-
* 4. Registers the agent with the Hashgraph Online Guarded Registry.
|
|
688
|
-
*
|
|
689
|
-
* @param builder The agent builder object
|
|
690
|
-
* @param options Optional configuration including progress callback and state management
|
|
691
|
-
* @returns Agent registration result
|
|
373
|
+
* Generates a standard HCS-10 memo string.
|
|
374
|
+
* @param type The type of topic memo ('inbound', 'outbound', 'connection').
|
|
375
|
+
* @param options Configuration options for the memo.
|
|
376
|
+
* @returns The formatted memo string.
|
|
377
|
+
* @protected
|
|
692
378
|
*/
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
if (progressCallback) {
|
|
700
|
-
progressCallback({
|
|
701
|
-
stage: "preparing",
|
|
702
|
-
message: "Preparing agent registration",
|
|
703
|
-
progressPercent: 10,
|
|
704
|
-
details: { state }
|
|
705
|
-
});
|
|
706
|
-
}
|
|
707
|
-
const account = config.existingAccount || await this.createAccount();
|
|
708
|
-
if (progressCallback) {
|
|
709
|
-
progressCallback({
|
|
710
|
-
stage: "preparing",
|
|
711
|
-
message: "Created account or using existing account",
|
|
712
|
-
progressPercent: 20,
|
|
713
|
-
details: { state, account }
|
|
714
|
-
});
|
|
715
|
-
}
|
|
716
|
-
const agentClient = new HCS10Client({
|
|
717
|
-
network: config.network,
|
|
718
|
-
operatorId: account.accountId,
|
|
719
|
-
operatorPrivateKey: account.privateKey,
|
|
720
|
-
operatorPublicKey: PrivateKey.fromString(
|
|
721
|
-
account.privateKey
|
|
722
|
-
).publicKey.toString(),
|
|
723
|
-
logLevel: "info",
|
|
724
|
-
guardedRegistryBaseUrl: baseUrl
|
|
725
|
-
});
|
|
726
|
-
if (progressCallback) {
|
|
727
|
-
progressCallback({
|
|
728
|
-
stage: "preparing",
|
|
729
|
-
message: "Initialized agent client",
|
|
730
|
-
progressPercent: 30,
|
|
731
|
-
details: { state }
|
|
732
|
-
});
|
|
733
|
-
}
|
|
734
|
-
const { outboundTopicId, inboundTopicId, pfpTopicId, profileTopicId } = await agentClient.createAgent(builder);
|
|
735
|
-
if (progressCallback) {
|
|
736
|
-
progressCallback({
|
|
737
|
-
stage: "submitting",
|
|
738
|
-
message: "Created agent with topics and profile",
|
|
739
|
-
progressPercent: 60,
|
|
740
|
-
details: {
|
|
741
|
-
state,
|
|
742
|
-
outboundTopicId,
|
|
743
|
-
inboundTopicId,
|
|
744
|
-
pfpTopicId,
|
|
745
|
-
profileTopicId
|
|
746
|
-
}
|
|
747
|
-
});
|
|
748
|
-
}
|
|
749
|
-
const operatorId = `${inboundTopicId}@${account.accountId}`;
|
|
750
|
-
const registrationResult = await agentClient.registerAgentWithGuardedRegistry(
|
|
751
|
-
account.accountId,
|
|
752
|
-
config.network,
|
|
753
|
-
{
|
|
754
|
-
progressCallback: (data) => {
|
|
755
|
-
const adjustedPercent = 60 + (data.progressPercent || 0) * 0.4;
|
|
756
|
-
if (progressCallback) {
|
|
757
|
-
progressCallback({
|
|
758
|
-
stage: data.stage,
|
|
759
|
-
message: data.message,
|
|
760
|
-
progressPercent: adjustedPercent,
|
|
761
|
-
details: {
|
|
762
|
-
...data.details,
|
|
763
|
-
outboundTopicId,
|
|
764
|
-
inboundTopicId,
|
|
765
|
-
pfpTopicId,
|
|
766
|
-
profileTopicId,
|
|
767
|
-
operatorId,
|
|
768
|
-
state: data.details?.state || state
|
|
769
|
-
}
|
|
770
|
-
});
|
|
771
|
-
}
|
|
772
|
-
},
|
|
773
|
-
existingState: state
|
|
379
|
+
_generateHcs10Memo(type, options) {
|
|
380
|
+
const ttl = options.ttl ?? 60;
|
|
381
|
+
switch (type) {
|
|
382
|
+
case "inbound":
|
|
383
|
+
if (!options.accountId) {
|
|
384
|
+
throw new Error("accountId is required for inbound memo");
|
|
774
385
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
return
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
progressPercent: 100,
|
|
784
|
-
details: {
|
|
785
|
-
outboundTopicId,
|
|
786
|
-
inboundTopicId,
|
|
787
|
-
pfpTopicId,
|
|
788
|
-
profileTopicId,
|
|
789
|
-
operatorId,
|
|
790
|
-
state: registrationResult.state
|
|
791
|
-
}
|
|
792
|
-
});
|
|
793
|
-
}
|
|
794
|
-
return {
|
|
795
|
-
...registrationResult,
|
|
796
|
-
metadata: {
|
|
797
|
-
accountId: account.accountId,
|
|
798
|
-
privateKey: account.privateKey,
|
|
799
|
-
operatorId,
|
|
800
|
-
inboundTopicId,
|
|
801
|
-
outboundTopicId,
|
|
802
|
-
profileTopicId,
|
|
803
|
-
pfpTopicId
|
|
386
|
+
return `hcs-10:0:${ttl}:0:${options.accountId}`;
|
|
387
|
+
case "outbound":
|
|
388
|
+
return `hcs-10:0:${ttl}:1`;
|
|
389
|
+
case "connection":
|
|
390
|
+
if (!options.inboundTopicId || options.connectionId === void 0) {
|
|
391
|
+
throw new Error(
|
|
392
|
+
"inboundTopicId and connectionId are required for connection memo"
|
|
393
|
+
);
|
|
804
394
|
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
`Failed to create and register agent: ${error.message}`
|
|
809
|
-
);
|
|
810
|
-
return {
|
|
811
|
-
error: error.message,
|
|
812
|
-
success: false
|
|
813
|
-
};
|
|
395
|
+
return `hcs-10:1:${ttl}:2:${options.inboundTopicId}:${options.connectionId}`;
|
|
396
|
+
default:
|
|
397
|
+
throw new Error(`Invalid HCS-10 memo type: ${type}`);
|
|
814
398
|
}
|
|
815
399
|
}
|
|
816
|
-
|
|
817
|
-
* Registers an agent with the guarded registry
|
|
818
|
-
* @param accountId Account ID to register
|
|
819
|
-
* @param inboundTopicId Inbound topic ID for the agent
|
|
820
|
-
* @param network Network type ('mainnet' or 'testnet')
|
|
821
|
-
* @param options Optional configuration including progress callback and confirmation settings
|
|
822
|
-
* @returns Registration result
|
|
823
|
-
*/
|
|
824
|
-
async registerAgentWithGuardedRegistry(accountId, network = this.network, options) {
|
|
400
|
+
async checkRegistrationStatus(transactionId, network, baseUrl) {
|
|
825
401
|
try {
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
stage: "preparing",
|
|
838
|
-
message: "Preparing agent registration",
|
|
839
|
-
progressPercent: 10,
|
|
840
|
-
details: {
|
|
841
|
-
state
|
|
842
|
-
}
|
|
843
|
-
});
|
|
844
|
-
}
|
|
845
|
-
const registrationResult = await this.executeRegistration(
|
|
846
|
-
accountId,
|
|
847
|
-
network,
|
|
848
|
-
this.guardedRegistryBaseUrl,
|
|
849
|
-
this.logger
|
|
850
|
-
);
|
|
851
|
-
if (!registrationResult.success) {
|
|
852
|
-
return {
|
|
853
|
-
...registrationResult,
|
|
854
|
-
state
|
|
855
|
-
};
|
|
856
|
-
}
|
|
857
|
-
if (progressCallback) {
|
|
858
|
-
progressCallback({
|
|
859
|
-
stage: "submitting",
|
|
860
|
-
message: "Submitting registration to registry",
|
|
861
|
-
progressPercent: 30,
|
|
862
|
-
details: {
|
|
863
|
-
transactionId: registrationResult.transactionId,
|
|
864
|
-
state
|
|
865
|
-
}
|
|
866
|
-
});
|
|
867
|
-
}
|
|
868
|
-
if (registrationResult.transaction) {
|
|
869
|
-
const transaction = Transaction.fromBytes(
|
|
870
|
-
Buffer.from(registrationResult.transaction, "base64")
|
|
871
|
-
);
|
|
872
|
-
this.logger.info(`Processing registration transaction`);
|
|
873
|
-
await transaction.execute(this.client);
|
|
874
|
-
this.logger.info(`Successfully processed registration transaction`);
|
|
875
|
-
}
|
|
876
|
-
if (progressCallback) {
|
|
877
|
-
progressCallback({
|
|
878
|
-
stage: "confirming",
|
|
879
|
-
message: "Confirming registration transaction",
|
|
880
|
-
progressPercent: 60,
|
|
881
|
-
details: {
|
|
882
|
-
accountId,
|
|
883
|
-
transactionId: registrationResult.transactionId,
|
|
884
|
-
state
|
|
885
|
-
}
|
|
886
|
-
});
|
|
887
|
-
}
|
|
888
|
-
const confirmed = await this.waitForRegistrationConfirmation(
|
|
889
|
-
registrationResult.transactionId,
|
|
890
|
-
network,
|
|
891
|
-
this.guardedRegistryBaseUrl,
|
|
892
|
-
maxAttempts,
|
|
893
|
-
delayMs,
|
|
894
|
-
this.logger
|
|
895
|
-
);
|
|
896
|
-
state.currentStage = "complete";
|
|
897
|
-
state.completedPercentage = 100;
|
|
898
|
-
if (!state.createdResources) {
|
|
899
|
-
state.createdResources = [];
|
|
900
|
-
}
|
|
901
|
-
if (registrationResult.transactionId) {
|
|
902
|
-
state.createdResources.push(
|
|
903
|
-
`registration:${registrationResult.transactionId}`
|
|
402
|
+
const response = await fetch(`${baseUrl}/api/request-confirm`, {
|
|
403
|
+
method: "POST",
|
|
404
|
+
headers: {
|
|
405
|
+
"Content-Type": "application/json",
|
|
406
|
+
"X-Network": network
|
|
407
|
+
},
|
|
408
|
+
body: JSON.stringify({ transaction_id: transactionId })
|
|
409
|
+
});
|
|
410
|
+
if (!response.ok) {
|
|
411
|
+
throw new Error(
|
|
412
|
+
`Failed to confirm registration: ${response.statusText}`
|
|
904
413
|
);
|
|
905
414
|
}
|
|
906
|
-
|
|
907
|
-
progressCallback({
|
|
908
|
-
stage: "completed",
|
|
909
|
-
message: "Agent registration complete",
|
|
910
|
-
progressPercent: 100,
|
|
911
|
-
details: {
|
|
912
|
-
confirmed,
|
|
913
|
-
transactionId: registrationResult.transactionId,
|
|
914
|
-
state
|
|
915
|
-
}
|
|
916
|
-
});
|
|
917
|
-
}
|
|
918
|
-
return {
|
|
919
|
-
...registrationResult,
|
|
920
|
-
confirmed,
|
|
921
|
-
state
|
|
922
|
-
};
|
|
415
|
+
return await response.json();
|
|
923
416
|
} catch (error) {
|
|
924
|
-
this.logger.error(`
|
|
925
|
-
|
|
926
|
-
error: error.message,
|
|
927
|
-
success: false
|
|
928
|
-
};
|
|
417
|
+
this.logger.error(`Error checking registration status: ${error}`);
|
|
418
|
+
throw error;
|
|
929
419
|
}
|
|
930
420
|
}
|
|
931
421
|
/**
|
|
932
|
-
*
|
|
933
|
-
* @param
|
|
934
|
-
* @
|
|
935
|
-
* @param inboundTopicId - The topic ID of the inbound topic
|
|
936
|
-
* @param memo - The memo of the agent
|
|
937
|
-
* @param submitKey - The submit key of the agent
|
|
422
|
+
* Validates if an operator_id follows the correct format (agentTopicId@accountId)
|
|
423
|
+
* @param operatorId The operator ID to validate
|
|
424
|
+
* @returns True if the format is valid, false otherwise
|
|
938
425
|
*/
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
426
|
+
isValidOperatorId(operatorId) {
|
|
427
|
+
if (!operatorId) {
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
const parts = operatorId.split("@");
|
|
431
|
+
if (parts.length !== 2) {
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
const agentTopicId = parts[0];
|
|
435
|
+
const accountId = parts[1];
|
|
436
|
+
if (!agentTopicId) {
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
if (!accountId) {
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
const hederaIdPattern = /^[0-9]+\.[0-9]+\.[0-9]+$/;
|
|
443
|
+
if (!hederaIdPattern.test(accountId)) {
|
|
444
|
+
return false;
|
|
445
|
+
}
|
|
446
|
+
if (!hederaIdPattern.test(agentTopicId)) {
|
|
447
|
+
return false;
|
|
448
|
+
}
|
|
449
|
+
return true;
|
|
949
450
|
}
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
const hasFeeScheduleKey = topicInfo.fee_schedule_key && topicInfo.fee_schedule_key.key;
|
|
961
|
-
if (hasFeeScheduleKey && topicInfo.custom_fees) {
|
|
962
|
-
const customFees = topicInfo.custom_fees;
|
|
963
|
-
if (customFees && customFees.fixed_fees && customFees.fixed_fees.length > 0) {
|
|
964
|
-
this.logger.info(
|
|
965
|
-
`Topic ${topicId} is fee-based with ${customFees.fixed_fees.length} custom fees`
|
|
966
|
-
);
|
|
967
|
-
return InboundTopicType.FEE_BASED;
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
return InboundTopicType.CONTROLLED;
|
|
971
|
-
} catch (error) {
|
|
972
|
-
this.logger.error(`Error determining topic type: ${error.message}`);
|
|
973
|
-
throw new Error(`Failed to determine topic type: ${error.message}`);
|
|
451
|
+
}
|
|
452
|
+
class HCS10Cache {
|
|
453
|
+
constructor() {
|
|
454
|
+
this.CACHE_TTL = 36e5;
|
|
455
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
456
|
+
this.cacheExpiry = /* @__PURE__ */ new Map();
|
|
457
|
+
}
|
|
458
|
+
static getInstance() {
|
|
459
|
+
if (!HCS10Cache.instance) {
|
|
460
|
+
HCS10Cache.instance = new HCS10Cache();
|
|
974
461
|
}
|
|
462
|
+
return HCS10Cache.instance;
|
|
463
|
+
}
|
|
464
|
+
set(key, value) {
|
|
465
|
+
this.cache.set(key, value);
|
|
466
|
+
this.cacheExpiry.set(key, Date.now() + this.CACHE_TTL);
|
|
975
467
|
}
|
|
976
|
-
|
|
977
|
-
|
|
468
|
+
get(key) {
|
|
469
|
+
const expiry = this.cacheExpiry.get(key);
|
|
470
|
+
if (expiry && expiry > Date.now()) {
|
|
471
|
+
return this.cache.get(key);
|
|
472
|
+
}
|
|
473
|
+
if (expiry) {
|
|
474
|
+
this.cache.delete(key);
|
|
475
|
+
this.cacheExpiry.delete(key);
|
|
476
|
+
}
|
|
477
|
+
return void 0;
|
|
978
478
|
}
|
|
979
|
-
|
|
980
|
-
|
|
479
|
+
clear() {
|
|
480
|
+
this.cache.clear();
|
|
481
|
+
this.cacheExpiry.clear();
|
|
981
482
|
}
|
|
982
483
|
}
|
|
983
484
|
export {
|
|
984
|
-
|
|
985
|
-
|
|
485
|
+
HCS10BaseClient,
|
|
486
|
+
HCS10Cache,
|
|
487
|
+
Hcs10MemoType
|
|
986
488
|
};
|
|
987
489
|
//# sourceMappingURL=standards-sdk.es5.js.map
|