@hashgraphonline/standards-sdk 0.0.64 → 0.0.66
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 +3 -792
- package/dist/es/standards-sdk.es100.js.map +1 -1
- package/dist/es/standards-sdk.es101.js +2282 -174
- package/dist/es/standards-sdk.es101.js.map +1 -1
- package/dist/es/standards-sdk.es102.js +14 -141
- package/dist/es/standards-sdk.es102.js.map +1 -1
- package/dist/es/standards-sdk.es103.js +5 -3
- package/dist/es/standards-sdk.es103.js.map +1 -1
- package/dist/es/standards-sdk.es104.js +39 -2
- package/dist/es/standards-sdk.es104.js.map +1 -1
- package/dist/es/standards-sdk.es105.js +40 -2
- package/dist/es/standards-sdk.es105.js.map +1 -1
- package/dist/es/standards-sdk.es106.js +37 -34
- package/dist/es/standards-sdk.es106.js.map +1 -1
- package/dist/es/standards-sdk.es107.js +74 -29
- package/dist/es/standards-sdk.es107.js.map +1 -1
- package/dist/es/standards-sdk.es108.js +3 -9
- package/dist/es/standards-sdk.es108.js.map +1 -1
- package/dist/es/standards-sdk.es109.js +2 -34
- package/dist/es/standards-sdk.es109.js.map +1 -1
- 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 +2 -21
- package/dist/es/standards-sdk.es110.js.map +1 -1
- package/dist/es/standards-sdk.es111.js +33 -26
- package/dist/es/standards-sdk.es111.js.map +1 -1
- package/dist/es/standards-sdk.es112.js +32 -25
- package/dist/es/standards-sdk.es112.js.map +1 -1
- package/dist/es/standards-sdk.es113.js +9 -38
- package/dist/es/standards-sdk.es113.js.map +1 -1
- package/dist/es/standards-sdk.es114.js +37 -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 +3 -0
- package/dist/es/standards-sdk.es14.js.map +1 -1
- package/dist/es/standards-sdk.es17.js +2 -2
- 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 +1767 -3
- package/dist/es/standards-sdk.es20.js.map +1 -1
- package/dist/es/standards-sdk.es21.js +36 -4167
- package/dist/es/standards-sdk.es21.js.map +1 -1
- package/dist/es/standards-sdk.es22.js +21 -6600
- package/dist/es/standards-sdk.es22.js.map +1 -1
- package/dist/es/standards-sdk.es23.js +6627 -36
- package/dist/es/standards-sdk.es23.js.map +1 -1
- package/dist/es/standards-sdk.es24.js +3 -48
- package/dist/es/standards-sdk.es24.js.map +1 -1
- package/dist/es/standards-sdk.es26.js +10 -10
- package/dist/es/standards-sdk.es27.js +2 -2
- package/dist/es/standards-sdk.es28.js +4147 -81
- 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 +2 -2282
- package/dist/es/standards-sdk.es32.js.map +1 -1
- package/dist/es/standards-sdk.es33.js +68 -148
- package/dist/es/standards-sdk.es33.js.map +1 -1
- package/dist/es/standards-sdk.es34.js +23 -3
- package/dist/es/standards-sdk.es34.js.map +1 -1
- package/dist/es/standards-sdk.es35.js +131 -402
- package/dist/es/standards-sdk.es35.js.map +1 -1
- package/dist/es/standards-sdk.es36.js +91 -2
- package/dist/es/standards-sdk.es36.js.map +1 -1
- package/dist/es/standards-sdk.es37.js +190 -115
- package/dist/es/standards-sdk.es37.js.map +1 -1
- package/dist/es/standards-sdk.es38.js +437 -3
- package/dist/es/standards-sdk.es38.js.map +1 -1
- package/dist/es/standards-sdk.es39.js +19 -358
- package/dist/es/standards-sdk.es39.js.map +1 -1
- package/dist/es/standards-sdk.es40.js +138 -5
- package/dist/es/standards-sdk.es40.js.map +1 -1
- package/dist/es/standards-sdk.es41.js +13 -174
- package/dist/es/standards-sdk.es41.js.map +1 -1
- package/dist/es/standards-sdk.es42.js +23 -75
- package/dist/es/standards-sdk.es42.js.map +1 -1
- package/dist/es/standards-sdk.es43.js +26 -111
- package/dist/es/standards-sdk.es43.js.map +1 -1
- package/dist/es/standards-sdk.es44.js +16 -47
- package/dist/es/standards-sdk.es44.js.map +1 -1
- package/dist/es/standards-sdk.es45.js +43 -9
- package/dist/es/standards-sdk.es45.js.map +1 -1
- package/dist/es/standards-sdk.es46.js +13 -92
- package/dist/es/standards-sdk.es46.js.map +1 -1
- package/dist/es/standards-sdk.es47.js +60 -3
- package/dist/es/standards-sdk.es47.js.map +1 -1
- package/dist/es/standards-sdk.es48.js +1289 -2
- package/dist/es/standards-sdk.es48.js.map +1 -1
- package/dist/es/standards-sdk.es49.js +27 -108
- 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 +5 -73
- package/dist/es/standards-sdk.es50.js.map +1 -1
- package/dist/es/standards-sdk.es51.js +158 -5
- package/dist/es/standards-sdk.es51.js.map +1 -1
- package/dist/es/standards-sdk.es52.js +792 -4
- package/dist/es/standards-sdk.es52.js.map +1 -1
- package/dist/es/standards-sdk.es53.js +162 -209
- package/dist/es/standards-sdk.es53.js.map +1 -1
- package/dist/es/standards-sdk.es54.js +137 -52
- package/dist/es/standards-sdk.es54.js.map +1 -1
- package/dist/es/standards-sdk.es55.js +4 -69
- package/dist/es/standards-sdk.es55.js.map +1 -1
- package/dist/es/standards-sdk.es56.js +357 -25
- package/dist/es/standards-sdk.es56.js.map +1 -1
- package/dist/es/standards-sdk.es57.js +5 -62
- package/dist/es/standards-sdk.es57.js.map +1 -1
- package/dist/es/standards-sdk.es58.js +173 -44
- package/dist/es/standards-sdk.es58.js.map +1 -1
- package/dist/es/standards-sdk.es59.js +80 -9
- package/dist/es/standards-sdk.es59.js.map +1 -1
- package/dist/es/standards-sdk.es60.js +106 -57
- package/dist/es/standards-sdk.es60.js.map +1 -1
- package/dist/es/standards-sdk.es61.js +52 -6
- package/dist/es/standards-sdk.es61.js.map +1 -1
- package/dist/es/standards-sdk.es62.js +9 -14
- package/dist/es/standards-sdk.es62.js.map +1 -1
- package/dist/es/standards-sdk.es63.js +97 -7
- package/dist/es/standards-sdk.es63.js.map +1 -1
- package/dist/es/standards-sdk.es64.js +4 -45
- package/dist/es/standards-sdk.es64.js.map +1 -1
- package/dist/es/standards-sdk.es65.js +2 -2
- package/dist/es/standards-sdk.es65.js.map +1 -1
- package/dist/es/standards-sdk.es66.js +105 -128
- package/dist/es/standards-sdk.es66.js.map +1 -1
- package/dist/es/standards-sdk.es67.js +70 -168
- package/dist/es/standards-sdk.es67.js.map +1 -1
- package/dist/es/standards-sdk.es68.js +6 -2
- package/dist/es/standards-sdk.es68.js.map +1 -1
- package/dist/es/standards-sdk.es69.js +5 -13
- 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 +221 -13
- package/dist/es/standards-sdk.es70.js.map +1 -1
- package/dist/es/standards-sdk.es71.js +56 -30
- package/dist/es/standards-sdk.es71.js.map +1 -1
- package/dist/es/standards-sdk.es72.js +69 -15
- package/dist/es/standards-sdk.es72.js.map +1 -1
- package/dist/es/standards-sdk.es73.js +20 -3
- package/dist/es/standards-sdk.es73.js.map +1 -1
- package/dist/es/standards-sdk.es74.js +26 -3
- package/dist/es/standards-sdk.es74.js.map +1 -1
- package/dist/es/standards-sdk.es75.js +24 -14
- package/dist/es/standards-sdk.es75.js.map +1 -1
- package/dist/es/standards-sdk.es76.js +37 -4
- package/dist/es/standards-sdk.es76.js.map +1 -1
- package/dist/es/standards-sdk.es77.js +3 -39
- package/dist/es/standards-sdk.es77.js.map +1 -1
- package/dist/es/standards-sdk.es78.js +158 -34
- package/dist/es/standards-sdk.es78.js.map +1 -1
- package/dist/es/standards-sdk.es79.js +30 -35
- 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 +57 -72
- package/dist/es/standards-sdk.es80.js.map +1 -1
- package/dist/es/standards-sdk.es81.js +46 -191
- package/dist/es/standards-sdk.es81.js.map +1 -1
- package/dist/es/standards-sdk.es82.js +8 -436
- package/dist/es/standards-sdk.es82.js.map +1 -1
- package/dist/es/standards-sdk.es83.js +60 -20
- package/dist/es/standards-sdk.es83.js.map +1 -1
- package/dist/es/standards-sdk.es84.js +6 -139
- package/dist/es/standards-sdk.es84.js.map +1 -1
- package/dist/es/standards-sdk.es85.js +14 -17
- package/dist/es/standards-sdk.es85.js.map +1 -1
- package/dist/es/standards-sdk.es86.js +7 -29
- package/dist/es/standards-sdk.es86.js.map +1 -1
- package/dist/es/standards-sdk.es87.js +44 -28
- package/dist/es/standards-sdk.es87.js.map +1 -1
- package/dist/es/standards-sdk.es88.js +2 -21
- package/dist/es/standards-sdk.es88.js.map +1 -1
- package/dist/es/standards-sdk.es89.js +135 -43
- package/dist/es/standards-sdk.es89.js.map +1 -1
- package/dist/es/standards-sdk.es9.js +1 -1
- package/dist/es/standards-sdk.es9.js.map +1 -1
- package/dist/es/standards-sdk.es90.js +168 -14
- package/dist/es/standards-sdk.es90.js.map +1 -1
- package/dist/es/standards-sdk.es91.js +95 -55
- package/dist/es/standards-sdk.es91.js.map +1 -1
- package/dist/es/standards-sdk.es92.js +2 -1289
- package/dist/es/standards-sdk.es92.js.map +1 -1
- package/dist/es/standards-sdk.es93.js +15 -147
- package/dist/es/standards-sdk.es93.js.map +1 -1
- package/dist/es/standards-sdk.es94.js +403 -85
- package/dist/es/standards-sdk.es94.js.map +1 -1
- package/dist/es/standards-sdk.es95.js +13 -84
- package/dist/es/standards-sdk.es95.js.map +1 -1
- package/dist/es/standards-sdk.es96.js +13 -32
- package/dist/es/standards-sdk.es96.js.map +1 -1
- package/dist/es/standards-sdk.es97.js +31 -5
- package/dist/es/standards-sdk.es97.js.map +1 -1
- package/dist/es/standards-sdk.es98.js +13 -157
- package/dist/es/standards-sdk.es98.js.map +1 -1
- package/dist/es/standards-sdk.es99.js +3 -22
- 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 +3 -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,489 +1,1145 @@
|
|
|
1
|
-
import Buffer from "./standards-sdk.
|
|
2
|
-
import {
|
|
1
|
+
import Buffer from "./standards-sdk.es20.js";
|
|
2
|
+
import { KeyList, TopicCreateTransaction, Transaction, TopicMessageSubmitTransaction, Hbar } from "@hashgraph/sdk";
|
|
3
3
|
import { Logger } from "./standards-sdk.es14.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import "./standards-sdk.
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return Hcs10MemoType2;
|
|
14
|
-
})(Hcs10MemoType || {});
|
|
15
|
-
class HCS10BaseClient extends Registration {
|
|
4
|
+
import { InscriptionSDK } from "./standards-sdk.es23.js";
|
|
5
|
+
import { HCS10BaseClient, Hcs10MemoType } from "./standards-sdk.es5.js";
|
|
6
|
+
import { m as mimeTypesExports } from "./standards-sdk.es24.js";
|
|
7
|
+
import { AgentBuilder } from "./standards-sdk.es10.js";
|
|
8
|
+
import { HCS11Client } from "./standards-sdk.es12.js";
|
|
9
|
+
import { ProgressReporter } from "./standards-sdk.es16.js";
|
|
10
|
+
import { inscribeWithSigner } from "./standards-sdk.es17.js";
|
|
11
|
+
const isBrowser = typeof window !== "undefined";
|
|
12
|
+
class BrowserHCSClient extends HCS10BaseClient {
|
|
16
13
|
constructor(config) {
|
|
17
|
-
super(
|
|
18
|
-
|
|
14
|
+
super({
|
|
15
|
+
network: config.network,
|
|
16
|
+
logLevel: config.logLevel,
|
|
17
|
+
prettyPrint: config.prettyPrint,
|
|
18
|
+
feeAmount: config.feeAmount
|
|
19
|
+
});
|
|
20
|
+
this.hcs11Client = null;
|
|
21
|
+
this.hwc = config.hwc;
|
|
22
|
+
if (!config.guardedRegistryBaseUrl) {
|
|
23
|
+
this.guardedRegistryBaseUrl = "https://moonscape.tech";
|
|
24
|
+
} else {
|
|
25
|
+
this.guardedRegistryBaseUrl = config.guardedRegistryBaseUrl;
|
|
26
|
+
}
|
|
27
|
+
let logLevel;
|
|
28
|
+
if (config.logLevel) {
|
|
29
|
+
logLevel = config.logLevel;
|
|
30
|
+
} else {
|
|
31
|
+
logLevel = "info";
|
|
32
|
+
}
|
|
19
33
|
this.logger = Logger.getInstance({
|
|
20
|
-
level:
|
|
21
|
-
module: "
|
|
34
|
+
level: logLevel,
|
|
35
|
+
module: "HCS-Browser",
|
|
22
36
|
prettyPrint: config.prettyPrint
|
|
23
37
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
38
|
+
if (isBrowser) {
|
|
39
|
+
try {
|
|
40
|
+
const { accountId, signer } = this.getAccountAndSigner();
|
|
41
|
+
this.hcs11Client = new HCS11Client({
|
|
42
|
+
network: config.network,
|
|
43
|
+
auth: {
|
|
44
|
+
operatorId: accountId,
|
|
45
|
+
signer
|
|
46
|
+
},
|
|
47
|
+
logLevel: config.logLevel
|
|
48
|
+
});
|
|
49
|
+
} catch (err) {
|
|
50
|
+
this.logger.warn(`Failed to initialize HCS11Client: ${err}`);
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
this.logger.error(
|
|
54
|
+
"BrowserHCSClient initialized in server environment - browser-specific features will not be available. Use HCS10Client instead."
|
|
55
|
+
);
|
|
56
|
+
}
|
|
29
57
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
async sendMessage(connectionTopicId, data, memo, submitKey, options) {
|
|
59
|
+
this.logger.info("Sending message");
|
|
60
|
+
const operatorId = await this.getOperatorId();
|
|
61
|
+
const payload = {
|
|
62
|
+
p: "hcs-10",
|
|
63
|
+
op: "message",
|
|
64
|
+
operator_id: operatorId,
|
|
65
|
+
data,
|
|
66
|
+
m: memo
|
|
67
|
+
};
|
|
68
|
+
const submissionCheck = await this.canSubmitToTopic(
|
|
69
|
+
connectionTopicId,
|
|
70
|
+
this.hwc.getAccountInfo().accountId
|
|
71
|
+
);
|
|
72
|
+
const payloadString = JSON.stringify(payload);
|
|
73
|
+
const isLargePayload = Buffer.from(payloadString).length > 1e3;
|
|
74
|
+
if (isLargePayload) {
|
|
75
|
+
this.logger.info(
|
|
76
|
+
"Message payload exceeds 1000 bytes, storing via inscription"
|
|
77
|
+
);
|
|
78
|
+
try {
|
|
79
|
+
const contentBuffer = Buffer.from(data);
|
|
80
|
+
const fileName = `message-${Date.now()}.json`;
|
|
81
|
+
const inscriptionResult = await this.inscribeFile(
|
|
82
|
+
contentBuffer,
|
|
83
|
+
fileName,
|
|
84
|
+
{
|
|
85
|
+
progressCallback: options?.progressCallback,
|
|
86
|
+
waitMaxAttempts: options?.waitMaxAttempts,
|
|
87
|
+
waitIntervalMs: options?.waitIntervalMs
|
|
60
88
|
}
|
|
89
|
+
);
|
|
90
|
+
if (inscriptionResult?.topic_id) {
|
|
91
|
+
payload.data = `hcs://1/${inscriptionResult.topic_id}`;
|
|
92
|
+
this.logger.info(
|
|
93
|
+
`Large message inscribed with topic ID: ${inscriptionResult.topic_id}`
|
|
94
|
+
);
|
|
95
|
+
} else {
|
|
96
|
+
throw new Error("Failed to inscribe large message content");
|
|
61
97
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
} catch (error) {
|
|
68
|
-
if (this.logger) {
|
|
69
|
-
this.logger.error(`Error fetching messages: ${error.message}`);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
this.logger.error("Error inscribing large message:", error);
|
|
100
|
+
throw new Error(
|
|
101
|
+
`Failed to handle large message: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
102
|
+
);
|
|
70
103
|
}
|
|
71
|
-
return { messages: [] };
|
|
72
104
|
}
|
|
105
|
+
return await this.submitPayload(
|
|
106
|
+
connectionTopicId,
|
|
107
|
+
payload,
|
|
108
|
+
submitKey,
|
|
109
|
+
submissionCheck.requiresFee
|
|
110
|
+
);
|
|
73
111
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
112
|
+
async submitConnectionRequest(inboundTopicId, memo) {
|
|
113
|
+
this.logger.info("Submitting connection request");
|
|
114
|
+
const accountResponse = this.getAccountAndSigner();
|
|
115
|
+
if (!accountResponse.accountId) {
|
|
116
|
+
throw new Error("Failed to retrieve user account ID");
|
|
117
|
+
}
|
|
118
|
+
const operatorId = await this.getOperatorId();
|
|
119
|
+
const accountId = accountResponse.accountId;
|
|
120
|
+
const connectionRequestMessage = {
|
|
121
|
+
p: "hcs-10",
|
|
122
|
+
op: "connection_request",
|
|
123
|
+
operator_id: operatorId,
|
|
124
|
+
m: memo
|
|
125
|
+
};
|
|
126
|
+
const response = await this.submitPayload(
|
|
127
|
+
inboundTopicId,
|
|
128
|
+
connectionRequestMessage
|
|
129
|
+
);
|
|
130
|
+
this.logger.info(
|
|
131
|
+
`Submitted connection request to topic ID: ${inboundTopicId}`
|
|
132
|
+
);
|
|
133
|
+
const outboundTopic = await this.retrieveOutboundConnectTopic(accountId);
|
|
134
|
+
if (!outboundTopic?.outboundTopic) {
|
|
135
|
+
this.logger.error(
|
|
136
|
+
`Failed to retrieve outbound topic for account ID: ${accountId}`
|
|
137
|
+
);
|
|
138
|
+
throw new Error(
|
|
139
|
+
`Failed to retrieve outbound topic for account ID: ${accountId}`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
this.logger.info(
|
|
143
|
+
`Retrieved outbound topic ID: ${outboundTopic.outboundTopic} for account ID: ${accountId}`
|
|
144
|
+
);
|
|
145
|
+
const responseSequenceNumber = response?.topicSequenceNumber?.toNumber();
|
|
146
|
+
if (!responseSequenceNumber) {
|
|
147
|
+
throw new Error("Failed to get response sequence number");
|
|
148
|
+
}
|
|
149
|
+
await this.submitPayload(outboundTopic.outboundTopic, {
|
|
150
|
+
...connectionRequestMessage,
|
|
151
|
+
outbound_topic_id: inboundTopicId,
|
|
152
|
+
connection_request_id: responseSequenceNumber
|
|
153
|
+
});
|
|
154
|
+
return response;
|
|
155
|
+
}
|
|
156
|
+
async getPublicKey(accountId) {
|
|
157
|
+
return await this.mirrorNode.getPublicKey(accountId);
|
|
158
|
+
}
|
|
159
|
+
async handleConnectionRequest(inboundTopicId, requestingAccountId, connectionId, connectionMemo = "Connection accepted. Looking forward to collaborating!", ttl = 60) {
|
|
160
|
+
this.logger.info("Handling connection request");
|
|
161
|
+
const userAccountId = this.hwc.getAccountInfo().accountId;
|
|
162
|
+
if (!userAccountId) {
|
|
163
|
+
throw new Error("Failed to retrieve user account ID");
|
|
164
|
+
}
|
|
165
|
+
const requesterKey = await this.mirrorNode.getPublicKey(
|
|
166
|
+
requestingAccountId
|
|
167
|
+
);
|
|
168
|
+
const accountKey = await this.mirrorNode.getPublicKey(userAccountId);
|
|
169
|
+
if (!accountKey) {
|
|
170
|
+
throw new Error("Failed to retrieve public key");
|
|
171
|
+
}
|
|
172
|
+
const thresholdKey = new KeyList([accountKey, requesterKey], 1);
|
|
173
|
+
const memo = this._generateHcs10Memo(Hcs10MemoType.CONNECTION, {
|
|
174
|
+
ttl,
|
|
175
|
+
inboundTopicId,
|
|
176
|
+
connectionId
|
|
177
|
+
});
|
|
178
|
+
const transaction = new TopicCreateTransaction().setTopicMemo(memo).setAdminKey(thresholdKey).setSubmitKey(thresholdKey);
|
|
179
|
+
this.logger.debug("Executing topic creation transaction");
|
|
180
|
+
const txResponse = await this.hwc.executeTransactionWithErrorHandling(
|
|
181
|
+
transaction,
|
|
182
|
+
false
|
|
183
|
+
);
|
|
184
|
+
if (txResponse.error) {
|
|
185
|
+
this.logger.error(txResponse.error);
|
|
186
|
+
throw new Error(txResponse.error);
|
|
187
|
+
}
|
|
188
|
+
const resultReceipt = txResponse.result;
|
|
189
|
+
if (!resultReceipt?.topicId) {
|
|
190
|
+
this.logger.error("Failed to create topic: topicId is null");
|
|
191
|
+
throw new Error("Failed to create topic: topicId is null");
|
|
192
|
+
}
|
|
193
|
+
const connectionTopicId = resultReceipt.topicId.toString();
|
|
194
|
+
const operatorId = `${inboundTopicId}@${userAccountId}`;
|
|
195
|
+
const confirmedConnectionSequenceNumber = await this.confirmConnection(
|
|
196
|
+
inboundTopicId,
|
|
197
|
+
connectionTopicId,
|
|
198
|
+
requestingAccountId,
|
|
199
|
+
connectionId,
|
|
200
|
+
operatorId,
|
|
201
|
+
connectionMemo
|
|
202
|
+
);
|
|
203
|
+
return {
|
|
204
|
+
connectionTopicId,
|
|
205
|
+
confirmedConnectionSequenceNumber,
|
|
206
|
+
operatorId
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
async confirmConnection(inboundTopicId, connectionTopicId, connectedAccountId, connectionId, operatorId, memo) {
|
|
210
|
+
this.logger.info("Confirming connection");
|
|
211
|
+
const payload = {
|
|
212
|
+
p: "hcs-10",
|
|
213
|
+
op: "connection_created",
|
|
214
|
+
connection_topic_id: connectionTopicId,
|
|
215
|
+
connected_account_id: connectedAccountId,
|
|
216
|
+
operator_id: operatorId,
|
|
217
|
+
connection_id: connectionId,
|
|
218
|
+
m: memo
|
|
219
|
+
};
|
|
220
|
+
const transactionResponse = await this.submitPayload(
|
|
221
|
+
inboundTopicId,
|
|
222
|
+
payload
|
|
223
|
+
);
|
|
224
|
+
if (!transactionResponse?.topicSequenceNumber) {
|
|
225
|
+
this.logger.error(
|
|
226
|
+
"Failed to confirm connection: sequence number is null"
|
|
227
|
+
);
|
|
228
|
+
throw new Error("Failed to confirm connection: sequence number is null");
|
|
229
|
+
}
|
|
230
|
+
return transactionResponse.topicSequenceNumber.toNumber();
|
|
231
|
+
}
|
|
232
|
+
async create(builder, options) {
|
|
233
|
+
const progressCallback = options?.progressCallback;
|
|
234
|
+
const progressReporter = new ProgressReporter({
|
|
235
|
+
module: "ProfileCreate",
|
|
236
|
+
logger: this.logger,
|
|
237
|
+
callback: progressCallback
|
|
238
|
+
});
|
|
81
239
|
try {
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
240
|
+
const isAgentBuilder = builder instanceof AgentBuilder;
|
|
241
|
+
let state;
|
|
242
|
+
if (options?.existingState) {
|
|
243
|
+
state = options.existingState;
|
|
244
|
+
} else {
|
|
245
|
+
state = {
|
|
246
|
+
currentStage: "init",
|
|
247
|
+
completedPercentage: 0,
|
|
248
|
+
createdResources: []
|
|
88
249
|
};
|
|
89
250
|
}
|
|
90
|
-
if (
|
|
91
|
-
|
|
251
|
+
if (isAgentBuilder) {
|
|
252
|
+
this.logger.info("Creating Agent Profile and HCS-10 Topics");
|
|
253
|
+
const agentConfig = builder.build();
|
|
254
|
+
state.agentMetadata = agentConfig.metadata;
|
|
255
|
+
} else {
|
|
256
|
+
this.logger.info("Creating Person HCS-11 Profile");
|
|
92
257
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
}
|
|
258
|
+
progressReporter.preparing(
|
|
259
|
+
`Starting ${isAgentBuilder ? "agent" : "person"} resource creation`,
|
|
260
|
+
0,
|
|
261
|
+
{
|
|
262
|
+
state
|
|
109
263
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
264
|
+
);
|
|
265
|
+
const {
|
|
266
|
+
inboundTopicId,
|
|
267
|
+
outboundTopicId,
|
|
268
|
+
state: updatedState
|
|
269
|
+
} = await this.createCommunicationTopics(options, progressReporter);
|
|
270
|
+
state = updatedState;
|
|
271
|
+
if (!isAgentBuilder) {
|
|
272
|
+
builder.setInboundTopicId(inboundTopicId);
|
|
273
|
+
builder.setOutboundTopicId(outboundTopicId);
|
|
274
|
+
}
|
|
275
|
+
let pfpTopicId;
|
|
276
|
+
let hasPfpBuffer;
|
|
277
|
+
let pfpFileName;
|
|
278
|
+
if (isAgentBuilder) {
|
|
279
|
+
const agentProfile = builder.build();
|
|
280
|
+
pfpTopicId = agentProfile.existingPfpTopicId || state.pfpTopicId;
|
|
281
|
+
hasPfpBuffer = agentProfile.pfpBuffer;
|
|
282
|
+
pfpFileName = agentProfile.pfpFileName || "pfp.png";
|
|
283
|
+
} else {
|
|
284
|
+
const personProfile = builder.build();
|
|
285
|
+
pfpTopicId = state.pfpTopicId;
|
|
286
|
+
hasPfpBuffer = personProfile.pfpBuffer;
|
|
287
|
+
pfpFileName = personProfile.pfpFileName;
|
|
288
|
+
}
|
|
289
|
+
if (!pfpTopicId && hasPfpBuffer && pfpFileName) {
|
|
290
|
+
pfpTopicId = await this.handleProfilePictureCreation(
|
|
291
|
+
hasPfpBuffer,
|
|
292
|
+
pfpFileName,
|
|
293
|
+
state,
|
|
294
|
+
progressReporter
|
|
295
|
+
);
|
|
296
|
+
} else if (pfpTopicId) {
|
|
297
|
+
progressReporter.preparing(
|
|
298
|
+
`Using existing profile picture: ${pfpTopicId}`,
|
|
299
|
+
50,
|
|
300
|
+
{ state }
|
|
113
301
|
);
|
|
302
|
+
state.pfpTopicId = pfpTopicId;
|
|
114
303
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
304
|
+
await this.createAndInscribeProfile(
|
|
305
|
+
isAgentBuilder,
|
|
306
|
+
builder,
|
|
307
|
+
pfpTopicId,
|
|
308
|
+
state,
|
|
309
|
+
inboundTopicId,
|
|
310
|
+
outboundTopicId,
|
|
311
|
+
options,
|
|
312
|
+
progressReporter
|
|
313
|
+
);
|
|
314
|
+
state.currentStage = "complete";
|
|
315
|
+
state.completedPercentage = 100;
|
|
316
|
+
progressReporter.completed(
|
|
317
|
+
`${isAgentBuilder ? "Agent" : "Person"} profile created successfully`,
|
|
318
|
+
{
|
|
319
|
+
profileTopicId: state.profileTopicId,
|
|
320
|
+
inboundTopicId,
|
|
321
|
+
outboundTopicId,
|
|
322
|
+
pfpTopicId,
|
|
323
|
+
state
|
|
324
|
+
}
|
|
325
|
+
);
|
|
326
|
+
let outTopicId = "";
|
|
327
|
+
if (state.outboundTopicId) {
|
|
328
|
+
outTopicId = state.outboundTopicId;
|
|
329
|
+
}
|
|
330
|
+
let inTopicId = "";
|
|
331
|
+
if (state.inboundTopicId) {
|
|
332
|
+
inTopicId = state.inboundTopicId;
|
|
333
|
+
}
|
|
334
|
+
let profilePicTopicId = "";
|
|
335
|
+
if (state.pfpTopicId) {
|
|
336
|
+
profilePicTopicId = state.pfpTopicId;
|
|
337
|
+
}
|
|
338
|
+
let profTopicId = "";
|
|
339
|
+
if (state.profileTopicId) {
|
|
340
|
+
profTopicId = state.profileTopicId;
|
|
121
341
|
}
|
|
122
342
|
return {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
343
|
+
outboundTopicId: outTopicId,
|
|
344
|
+
inboundTopicId: inTopicId,
|
|
345
|
+
pfpTopicId: profilePicTopicId,
|
|
346
|
+
profileTopicId: profTopicId,
|
|
347
|
+
success: true,
|
|
348
|
+
state
|
|
126
349
|
};
|
|
127
350
|
} catch (error) {
|
|
128
|
-
|
|
129
|
-
|
|
351
|
+
progressReporter.failed("Error during profile creation", {
|
|
352
|
+
error: error.message
|
|
353
|
+
});
|
|
130
354
|
return {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
355
|
+
outboundTopicId: "",
|
|
356
|
+
inboundTopicId: "",
|
|
357
|
+
pfpTopicId: "",
|
|
358
|
+
profileTopicId: "",
|
|
359
|
+
success: false,
|
|
360
|
+
error: error.message,
|
|
361
|
+
state: {
|
|
362
|
+
currentStage: "init",
|
|
363
|
+
completedPercentage: 0,
|
|
364
|
+
error: error.message
|
|
365
|
+
}
|
|
134
366
|
};
|
|
135
367
|
}
|
|
136
368
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
369
|
+
async handleProfilePictureCreation(pfpBuffer, pfpFileName, state, progressReporter) {
|
|
370
|
+
state.currentStage = "pfp";
|
|
371
|
+
progressReporter.preparing("Creating profile picture", 30, {
|
|
372
|
+
state
|
|
373
|
+
});
|
|
374
|
+
const pfpProgress = progressReporter.createSubProgress({
|
|
375
|
+
minPercent: 30,
|
|
376
|
+
maxPercent: 50,
|
|
377
|
+
logPrefix: "PFP"
|
|
378
|
+
});
|
|
379
|
+
const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName, {
|
|
380
|
+
progressCallback: (data) => pfpProgress.report({
|
|
381
|
+
...data,
|
|
382
|
+
progressPercent: data.progressPercent ?? 0,
|
|
383
|
+
details: { ...data.details, state }
|
|
384
|
+
})
|
|
385
|
+
});
|
|
386
|
+
if (!pfpResult.success) {
|
|
387
|
+
let errorMessage = "Failed to inscribe profile picture";
|
|
388
|
+
if (pfpResult.error) {
|
|
389
|
+
errorMessage = pfpResult.error;
|
|
390
|
+
}
|
|
391
|
+
throw new Error(errorMessage);
|
|
392
|
+
}
|
|
393
|
+
const pfpTopicId = pfpResult.pfpTopicId;
|
|
394
|
+
state.pfpTopicId = pfpTopicId;
|
|
395
|
+
if (state.createdResources) {
|
|
396
|
+
state.createdResources.push(`pfp:${state.pfpTopicId}`);
|
|
397
|
+
}
|
|
398
|
+
progressReporter.preparing("Profile picture created", 50, { state });
|
|
399
|
+
return pfpTopicId;
|
|
400
|
+
}
|
|
401
|
+
async createAndInscribeProfile(isAgentBuilder, builder, pfpTopicId, state, inboundTopicId, outboundTopicId, options, progressReporter) {
|
|
402
|
+
if (!this.hcs11Client) {
|
|
403
|
+
if (progressReporter) {
|
|
404
|
+
progressReporter.failed("HCS11Client is not available");
|
|
405
|
+
}
|
|
406
|
+
throw new Error("HCS11Client is not available");
|
|
407
|
+
}
|
|
408
|
+
this.logger.info("Creating and inscribing profile");
|
|
409
|
+
if (!state.profileTopicId) {
|
|
410
|
+
if (progressReporter) {
|
|
411
|
+
progressReporter.preparing(
|
|
412
|
+
`Storing HCS-11 ${isAgentBuilder ? "agent" : "person"} profile`,
|
|
413
|
+
80
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
const profileProgress = progressReporter?.createSubProgress({
|
|
417
|
+
minPercent: 80,
|
|
418
|
+
maxPercent: 95,
|
|
419
|
+
logPrefix: "StoreProfile"
|
|
420
|
+
});
|
|
421
|
+
let hcs11Profile;
|
|
422
|
+
if (isAgentBuilder) {
|
|
423
|
+
const agentProfile = builder.build();
|
|
424
|
+
const socialLinks = agentProfile.metadata?.socials ? Object.entries(agentProfile.metadata.socials).map(
|
|
425
|
+
([platform, handle]) => ({
|
|
426
|
+
platform,
|
|
427
|
+
handle
|
|
428
|
+
})
|
|
429
|
+
) : [];
|
|
430
|
+
hcs11Profile = this.hcs11Client.createAIAgentProfile(
|
|
431
|
+
agentProfile.name,
|
|
432
|
+
agentProfile.metadata?.type === "manual" ? 0 : 1,
|
|
433
|
+
agentProfile.capabilities || [],
|
|
434
|
+
agentProfile.metadata?.model || "unknown",
|
|
435
|
+
{
|
|
436
|
+
alias: agentProfile.name.toLowerCase().replace(/\s+/g, "_"),
|
|
437
|
+
bio: agentProfile.bio,
|
|
438
|
+
profileImage: pfpTopicId ? `hcs://1/${pfpTopicId}` : void 0,
|
|
439
|
+
socials: socialLinks,
|
|
440
|
+
properties: agentProfile.metadata?.properties || {},
|
|
441
|
+
inboundTopicId,
|
|
442
|
+
outboundTopicId,
|
|
443
|
+
creator: agentProfile.metadata?.creator
|
|
152
444
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
445
|
+
);
|
|
446
|
+
} else {
|
|
447
|
+
const personProfile = builder.build();
|
|
448
|
+
const { pfpBuffer, pfpFileName, ...cleanProfile } = personProfile;
|
|
449
|
+
hcs11Profile = this.hcs11Client.createPersonalProfile(
|
|
450
|
+
personProfile.display_name,
|
|
451
|
+
{
|
|
452
|
+
alias: personProfile.alias,
|
|
453
|
+
bio: personProfile.bio,
|
|
454
|
+
socials: personProfile.socials,
|
|
455
|
+
profileImage: pfpTopicId ? `hcs://1/${pfpTopicId}` : personProfile.profileImage,
|
|
456
|
+
properties: personProfile.properties,
|
|
457
|
+
inboundTopicId,
|
|
458
|
+
outboundTopicId
|
|
157
459
|
}
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
const profileResult = await this.hcs11Client.createAndInscribeProfile(
|
|
463
|
+
hcs11Profile,
|
|
464
|
+
options?.updateAccountMemo ?? true,
|
|
465
|
+
{
|
|
466
|
+
progressCallback: (data) => profileProgress?.report({
|
|
467
|
+
...data,
|
|
468
|
+
progressPercent: data.progressPercent ?? 0
|
|
469
|
+
})
|
|
158
470
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
471
|
+
);
|
|
472
|
+
if (!profileResult.success) {
|
|
473
|
+
if (progressReporter) {
|
|
474
|
+
progressReporter.failed(
|
|
475
|
+
`Failed to inscribe ${isAgentBuilder ? "agent" : "person"} profile`,
|
|
476
|
+
{
|
|
477
|
+
error: profileResult.error
|
|
478
|
+
}
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
let errorMessage = `Failed to inscribe ${isAgentBuilder ? "agent" : "person"} profile`;
|
|
482
|
+
if (profileResult.error) {
|
|
483
|
+
errorMessage = profileResult.error;
|
|
484
|
+
}
|
|
485
|
+
throw new Error(errorMessage);
|
|
486
|
+
}
|
|
487
|
+
state.profileTopicId = profileResult.profileTopicId;
|
|
488
|
+
if (state.createdResources) {
|
|
489
|
+
state.createdResources.push(`profile:${profileResult.profileTopicId}`);
|
|
167
490
|
}
|
|
168
|
-
|
|
491
|
+
if (progressReporter) {
|
|
492
|
+
progressReporter.preparing("HCS-11 Profile stored", 95, { state });
|
|
493
|
+
}
|
|
494
|
+
} else if (progressReporter) {
|
|
495
|
+
progressReporter.preparing(
|
|
496
|
+
`Using existing ${isAgentBuilder ? "agent" : "person"} profile`,
|
|
497
|
+
95,
|
|
498
|
+
{
|
|
499
|
+
state
|
|
500
|
+
}
|
|
501
|
+
);
|
|
169
502
|
}
|
|
170
503
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
504
|
+
initializeRegistrationState(inboundTopicId, existingState) {
|
|
505
|
+
const state = existingState || {
|
|
506
|
+
inboundTopicId,
|
|
507
|
+
currentStage: "registration",
|
|
508
|
+
completedPercentage: 0,
|
|
509
|
+
createdResources: []
|
|
510
|
+
};
|
|
511
|
+
if (state.currentStage !== "registration" && state.currentStage !== "complete") {
|
|
512
|
+
state.currentStage = "registration";
|
|
177
513
|
}
|
|
514
|
+
return state;
|
|
178
515
|
}
|
|
179
|
-
|
|
180
|
-
|
|
516
|
+
updateStateForCompletedRegistration(state, inboundTopicId) {
|
|
517
|
+
state.currentStage = "complete";
|
|
518
|
+
state.completedPercentage = 100;
|
|
519
|
+
if (state.createdResources) {
|
|
520
|
+
state.createdResources.push(`registration:${inboundTopicId}`);
|
|
521
|
+
}
|
|
181
522
|
}
|
|
182
|
-
async
|
|
183
|
-
this.logger.info(`Retrieving profile for account: ${accountId}`);
|
|
523
|
+
async registerAgentWithGuardedRegistry(accountId, network = this.network, options) {
|
|
184
524
|
try {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
525
|
+
this.logger.info("Registering agent with guarded registry");
|
|
526
|
+
const agentProfile = await this.retrieveProfile(accountId);
|
|
527
|
+
const inboundTopicId = agentProfile.topicInfo.inboundTopic;
|
|
528
|
+
const state = this.initializeRegistrationState(
|
|
529
|
+
inboundTopicId,
|
|
530
|
+
options?.existingState
|
|
531
|
+
);
|
|
532
|
+
const progressReporter = new ProgressReporter({
|
|
533
|
+
module: "AgentRegistration",
|
|
534
|
+
logger: this.logger,
|
|
535
|
+
callback: options?.progressCallback
|
|
536
|
+
});
|
|
537
|
+
progressReporter.preparing("Preparing agent registration", 10, {
|
|
538
|
+
inboundTopicId,
|
|
539
|
+
accountId
|
|
192
540
|
});
|
|
193
|
-
const
|
|
541
|
+
const registrationResult = await this.executeRegistration(
|
|
194
542
|
accountId,
|
|
195
|
-
|
|
543
|
+
network,
|
|
544
|
+
this.guardedRegistryBaseUrl,
|
|
545
|
+
this.logger
|
|
196
546
|
);
|
|
197
|
-
if (!
|
|
198
|
-
this.logger.error(
|
|
199
|
-
`Failed to retrieve profile for account ID: ${accountId}`,
|
|
200
|
-
profileResult?.error
|
|
201
|
-
);
|
|
547
|
+
if (!registrationResult.success) {
|
|
202
548
|
return {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
error: profileResult?.error || `Failed to retrieve profile for account ID: ${accountId}`
|
|
549
|
+
...registrationResult,
|
|
550
|
+
state
|
|
206
551
|
};
|
|
207
552
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
const
|
|
217
|
-
|
|
553
|
+
progressReporter.submitting("Submitting registration to registry", 30, {
|
|
554
|
+
transactionId: registrationResult.transactionId
|
|
555
|
+
});
|
|
556
|
+
if (registrationResult.transaction) {
|
|
557
|
+
const transaction = Transaction.fromBytes(
|
|
558
|
+
Buffer.from(registrationResult.transaction, "base64")
|
|
559
|
+
);
|
|
560
|
+
this.logger.info(`Processing registration transaction`);
|
|
561
|
+
const txResult = await this.hwc.executeTransactionWithErrorHandling(
|
|
562
|
+
transaction,
|
|
563
|
+
true
|
|
564
|
+
);
|
|
565
|
+
if (txResult.error) {
|
|
566
|
+
return {
|
|
567
|
+
...registrationResult,
|
|
568
|
+
error: txResult.error,
|
|
569
|
+
success: false,
|
|
570
|
+
state
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
this.logger.info(`Successfully processed registration transaction`);
|
|
218
574
|
}
|
|
575
|
+
progressReporter.confirming("Confirming registration transaction", 60, {
|
|
576
|
+
accountId,
|
|
577
|
+
inboundTopicId,
|
|
578
|
+
transactionId: registrationResult.transactionId
|
|
579
|
+
});
|
|
580
|
+
const maxAttempts = options?.maxAttempts ?? 60;
|
|
581
|
+
const delayMs = options?.delayMs ?? 2e3;
|
|
582
|
+
const confirmed = await this.waitForRegistrationConfirmation(
|
|
583
|
+
registrationResult.transactionId,
|
|
584
|
+
network,
|
|
585
|
+
this.guardedRegistryBaseUrl,
|
|
586
|
+
maxAttempts,
|
|
587
|
+
delayMs,
|
|
588
|
+
this.logger
|
|
589
|
+
);
|
|
590
|
+
this.updateStateForCompletedRegistration(state, inboundTopicId);
|
|
591
|
+
progressReporter.completed("Agent registration complete", {
|
|
592
|
+
transactionId: registrationResult.transactionId,
|
|
593
|
+
inboundTopicId,
|
|
594
|
+
state,
|
|
595
|
+
confirmed
|
|
596
|
+
});
|
|
219
597
|
return {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
598
|
+
...registrationResult,
|
|
599
|
+
confirmed,
|
|
600
|
+
state
|
|
223
601
|
};
|
|
224
602
|
} catch (error) {
|
|
225
|
-
this.logger.error(
|
|
603
|
+
this.logger.error(`Registration error: ${error.message}`);
|
|
226
604
|
return {
|
|
227
|
-
|
|
605
|
+
error: `Error during registration: ${error.message}`,
|
|
228
606
|
success: false,
|
|
229
|
-
|
|
607
|
+
state: {
|
|
608
|
+
currentStage: "registration",
|
|
609
|
+
completedPercentage: 0,
|
|
610
|
+
error: error.message
|
|
611
|
+
}
|
|
230
612
|
};
|
|
231
613
|
}
|
|
232
614
|
}
|
|
233
|
-
async
|
|
234
|
-
this.logger.info(`Retrieving topics for account: ${accountId}`);
|
|
615
|
+
async createAndRegisterAgent(builder, options) {
|
|
235
616
|
try {
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
617
|
+
const agentConfig = builder.build();
|
|
618
|
+
const progressCallback = options?.progressCallback;
|
|
619
|
+
const progressReporter = new ProgressReporter({
|
|
620
|
+
module: "AgentCreateRegister",
|
|
621
|
+
logger: this.logger,
|
|
622
|
+
callback: progressCallback
|
|
623
|
+
});
|
|
624
|
+
let state = options?.existingState || {
|
|
625
|
+
currentStage: "init",
|
|
626
|
+
completedPercentage: 0,
|
|
627
|
+
createdResources: []
|
|
628
|
+
};
|
|
629
|
+
state.agentMetadata = agentConfig.metadata;
|
|
630
|
+
progressReporter.preparing("Starting agent creation process", 0, {
|
|
631
|
+
state
|
|
632
|
+
});
|
|
633
|
+
if (state.currentStage !== "complete" || !state.inboundTopicId || !state.outboundTopicId || !state.profileTopicId) {
|
|
634
|
+
const createResult = await this.create(builder, {
|
|
635
|
+
progressCallback: (progress) => {
|
|
636
|
+
const adjustedPercent = (progress.progressPercent || 0) * 0.3;
|
|
637
|
+
progressReporter.report({
|
|
638
|
+
...progress,
|
|
639
|
+
progressPercent: adjustedPercent,
|
|
640
|
+
details: {
|
|
641
|
+
...progress.details,
|
|
642
|
+
state: progress.details?.state || state
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
},
|
|
646
|
+
existingState: state,
|
|
647
|
+
updateAccountMemo: false
|
|
648
|
+
});
|
|
649
|
+
if (!("state" in createResult)) {
|
|
650
|
+
throw new Error("Create method did not return expected agent state.");
|
|
651
|
+
}
|
|
652
|
+
if (!createResult.success) {
|
|
653
|
+
throw new Error(
|
|
654
|
+
createResult.error || "Failed to create agent resources"
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
state = createResult.state;
|
|
658
|
+
state.agentMetadata = agentConfig.metadata;
|
|
239
659
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
660
|
+
progressReporter.preparing(
|
|
661
|
+
`Agent creation status: ${state.currentStage}, ${state.completedPercentage}%`,
|
|
662
|
+
30,
|
|
663
|
+
{ state }
|
|
664
|
+
);
|
|
665
|
+
const { accountId } = this.getAccountAndSigner();
|
|
666
|
+
if (state.currentStage !== "complete" || !state.createdResources?.includes(
|
|
667
|
+
`registration:${state.inboundTopicId}`
|
|
668
|
+
)) {
|
|
669
|
+
if (options?.baseUrl) {
|
|
670
|
+
this.guardedRegistryBaseUrl = options.baseUrl;
|
|
671
|
+
}
|
|
672
|
+
const registrationResult = await this.registerAgentWithGuardedRegistry(
|
|
673
|
+
accountId,
|
|
674
|
+
agentConfig.network,
|
|
675
|
+
{
|
|
676
|
+
progressCallback: (progress) => {
|
|
677
|
+
const adjustedPercent = 30 + (progress.progressPercent || 0) * 0.7;
|
|
678
|
+
progressReporter.report({
|
|
679
|
+
...progress,
|
|
680
|
+
progressPercent: adjustedPercent,
|
|
681
|
+
details: {
|
|
682
|
+
...progress.details,
|
|
683
|
+
state: progress.details?.state || state
|
|
684
|
+
}
|
|
685
|
+
});
|
|
686
|
+
},
|
|
687
|
+
maxAttempts: options?.maxAttempts,
|
|
688
|
+
delayMs: options?.delayMs,
|
|
689
|
+
existingState: state
|
|
690
|
+
}
|
|
244
691
|
);
|
|
692
|
+
if (!registrationResult.success) {
|
|
693
|
+
throw new Error(
|
|
694
|
+
registrationResult.error || "Failed to register agent with registry"
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
state = registrationResult.state;
|
|
698
|
+
if (state.profileTopicId) {
|
|
699
|
+
await this.hcs11Client?.updateAccountMemoWithProfile(
|
|
700
|
+
accountId,
|
|
701
|
+
state.profileTopicId
|
|
702
|
+
);
|
|
703
|
+
}
|
|
245
704
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
705
|
+
progressReporter.completed("Agent creation and registration complete", {
|
|
706
|
+
state
|
|
707
|
+
});
|
|
708
|
+
return {
|
|
709
|
+
success: true,
|
|
710
|
+
state,
|
|
711
|
+
metadata: {
|
|
712
|
+
accountId,
|
|
713
|
+
operatorId: `${state.inboundTopicId}@${accountId}`,
|
|
714
|
+
inboundTopicId: state.inboundTopicId,
|
|
715
|
+
outboundTopicId: state.outboundTopicId,
|
|
716
|
+
profileTopicId: state.profileTopicId,
|
|
717
|
+
pfpTopicId: state.pfpTopicId,
|
|
718
|
+
privateKey: null,
|
|
719
|
+
...state.agentMetadata
|
|
720
|
+
}
|
|
250
721
|
};
|
|
251
|
-
const cacheKey = `${accountId}-${this.network}`;
|
|
252
|
-
HCS10Cache.getInstance().set(cacheKey, topicInfo);
|
|
253
|
-
return topicInfo;
|
|
254
722
|
} catch (error) {
|
|
255
|
-
this.logger.error(
|
|
256
|
-
|
|
723
|
+
this.logger.error(
|
|
724
|
+
`Failed to create and register agent: ${error.message}`
|
|
725
|
+
);
|
|
726
|
+
return {
|
|
727
|
+
success: false,
|
|
728
|
+
error: `Failed to create and register agent: ${error.message}`,
|
|
729
|
+
state: options?.existingState || {
|
|
730
|
+
currentStage: "init",
|
|
731
|
+
completedPercentage: 0,
|
|
732
|
+
error: error.message
|
|
733
|
+
}
|
|
734
|
+
};
|
|
257
735
|
}
|
|
258
736
|
}
|
|
259
|
-
async
|
|
737
|
+
async storeHCS11Profile(agentName, agentBio, inboundTopicId, outboundTopicId, capabilities = [], metadata = {}, pfpBuffer, pfpFileName, existingPfpTopicId, options) {
|
|
260
738
|
try {
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
739
|
+
const progressCallback = options?.progressCallback;
|
|
740
|
+
const progressReporter = new ProgressReporter({
|
|
741
|
+
module: "StoreHCS11Profile",
|
|
742
|
+
logger: this.logger,
|
|
743
|
+
callback: progressCallback
|
|
744
|
+
});
|
|
745
|
+
progressReporter.preparing("Preparing agent profile data", 0);
|
|
746
|
+
let pfpTopicId = existingPfpTopicId;
|
|
747
|
+
if (!pfpTopicId && pfpBuffer && pfpFileName) {
|
|
748
|
+
const pfpProgress = progressReporter.createSubProgress({
|
|
749
|
+
minPercent: 0,
|
|
750
|
+
maxPercent: 60,
|
|
751
|
+
logPrefix: "PFP"
|
|
752
|
+
});
|
|
753
|
+
const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName, {
|
|
754
|
+
progressCallback: (data) => {
|
|
755
|
+
pfpProgress.report({
|
|
756
|
+
stage: data.stage,
|
|
757
|
+
message: data.message,
|
|
758
|
+
progressPercent: data.progressPercent || 0,
|
|
759
|
+
details: data.details
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
});
|
|
763
|
+
if (!pfpResult.success) {
|
|
764
|
+
progressReporter.failed(
|
|
765
|
+
"Failed to inscribe profile picture, continuing without PFP"
|
|
766
|
+
);
|
|
767
|
+
} else {
|
|
768
|
+
pfpTopicId = pfpResult.pfpTopicId;
|
|
769
|
+
}
|
|
770
|
+
} else if (existingPfpTopicId) {
|
|
771
|
+
progressReporter.preparing(
|
|
772
|
+
`Using existing profile picture: ${existingPfpTopicId}`,
|
|
773
|
+
30
|
|
265
774
|
);
|
|
266
|
-
|
|
775
|
+
} else {
|
|
776
|
+
progressReporter.preparing("No profile picture provided", 30);
|
|
267
777
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
778
|
+
if (!this.hcs11Client) {
|
|
779
|
+
progressReporter.failed(
|
|
780
|
+
"HCS11Client is not available in this environment"
|
|
781
|
+
);
|
|
782
|
+
return {
|
|
783
|
+
profileTopicId: "",
|
|
784
|
+
success: false,
|
|
785
|
+
error: "HCS11Client is not available in this environment",
|
|
786
|
+
transactionId: ""
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
const agentType = this.hcs11Client.getAgentTypeFromMetadata({
|
|
790
|
+
type: metadata.type || "autonomous"
|
|
791
|
+
});
|
|
792
|
+
progressReporter.preparing("Building agent profile", 65);
|
|
793
|
+
const formattedSocials = metadata.socials ? Object.entries(metadata.socials).filter(([_, handle]) => handle).map(([platform, handle]) => ({
|
|
794
|
+
platform,
|
|
795
|
+
handle
|
|
796
|
+
})) : void 0;
|
|
797
|
+
const profile = this.hcs11Client.createAIAgentProfile(
|
|
798
|
+
agentName,
|
|
799
|
+
agentType,
|
|
800
|
+
capabilities,
|
|
801
|
+
metadata.model || "unknown",
|
|
802
|
+
{
|
|
803
|
+
alias: agentName.toLowerCase().replace(/\s+/g, "_"),
|
|
804
|
+
bio: agentBio,
|
|
805
|
+
profileImage: pfpTopicId ? `hcs://1/${pfpTopicId}` : void 0,
|
|
806
|
+
socials: formattedSocials,
|
|
807
|
+
properties: {
|
|
808
|
+
version: metadata.version || "1.0.0",
|
|
809
|
+
creator: metadata.creator || "Unknown",
|
|
810
|
+
supported_languages: metadata.supported_languages || ["en"],
|
|
811
|
+
permissions: metadata.permissions || [],
|
|
812
|
+
model_details: metadata.model_details,
|
|
813
|
+
training: metadata.training,
|
|
814
|
+
capabilities_description: metadata.capabilities_description,
|
|
815
|
+
...metadata
|
|
816
|
+
},
|
|
817
|
+
inboundTopicId,
|
|
818
|
+
outboundTopicId,
|
|
819
|
+
creator: metadata.creator
|
|
820
|
+
}
|
|
271
821
|
);
|
|
822
|
+
const profileProgress = progressReporter.createSubProgress({
|
|
823
|
+
minPercent: 65,
|
|
824
|
+
maxPercent: 100,
|
|
825
|
+
logPrefix: "Profile"
|
|
826
|
+
});
|
|
827
|
+
const profileResult = await this.hcs11Client.createAndInscribeProfile(
|
|
828
|
+
profile,
|
|
829
|
+
true,
|
|
830
|
+
{
|
|
831
|
+
progressCallback: (profileData) => {
|
|
832
|
+
profileProgress.report({
|
|
833
|
+
stage: profileData.stage,
|
|
834
|
+
message: profileData.message,
|
|
835
|
+
progressPercent: profileData.progressPercent || 0,
|
|
836
|
+
details: profileData.details
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
);
|
|
841
|
+
if (!profileResult.success) {
|
|
842
|
+
progressReporter.failed("Failed to inscribe profile");
|
|
843
|
+
return {
|
|
844
|
+
profileTopicId: "",
|
|
845
|
+
success: false,
|
|
846
|
+
error: profileResult.error || "Failed to inscribe profile",
|
|
847
|
+
transactionId: profileResult.transactionId || ""
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
progressReporter.completed("Profile stored successfully", {
|
|
851
|
+
profileTopicId: profileResult.profileTopicId
|
|
852
|
+
});
|
|
853
|
+
return {
|
|
854
|
+
profileTopicId: profileResult.profileTopicId,
|
|
855
|
+
pfpTopicId,
|
|
856
|
+
success: true,
|
|
857
|
+
transactionId: profileResult.transactionId || ""
|
|
858
|
+
};
|
|
272
859
|
} catch (error) {
|
|
273
|
-
this.logger.error(
|
|
274
|
-
return
|
|
860
|
+
this.logger.error(`Error storing HCS11 profile: ${error.message}`);
|
|
861
|
+
return {
|
|
862
|
+
profileTopicId: "",
|
|
863
|
+
success: false,
|
|
864
|
+
error: error.message,
|
|
865
|
+
transactionId: ""
|
|
866
|
+
};
|
|
275
867
|
}
|
|
276
868
|
}
|
|
277
|
-
async
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
869
|
+
async createTopic(memo, adminKey, submitKey) {
|
|
870
|
+
this.logger.info("Creating topic");
|
|
871
|
+
const { accountId, signer } = this.getAccountAndSigner();
|
|
872
|
+
const transaction = new TopicCreateTransaction().setTopicMemo(memo);
|
|
873
|
+
const publicKey = await this.mirrorNode.getPublicKey(accountId);
|
|
874
|
+
if (adminKey && publicKey) {
|
|
875
|
+
transaction.setAdminKey(publicKey);
|
|
876
|
+
transaction.setAutoRenewAccountId(accountId);
|
|
877
|
+
}
|
|
878
|
+
if (submitKey && publicKey) {
|
|
879
|
+
transaction.setSubmitKey(publicKey);
|
|
880
|
+
}
|
|
881
|
+
const transactionResponse = await this.hwc.executeTransactionWithErrorHandling(
|
|
882
|
+
transaction,
|
|
883
|
+
false
|
|
884
|
+
);
|
|
885
|
+
const error = transactionResponse.error;
|
|
886
|
+
if (error) {
|
|
887
|
+
this.logger.error(error);
|
|
888
|
+
return {
|
|
889
|
+
success: false,
|
|
890
|
+
error
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
const resultReceipt = transactionResponse.result;
|
|
894
|
+
if (!resultReceipt?.topicId) {
|
|
895
|
+
this.logger.error("Failed to create topic: topicId is null");
|
|
896
|
+
return {
|
|
897
|
+
success: false,
|
|
898
|
+
error: "Failed to create topic: topicId is null"
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
return {
|
|
902
|
+
success: true,
|
|
903
|
+
topicId: resultReceipt.topicId.toString()
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
async submitPayload(topicId, payload, submitKey, requiresFee) {
|
|
907
|
+
this.logger.debug(`Submitting payload to topic ${topicId}`);
|
|
908
|
+
let message;
|
|
909
|
+
if (typeof payload === "string") {
|
|
910
|
+
message = payload;
|
|
911
|
+
} else {
|
|
912
|
+
message = JSON.stringify(payload);
|
|
913
|
+
}
|
|
914
|
+
const transaction = new TopicMessageSubmitTransaction().setTopicId(topicId).setMessage(message);
|
|
915
|
+
let transactionResponse;
|
|
916
|
+
if (requiresFee) {
|
|
917
|
+
this.logger.info(
|
|
918
|
+
"Topic requires fee payment, setting max transaction fee"
|
|
281
919
|
);
|
|
282
|
-
|
|
283
|
-
|
|
920
|
+
transaction.setMaxTransactionFee(new Hbar(this.feeAmount));
|
|
921
|
+
transaction.setTransactionMemo("HIP-991 Fee Payment");
|
|
922
|
+
}
|
|
923
|
+
if (submitKey) {
|
|
924
|
+
const { accountId, signer } = this.getAccountAndSigner();
|
|
925
|
+
transaction.freezeWithSigner(signer);
|
|
926
|
+
const signedTransaction = await transaction.sign(submitKey);
|
|
927
|
+
transactionResponse = await this.hwc.executeTransactionWithErrorHandling(
|
|
928
|
+
signedTransaction,
|
|
929
|
+
true
|
|
284
930
|
);
|
|
285
|
-
|
|
286
|
-
|
|
931
|
+
} else {
|
|
932
|
+
transactionResponse = await this.hwc.executeTransactionWithErrorHandling(
|
|
933
|
+
transaction,
|
|
934
|
+
false
|
|
287
935
|
);
|
|
288
|
-
} catch (error) {
|
|
289
|
-
this.logger.error("Failed to check connection created:", error);
|
|
290
|
-
return false;
|
|
291
936
|
}
|
|
292
|
-
|
|
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;
|
|
303
|
-
}
|
|
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}`);
|
|
313
|
-
}
|
|
314
|
-
return response.data.content || response.data.text || JSON.stringify(response.data);
|
|
315
|
-
} catch (error) {
|
|
937
|
+
if (transactionResponse?.error) {
|
|
316
938
|
this.logger.error(
|
|
317
|
-
`
|
|
939
|
+
`Failed to submit payload: ${transactionResponse.error}`
|
|
318
940
|
);
|
|
319
|
-
throw new Error(
|
|
320
|
-
|
|
941
|
+
throw new Error(`Failed to submit payload: ${transactionResponse.error}`);
|
|
942
|
+
}
|
|
943
|
+
if (!transactionResponse?.result) {
|
|
944
|
+
this.logger.error(
|
|
945
|
+
"Failed to submit message: receipt is null or undefined"
|
|
321
946
|
);
|
|
947
|
+
throw new Error("Failed to submit message: receipt is null or undefined");
|
|
322
948
|
}
|
|
949
|
+
this.logger.debug("Payload submitted successfully via HWC");
|
|
950
|
+
return transactionResponse.result;
|
|
323
951
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
p: "hcs-10",
|
|
343
|
-
op: "connection_created",
|
|
344
|
-
connection_topic_id: connectionTopicId,
|
|
345
|
-
outbound_topic_id: outboundTopicId,
|
|
346
|
-
confirmed_request_id: confirmedRequestId,
|
|
347
|
-
connection_request_id: connectionRequestId,
|
|
348
|
-
operator_id: operatorId,
|
|
349
|
-
m: memo
|
|
952
|
+
async inscribeFile(buffer, fileName, options) {
|
|
953
|
+
const { accountId, signer } = this.getAccountAndSigner();
|
|
954
|
+
const mimeType = mimeTypesExports.lookup(fileName) || "application/octet-stream";
|
|
955
|
+
const sdk = await InscriptionSDK.createWithAuth({
|
|
956
|
+
type: "client",
|
|
957
|
+
accountId,
|
|
958
|
+
signer,
|
|
959
|
+
network: this.network
|
|
960
|
+
});
|
|
961
|
+
const inscriptionOptions = {
|
|
962
|
+
mode: "file",
|
|
963
|
+
waitForConfirmation: true,
|
|
964
|
+
waitMaxAttempts: options?.waitMaxAttempts || 30,
|
|
965
|
+
waitIntervalMs: options?.waitIntervalMs || 4e3,
|
|
966
|
+
progressCallback: options?.progressCallback,
|
|
967
|
+
logging: {
|
|
968
|
+
level: this.logger.getLevel ? this.logger.getLevel() : "info"
|
|
969
|
+
}
|
|
350
970
|
};
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
971
|
+
const response = await inscribeWithSigner(
|
|
972
|
+
{
|
|
973
|
+
type: "buffer",
|
|
974
|
+
buffer,
|
|
975
|
+
fileName,
|
|
976
|
+
mimeType
|
|
977
|
+
},
|
|
978
|
+
signer,
|
|
979
|
+
{
|
|
980
|
+
...inscriptionOptions,
|
|
981
|
+
network: this.network
|
|
982
|
+
},
|
|
983
|
+
sdk
|
|
984
|
+
);
|
|
985
|
+
if (!response.confirmed || !response.inscription) {
|
|
986
|
+
throw new Error("Inscription was not confirmed");
|
|
364
987
|
}
|
|
365
|
-
|
|
366
|
-
this.operatorId = operatorId;
|
|
367
|
-
return operatorId;
|
|
988
|
+
return response.inscription;
|
|
368
989
|
}
|
|
369
|
-
|
|
370
|
-
|
|
990
|
+
getAccountAndSigner() {
|
|
991
|
+
const accountInfo = this.hwc.getAccountInfo();
|
|
992
|
+
const accountId = accountInfo.accountId.toString();
|
|
993
|
+
const signer = this.hwc.dAppConnector.signers.find((s) => {
|
|
994
|
+
return s.getAccountId().toString() === accountId;
|
|
995
|
+
});
|
|
996
|
+
if (!signer) {
|
|
997
|
+
this.logger.error("Failed to find signer");
|
|
998
|
+
throw new Error("Failed to find signer");
|
|
999
|
+
}
|
|
1000
|
+
return { accountId, signer };
|
|
371
1001
|
}
|
|
372
1002
|
/**
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
* @param
|
|
376
|
-
* @
|
|
377
|
-
* @
|
|
1003
|
+
* Inscribes a profile picture (PFP) on HCS-11.
|
|
1004
|
+
*
|
|
1005
|
+
* @param buffer - The buffer containing the PFP image.
|
|
1006
|
+
* @param fileName - The name of the file containing the PFP image.
|
|
1007
|
+
* @param options - Optional configuration options.
|
|
1008
|
+
* @returns A promise that resolves to the topic ID of the inscribed PFP.
|
|
378
1009
|
*/
|
|
379
|
-
|
|
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");
|
|
385
|
-
}
|
|
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
|
-
);
|
|
394
|
-
}
|
|
395
|
-
return `hcs-10:1:${ttl}:2:${options.inboundTopicId}:${options.connectionId}`;
|
|
396
|
-
default:
|
|
397
|
-
throw new Error(`Invalid HCS-10 memo type: ${type}`);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
async checkRegistrationStatus(transactionId, network, baseUrl) {
|
|
1010
|
+
async inscribePfp(buffer, fileName, options) {
|
|
401
1011
|
try {
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
},
|
|
408
|
-
body: JSON.stringify({ transaction_id: transactionId })
|
|
1012
|
+
const progressCallback = options?.progressCallback;
|
|
1013
|
+
const progressReporter = new ProgressReporter({
|
|
1014
|
+
module: "PFP-Inscription",
|
|
1015
|
+
logger: this.logger,
|
|
1016
|
+
callback: progressCallback
|
|
409
1017
|
});
|
|
410
|
-
if (!
|
|
411
|
-
|
|
412
|
-
|
|
1018
|
+
if (!this.hcs11Client) {
|
|
1019
|
+
progressReporter.failed(
|
|
1020
|
+
"HCS11Client is not available in this environment"
|
|
413
1021
|
);
|
|
1022
|
+
return {
|
|
1023
|
+
pfpTopicId: "",
|
|
1024
|
+
success: false,
|
|
1025
|
+
error: "HCS11Client is not available in this environment",
|
|
1026
|
+
transactionId: ""
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
progressReporter.preparing("Preparing to inscribe profile picture", 10);
|
|
1030
|
+
this.logger.info("Inscribing profile picture using HCS-11 client");
|
|
1031
|
+
const wrappedProgressCallback = (data) => {
|
|
1032
|
+
progressReporter.report({
|
|
1033
|
+
stage: data.stage || "confirming",
|
|
1034
|
+
message: data.message || "Processing PFP inscription",
|
|
1035
|
+
progressPercent: data.progressPercent || 50,
|
|
1036
|
+
details: data.details
|
|
1037
|
+
});
|
|
1038
|
+
};
|
|
1039
|
+
const imageResult = await this.hcs11Client.inscribeImage(
|
|
1040
|
+
buffer,
|
|
1041
|
+
fileName,
|
|
1042
|
+
{ progressCallback: wrappedProgressCallback }
|
|
1043
|
+
);
|
|
1044
|
+
if (!imageResult.success) {
|
|
1045
|
+
let errorMessage = "Failed to inscribe profile picture";
|
|
1046
|
+
if (imageResult.error) {
|
|
1047
|
+
errorMessage = imageResult.error;
|
|
1048
|
+
}
|
|
1049
|
+
let txId = "";
|
|
1050
|
+
if (imageResult.transactionId) {
|
|
1051
|
+
txId = imageResult.transactionId;
|
|
1052
|
+
}
|
|
1053
|
+
return {
|
|
1054
|
+
pfpTopicId: "",
|
|
1055
|
+
success: false,
|
|
1056
|
+
error: errorMessage,
|
|
1057
|
+
transactionId: txId
|
|
1058
|
+
};
|
|
414
1059
|
}
|
|
415
|
-
|
|
1060
|
+
progressReporter.completed("Successfully inscribed profile picture", {
|
|
1061
|
+
pfpTopicId: imageResult.imageTopicId
|
|
1062
|
+
});
|
|
1063
|
+
this.logger.info(
|
|
1064
|
+
`Successfully inscribed profile picture with topic ID: ${imageResult.imageTopicId}`
|
|
1065
|
+
);
|
|
1066
|
+
return {
|
|
1067
|
+
pfpTopicId: imageResult.imageTopicId,
|
|
1068
|
+
success: true,
|
|
1069
|
+
transactionId: imageResult.transactionId || ""
|
|
1070
|
+
};
|
|
416
1071
|
} catch (error) {
|
|
417
|
-
this.logger.error(`Error
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
* @returns True if the format is valid, false otherwise
|
|
425
|
-
*/
|
|
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;
|
|
1072
|
+
this.logger.error(`Error inscribing profile picture: ${error.message}`);
|
|
1073
|
+
return {
|
|
1074
|
+
pfpTopicId: "",
|
|
1075
|
+
success: false,
|
|
1076
|
+
error: error.message,
|
|
1077
|
+
transactionId: ""
|
|
1078
|
+
};
|
|
448
1079
|
}
|
|
449
|
-
return true;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
class HCS10Cache {
|
|
453
|
-
constructor() {
|
|
454
|
-
this.CACHE_TTL = 36e5;
|
|
455
|
-
this.cache = /* @__PURE__ */ new Map();
|
|
456
|
-
this.cacheExpiry = /* @__PURE__ */ new Map();
|
|
457
1080
|
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
1081
|
+
async createCommunicationTopics(options, progressReporter) {
|
|
1082
|
+
let state = options?.existingState || {
|
|
1083
|
+
currentStage: "init",
|
|
1084
|
+
completedPercentage: 0,
|
|
1085
|
+
createdResources: []
|
|
1086
|
+
};
|
|
1087
|
+
if (progressReporter) {
|
|
1088
|
+
progressReporter.preparing("Starting communication topic creation", 0, {
|
|
1089
|
+
state
|
|
1090
|
+
});
|
|
461
1091
|
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
1092
|
+
const { accountId } = this.getAccountAndSigner();
|
|
1093
|
+
if (!state.outboundTopicId) {
|
|
1094
|
+
state.currentStage = "topics";
|
|
1095
|
+
if (progressReporter) {
|
|
1096
|
+
progressReporter.preparing("Creating outbound topic", 5, {
|
|
1097
|
+
state
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
const outboundMemo = this._generateHcs10Memo(Hcs10MemoType.OUTBOUND, {
|
|
1101
|
+
ttl: options?.ttl,
|
|
1102
|
+
accountId
|
|
1103
|
+
});
|
|
1104
|
+
const outboundResult = await this.createTopic(outboundMemo, true, true);
|
|
1105
|
+
if (!outboundResult.success || !outboundResult.topicId) {
|
|
1106
|
+
throw new Error(
|
|
1107
|
+
outboundResult.error || "Failed to create outbound topic"
|
|
1108
|
+
);
|
|
1109
|
+
}
|
|
1110
|
+
state.outboundTopicId = outboundResult.topicId;
|
|
1111
|
+
if (state.createdResources)
|
|
1112
|
+
state.createdResources.push(`outbound:${state.outboundTopicId}`);
|
|
472
1113
|
}
|
|
473
|
-
if (
|
|
474
|
-
|
|
475
|
-
|
|
1114
|
+
if (!state.inboundTopicId) {
|
|
1115
|
+
state.currentStage = "topics";
|
|
1116
|
+
if (progressReporter) {
|
|
1117
|
+
progressReporter.preparing("Creating inbound topic", 10, {
|
|
1118
|
+
state
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
1121
|
+
const inboundMemo = this._generateHcs10Memo(Hcs10MemoType.INBOUND, {
|
|
1122
|
+
ttl: options?.ttl,
|
|
1123
|
+
accountId
|
|
1124
|
+
});
|
|
1125
|
+
const inboundResult = await this.createTopic(inboundMemo, true, false);
|
|
1126
|
+
if (!inboundResult.success || !inboundResult.topicId) {
|
|
1127
|
+
throw new Error(
|
|
1128
|
+
inboundResult.error || "Failed to create inbound topic"
|
|
1129
|
+
);
|
|
1130
|
+
}
|
|
1131
|
+
state.inboundTopicId = inboundResult.topicId;
|
|
1132
|
+
if (state.createdResources)
|
|
1133
|
+
state.createdResources.push(`inbound:${state.inboundTopicId}`);
|
|
476
1134
|
}
|
|
477
|
-
return
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
1135
|
+
return {
|
|
1136
|
+
inboundTopicId: state.inboundTopicId,
|
|
1137
|
+
outboundTopicId: state.outboundTopicId,
|
|
1138
|
+
state
|
|
1139
|
+
};
|
|
482
1140
|
}
|
|
483
1141
|
}
|
|
484
1142
|
export {
|
|
485
|
-
|
|
486
|
-
HCS10Cache,
|
|
487
|
-
Hcs10MemoType
|
|
1143
|
+
BrowserHCSClient
|
|
488
1144
|
};
|
|
489
1145
|
//# sourceMappingURL=standards-sdk.es8.js.map
|