@hashgraphonline/standards-sdk 0.1.144 → 0.1.145
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/cjs/hcs-10/base-client.d.ts.map +1 -1
- package/dist/cjs/hcs-10/sdk.d.ts +8 -0
- package/dist/cjs/hcs-10/sdk.d.ts.map +1 -1
- package/dist/cjs/hcs-11/client.d.ts +2 -2
- package/dist/cjs/hcs-11/client.d.ts.map +1 -1
- package/dist/cjs/hcs-11/person-builder.d.ts +1 -0
- package/dist/cjs/hcs-11/person-builder.d.ts.map +1 -1
- package/dist/cjs/hcs-11/types.d.ts +1 -0
- package/dist/cjs/hcs-11/types.d.ts.map +1 -1
- package/dist/cjs/hcs-12/rendering/resource-manager.d.ts.map +1 -1
- package/dist/cjs/hcs-14/issuers/hiero.d.ts.map +1 -1
- package/dist/cjs/hcs-15/browser.d.ts +2 -0
- package/dist/cjs/hcs-15/browser.d.ts.map +1 -1
- package/dist/cjs/hcs-15/sdk.d.ts +7 -1
- package/dist/cjs/hcs-15/sdk.d.ts.map +1 -1
- package/dist/cjs/hcs-15/tx.d.ts +4 -0
- package/dist/cjs/hcs-15/tx.d.ts.map +1 -1
- package/dist/cjs/hcs-15/types.d.ts +16 -1
- package/dist/cjs/hcs-15/types.d.ts.map +1 -1
- package/dist/cjs/hcs-16/browser.d.ts +11 -2
- package/dist/cjs/hcs-16/browser.d.ts.map +1 -1
- package/dist/cjs/hcs-16/sdk.d.ts +62 -1
- package/dist/cjs/hcs-16/sdk.d.ts.map +1 -1
- package/dist/cjs/hcs-16/tx.d.ts +21 -3
- package/dist/cjs/hcs-16/tx.d.ts.map +1 -1
- package/dist/cjs/hcs-17/base-client.d.ts +1 -0
- package/dist/cjs/hcs-17/base-client.d.ts.map +1 -1
- package/dist/cjs/hcs-17/sdk.d.ts.map +1 -1
- package/dist/cjs/hcs-17/tx.d.ts +2 -0
- package/dist/cjs/hcs-17/tx.d.ts.map +1 -1
- package/dist/cjs/hcs-17/types.d.ts +4 -0
- package/dist/cjs/hcs-17/types.d.ts.map +1 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/client/base-client.d.ts +14 -1
- package/dist/cjs/services/registry-broker/client/base-client.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/client/feedback.d.ts +2 -0
- package/dist/cjs/services/registry-broker/client/feedback.d.ts.map +1 -0
- package/dist/cjs/services/registry-broker/private-key-signer.d.ts +1 -0
- package/dist/cjs/services/registry-broker/private-key-signer.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/schemas.d.ts +998 -577
- package/dist/cjs/services/registry-broker/schemas.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/types.d.ts +20 -1
- package/dist/cjs/services/registry-broker/types.d.ts.map +1 -1
- package/dist/cjs/standards-sdk.cjs +2 -2
- package/dist/cjs/standards-sdk.cjs.map +1 -1
- package/dist/cjs/utils/crypto-abstraction.d.ts.map +1 -1
- package/dist/cjs/utils/crypto-env.d.ts.map +1 -1
- package/dist/cjs/utils/dynamic-import.d.ts +5 -1
- package/dist/cjs/utils/dynamic-import.d.ts.map +1 -1
- package/dist/cjs/utils/hash-adapter.d.ts.map +1 -1
- package/dist/es/hcs-10/base-client.d.ts.map +1 -1
- package/dist/es/hcs-10/sdk.d.ts +8 -0
- package/dist/es/hcs-10/sdk.d.ts.map +1 -1
- package/dist/es/hcs-11/client.d.ts +2 -2
- package/dist/es/hcs-11/client.d.ts.map +1 -1
- package/dist/es/hcs-11/person-builder.d.ts +1 -0
- package/dist/es/hcs-11/person-builder.d.ts.map +1 -1
- package/dist/es/hcs-11/types.d.ts +1 -0
- package/dist/es/hcs-11/types.d.ts.map +1 -1
- package/dist/es/hcs-12/rendering/resource-manager.d.ts.map +1 -1
- package/dist/es/hcs-14/issuers/hiero.d.ts.map +1 -1
- package/dist/es/hcs-15/browser.d.ts +2 -0
- package/dist/es/hcs-15/browser.d.ts.map +1 -1
- package/dist/es/hcs-15/sdk.d.ts +7 -1
- package/dist/es/hcs-15/sdk.d.ts.map +1 -1
- package/dist/es/hcs-15/tx.d.ts +4 -0
- package/dist/es/hcs-15/tx.d.ts.map +1 -1
- package/dist/es/hcs-15/types.d.ts +16 -1
- package/dist/es/hcs-15/types.d.ts.map +1 -1
- package/dist/es/hcs-16/browser.d.ts +11 -2
- package/dist/es/hcs-16/browser.d.ts.map +1 -1
- package/dist/es/hcs-16/sdk.d.ts +62 -1
- package/dist/es/hcs-16/sdk.d.ts.map +1 -1
- package/dist/es/hcs-16/tx.d.ts +21 -3
- package/dist/es/hcs-16/tx.d.ts.map +1 -1
- package/dist/es/hcs-17/base-client.d.ts +1 -0
- package/dist/es/hcs-17/base-client.d.ts.map +1 -1
- package/dist/es/hcs-17/sdk.d.ts.map +1 -1
- package/dist/es/hcs-17/tx.d.ts +2 -0
- package/dist/es/hcs-17/tx.d.ts.map +1 -1
- package/dist/es/hcs-17/types.d.ts +4 -0
- package/dist/es/hcs-17/types.d.ts.map +1 -1
- package/dist/es/index.d.ts.map +1 -1
- package/dist/es/services/registry-broker/client/base-client.d.ts +14 -1
- package/dist/es/services/registry-broker/client/base-client.d.ts.map +1 -1
- package/dist/es/services/registry-broker/client/feedback.d.ts +2 -0
- package/dist/es/services/registry-broker/client/feedback.d.ts.map +1 -0
- package/dist/es/services/registry-broker/private-key-signer.d.ts +1 -0
- package/dist/es/services/registry-broker/private-key-signer.d.ts.map +1 -1
- package/dist/es/services/registry-broker/schemas.d.ts +998 -577
- package/dist/es/services/registry-broker/schemas.d.ts.map +1 -1
- package/dist/es/services/registry-broker/types.d.ts +20 -1
- package/dist/es/services/registry-broker/types.d.ts.map +1 -1
- package/dist/es/standards-sdk.es.js +141 -135
- package/dist/es/standards-sdk.es.js.map +1 -1
- package/dist/es/standards-sdk.es10.js +70 -90
- package/dist/es/standards-sdk.es10.js.map +1 -1
- package/dist/es/standards-sdk.es100.js +229 -26
- package/dist/es/standards-sdk.es100.js.map +1 -1
- package/dist/es/standards-sdk.es101.js +109 -228
- package/dist/es/standards-sdk.es101.js.map +1 -1
- package/dist/es/standards-sdk.es102.js +15 -94
- package/dist/es/standards-sdk.es102.js.map +1 -1
- package/dist/es/standards-sdk.es103.js +80 -30
- package/dist/es/standards-sdk.es103.js.map +1 -1
- package/dist/es/standards-sdk.es104.js +27 -80
- package/dist/es/standards-sdk.es104.js.map +1 -1
- package/dist/es/standards-sdk.es105.js +136 -25
- package/dist/es/standards-sdk.es105.js.map +1 -1
- package/dist/es/standards-sdk.es106.js +27 -140
- package/dist/es/standards-sdk.es106.js.map +1 -1
- package/dist/es/standards-sdk.es107.js +20 -27
- package/dist/es/standards-sdk.es107.js.map +1 -1
- package/dist/es/standards-sdk.es108.js +156 -18
- package/dist/es/standards-sdk.es108.js.map +1 -1
- package/dist/es/standards-sdk.es109.js +198 -148
- package/dist/es/standards-sdk.es109.js.map +1 -1
- package/dist/es/standards-sdk.es11.js +121 -45
- package/dist/es/standards-sdk.es11.js.map +1 -1
- package/dist/es/standards-sdk.es110.js +747 -166
- package/dist/es/standards-sdk.es110.js.map +1 -1
- package/dist/es/standards-sdk.es111.js +9 -786
- package/dist/es/standards-sdk.es111.js.map +1 -1
- package/dist/es/standards-sdk.es112.js +567 -13
- package/dist/es/standards-sdk.es112.js.map +1 -1
- package/dist/es/standards-sdk.es113.js +576 -541
- package/dist/es/standards-sdk.es113.js.map +1 -1
- package/dist/es/standards-sdk.es114.js +12 -601
- package/dist/es/standards-sdk.es114.js.map +1 -1
- package/dist/es/standards-sdk.es115.js +2 -13
- package/dist/es/standards-sdk.es115.js.map +1 -1
- package/dist/es/standards-sdk.es116.js +87 -2
- package/dist/es/standards-sdk.es116.js.map +1 -1
- package/dist/es/standards-sdk.es117.js +37 -80
- package/dist/es/standards-sdk.es117.js.map +1 -1
- package/dist/es/standards-sdk.es118.js +2 -39
- package/dist/es/standards-sdk.es118.js.map +1 -1
- package/dist/es/standards-sdk.es119.js +231 -2
- package/dist/es/standards-sdk.es119.js.map +1 -1
- package/dist/es/standards-sdk.es12.js +60 -159
- package/dist/es/standards-sdk.es12.js.map +1 -1
- package/dist/es/standards-sdk.es120.js +1110 -193
- package/dist/es/standards-sdk.es120.js.map +1 -1
- package/dist/es/standards-sdk.es121.js +225 -1059
- package/dist/es/standards-sdk.es121.js.map +1 -1
- package/dist/es/standards-sdk.es122.js +419 -303
- package/dist/es/standards-sdk.es122.js.map +1 -1
- package/dist/es/standards-sdk.es123.js +351 -418
- package/dist/es/standards-sdk.es123.js.map +1 -1
- package/dist/es/standards-sdk.es124.js +872 -347
- package/dist/es/standards-sdk.es124.js.map +1 -1
- package/dist/es/standards-sdk.es125.js +182 -854
- package/dist/es/standards-sdk.es125.js.map +1 -1
- package/dist/es/standards-sdk.es126.js +1512 -153
- package/dist/es/standards-sdk.es126.js.map +1 -1
- package/dist/es/standards-sdk.es127.js +157 -1547
- package/dist/es/standards-sdk.es127.js.map +1 -1
- package/dist/es/standards-sdk.es128.js +192 -162
- package/dist/es/standards-sdk.es128.js.map +1 -1
- package/dist/es/standards-sdk.es129.js +61 -164
- package/dist/es/standards-sdk.es129.js.map +1 -1
- package/dist/es/standards-sdk.es13.js +200 -60
- package/dist/es/standards-sdk.es13.js.map +1 -1
- package/dist/es/standards-sdk.es130.js +102 -85
- package/dist/es/standards-sdk.es130.js.map +1 -1
- package/dist/es/standards-sdk.es131.js +222 -96
- package/dist/es/standards-sdk.es131.js.map +1 -1
- package/dist/es/standards-sdk.es132.js +153 -220
- package/dist/es/standards-sdk.es132.js.map +1 -1
- package/dist/es/standards-sdk.es133.js +104 -162
- package/dist/es/standards-sdk.es133.js.map +1 -1
- package/dist/es/standards-sdk.es134.js +296 -92
- package/dist/es/standards-sdk.es134.js.map +1 -1
- package/dist/es/standards-sdk.es135.js +432 -294
- package/dist/es/standards-sdk.es135.js.map +1 -1
- package/dist/es/standards-sdk.es136.js +14 -363
- package/dist/es/standards-sdk.es136.js.map +1 -1
- package/dist/es/standards-sdk.es137.js +79 -15
- package/dist/es/standards-sdk.es137.js.map +1 -1
- package/dist/es/standards-sdk.es138.js +79 -59
- package/dist/es/standards-sdk.es138.js.map +1 -1
- package/dist/es/standards-sdk.es139.js +152 -80
- package/dist/es/standards-sdk.es139.js.map +1 -1
- package/dist/es/standards-sdk.es14.js +149 -178
- package/dist/es/standards-sdk.es14.js.map +1 -1
- package/dist/es/standards-sdk.es140.js +7 -159
- package/dist/es/standards-sdk.es140.js.map +1 -1
- package/dist/es/standards-sdk.es141.js +86 -7
- package/dist/es/standards-sdk.es141.js.map +1 -1
- package/dist/es/standards-sdk.es142.js +44 -65
- package/dist/es/standards-sdk.es142.js.map +1 -1
- package/dist/es/standards-sdk.es143.js +30 -65
- package/dist/es/standards-sdk.es143.js.map +1 -1
- package/dist/es/standards-sdk.es144.js +34 -28
- package/dist/es/standards-sdk.es144.js.map +1 -1
- package/dist/es/standards-sdk.es145.js +28 -138
- package/dist/es/standards-sdk.es145.js.map +1 -1
- package/dist/es/standards-sdk.es146.js +133 -37
- package/dist/es/standards-sdk.es146.js.map +1 -1
- package/dist/es/standards-sdk.es147.js +34 -12281
- package/dist/es/standards-sdk.es147.js.map +1 -1
- package/dist/es/standards-sdk.es148.js +12284 -12
- package/dist/es/standards-sdk.es148.js.map +1 -1
- package/dist/es/standards-sdk.es149.js +958 -56
- package/dist/es/standards-sdk.es149.js.map +1 -1
- package/dist/es/standards-sdk.es15.js +152 -151
- package/dist/es/standards-sdk.es15.js.map +1 -1
- package/dist/es/standards-sdk.es150.js +48 -74
- package/dist/es/standards-sdk.es150.js.map +1 -1
- package/dist/es/standards-sdk.es151.js +72 -160
- package/dist/es/standards-sdk.es151.js.map +1 -1
- package/dist/es/standards-sdk.es152.js +13 -318
- package/dist/es/standards-sdk.es152.js.map +1 -1
- package/dist/es/standards-sdk.es153.js +120 -294
- package/dist/es/standards-sdk.es153.js.map +1 -1
- package/dist/es/standards-sdk.es154.js +191 -322
- package/dist/es/standards-sdk.es154.js.map +1 -1
- package/dist/es/standards-sdk.es155.js +294 -279
- package/dist/es/standards-sdk.es155.js.map +1 -1
- package/dist/es/standards-sdk.es156.js +440 -63
- package/dist/es/standards-sdk.es156.js.map +1 -1
- package/dist/es/standards-sdk.es157.js +331 -871
- package/dist/es/standards-sdk.es157.js.map +1 -1
- package/dist/es/standards-sdk.es158.js +68 -231
- package/dist/es/standards-sdk.es158.js.map +1 -1
- package/dist/es/standards-sdk.es159.js +218 -223
- package/dist/es/standards-sdk.es159.js.map +1 -1
- package/dist/es/standards-sdk.es16.js +917 -136
- package/dist/es/standards-sdk.es16.js.map +1 -1
- package/dist/es/standards-sdk.es160.js +247 -0
- package/dist/es/standards-sdk.es160.js.map +1 -0
- package/dist/es/standards-sdk.es17.js +23 -944
- package/dist/es/standards-sdk.es17.js.map +1 -1
- package/dist/es/standards-sdk.es18.js +2422 -24
- package/dist/es/standards-sdk.es18.js.map +1 -1
- package/dist/es/standards-sdk.es19.js +817 -2071
- package/dist/es/standards-sdk.es19.js.map +1 -1
- package/dist/es/standards-sdk.es2.js +654 -189
- package/dist/es/standards-sdk.es2.js.map +1 -1
- package/dist/es/standards-sdk.es20.js +205 -1091
- package/dist/es/standards-sdk.es20.js.map +1 -1
- package/dist/es/standards-sdk.es21.js +858 -221
- package/dist/es/standards-sdk.es21.js.map +1 -1
- package/dist/es/standards-sdk.es22.js +179 -903
- package/dist/es/standards-sdk.es22.js.map +1 -1
- package/dist/es/standards-sdk.es23.js +164 -179
- package/dist/es/standards-sdk.es23.js.map +1 -1
- package/dist/es/standards-sdk.es24.js +62 -118
- package/dist/es/standards-sdk.es24.js.map +1 -1
- package/dist/es/standards-sdk.es25.js +377 -52
- package/dist/es/standards-sdk.es25.js.map +1 -1
- package/dist/es/standards-sdk.es26.js +36 -394
- package/dist/es/standards-sdk.es26.js.map +1 -1
- package/dist/es/standards-sdk.es27.js +901 -50
- package/dist/es/standards-sdk.es27.js.map +1 -1
- package/dist/es/standards-sdk.es28.js +134 -902
- package/dist/es/standards-sdk.es28.js.map +1 -1
- package/dist/es/standards-sdk.es29.js +7 -134
- package/dist/es/standards-sdk.es29.js.map +1 -1
- package/dist/es/standards-sdk.es3.js +63 -680
- package/dist/es/standards-sdk.es3.js.map +1 -1
- package/dist/es/standards-sdk.es30.js +344 -7
- package/dist/es/standards-sdk.es30.js.map +1 -1
- package/dist/es/standards-sdk.es31.js +302 -287
- package/dist/es/standards-sdk.es31.js.map +1 -1
- package/dist/es/standards-sdk.es32.js +94 -322
- package/dist/es/standards-sdk.es32.js.map +1 -1
- package/dist/es/standards-sdk.es33.js +458 -101
- package/dist/es/standards-sdk.es33.js.map +1 -1
- package/dist/es/standards-sdk.es34.js +132 -451
- package/dist/es/standards-sdk.es34.js.map +1 -1
- package/dist/es/standards-sdk.es35.js +216 -130
- package/dist/es/standards-sdk.es35.js.map +1 -1
- package/dist/es/standards-sdk.es36.js +273 -195
- package/dist/es/standards-sdk.es36.js.map +1 -1
- package/dist/es/standards-sdk.es37.js +148 -87
- package/dist/es/standards-sdk.es37.js.map +1 -1
- package/dist/es/standards-sdk.es38.js +183 -320
- package/dist/es/standards-sdk.es38.js.map +1 -1
- package/dist/es/standards-sdk.es39.js +238 -161
- package/dist/es/standards-sdk.es39.js.map +1 -1
- package/dist/es/standards-sdk.es4.js +425 -63
- package/dist/es/standards-sdk.es4.js.map +1 -1
- package/dist/es/standards-sdk.es40.js +136 -254
- package/dist/es/standards-sdk.es40.js.map +1 -1
- package/dist/es/standards-sdk.es41.js +225 -176
- package/dist/es/standards-sdk.es41.js.map +1 -1
- package/dist/es/standards-sdk.es42.js +199 -261
- package/dist/es/standards-sdk.es42.js.map +1 -1
- package/dist/es/standards-sdk.es43.js +237 -199
- package/dist/es/standards-sdk.es43.js.map +1 -1
- package/dist/es/standards-sdk.es44.js +209 -201
- package/dist/es/standards-sdk.es44.js.map +1 -1
- package/dist/es/standards-sdk.es45.js +305 -201
- package/dist/es/standards-sdk.es45.js.map +1 -1
- package/dist/es/standards-sdk.es46.js +371 -261
- package/dist/es/standards-sdk.es46.js.map +1 -1
- package/dist/es/standards-sdk.es47.js +316 -371
- package/dist/es/standards-sdk.es47.js.map +1 -1
- package/dist/es/standards-sdk.es48.js +404 -336
- package/dist/es/standards-sdk.es48.js.map +1 -1
- package/dist/es/standards-sdk.es49.js +83 -449
- package/dist/es/standards-sdk.es49.js.map +1 -1
- package/dist/es/standards-sdk.es5.js +232 -354
- package/dist/es/standards-sdk.es5.js.map +1 -1
- package/dist/es/standards-sdk.es50.js +179 -89
- package/dist/es/standards-sdk.es50.js.map +1 -1
- package/dist/es/standards-sdk.es51.js +231 -165
- package/dist/es/standards-sdk.es51.js.map +1 -1
- package/dist/es/standards-sdk.es52.js +25 -262
- package/dist/es/standards-sdk.es52.js.map +1 -1
- package/dist/es/standards-sdk.es53.js +56 -26
- package/dist/es/standards-sdk.es53.js.map +1 -1
- package/dist/es/standards-sdk.es54.js +12 -57
- package/dist/es/standards-sdk.es54.js.map +1 -1
- package/dist/es/standards-sdk.es55.js +49 -12
- package/dist/es/standards-sdk.es55.js.map +1 -1
- package/dist/es/standards-sdk.es56.js +115 -43
- package/dist/es/standards-sdk.es56.js.map +1 -1
- package/dist/es/standards-sdk.es57.js +42 -115
- package/dist/es/standards-sdk.es57.js.map +1 -1
- package/dist/es/standards-sdk.es58.js +52 -43
- package/dist/es/standards-sdk.es58.js.map +1 -1
- package/dist/es/standards-sdk.es59.js +36 -50
- package/dist/es/standards-sdk.es59.js.map +1 -1
- package/dist/es/standards-sdk.es6.js +125 -246
- package/dist/es/standards-sdk.es6.js.map +1 -1
- package/dist/es/standards-sdk.es60.js +207 -39
- package/dist/es/standards-sdk.es60.js.map +1 -1
- package/dist/es/standards-sdk.es61.js +24 -200
- package/dist/es/standards-sdk.es61.js.map +1 -1
- package/dist/es/standards-sdk.es62.js +87 -25
- package/dist/es/standards-sdk.es62.js.map +1 -1
- package/dist/es/standards-sdk.es63.js +3 -51
- package/dist/es/standards-sdk.es63.js.map +1 -1
- package/dist/es/standards-sdk.es64.js +100 -3
- package/dist/es/standards-sdk.es64.js.map +1 -1
- package/dist/es/standards-sdk.es65.js +61 -62
- package/dist/es/standards-sdk.es65.js.map +1 -1
- package/dist/es/standards-sdk.es66.js +17 -98
- package/dist/es/standards-sdk.es66.js.map +1 -1
- package/dist/es/standards-sdk.es67.js +77 -19
- package/dist/es/standards-sdk.es67.js.map +1 -1
- package/dist/es/standards-sdk.es68.js +458 -77
- package/dist/es/standards-sdk.es68.js.map +1 -1
- package/dist/es/standards-sdk.es69.js +106 -240
- package/dist/es/standards-sdk.es69.js.map +1 -1
- package/dist/es/standards-sdk.es7.js +28 -183
- package/dist/es/standards-sdk.es7.js.map +1 -1
- package/dist/es/standards-sdk.es70.js +170 -286
- package/dist/es/standards-sdk.es70.js.map +1 -1
- package/dist/es/standards-sdk.es71.js +71 -207
- package/dist/es/standards-sdk.es71.js.map +1 -1
- package/dist/es/standards-sdk.es72.js +71 -72
- package/dist/es/standards-sdk.es72.js.map +1 -1
- package/dist/es/standards-sdk.es73.js +143 -71
- package/dist/es/standards-sdk.es73.js.map +1 -1
- package/dist/es/standards-sdk.es74.js +62 -136
- package/dist/es/standards-sdk.es74.js.map +1 -1
- package/dist/es/standards-sdk.es75.js +380 -45
- package/dist/es/standards-sdk.es75.js.map +1 -1
- package/dist/es/standards-sdk.es76.js +222 -130
- package/dist/es/standards-sdk.es76.js.map +1 -1
- package/dist/es/standards-sdk.es77.js +320 -444
- package/dist/es/standards-sdk.es77.js.map +1 -1
- package/dist/es/standards-sdk.es78.js +88 -370
- package/dist/es/standards-sdk.es78.js.map +1 -1
- package/dist/es/standards-sdk.es79.js +125 -89
- package/dist/es/standards-sdk.es79.js.map +1 -1
- package/dist/es/standards-sdk.es8.js +80 -29
- package/dist/es/standards-sdk.es8.js.map +1 -1
- package/dist/es/standards-sdk.es80.js +8 -125
- package/dist/es/standards-sdk.es80.js.map +1 -1
- package/dist/es/standards-sdk.es81.js +45 -6
- package/dist/es/standards-sdk.es81.js.map +1 -1
- package/dist/es/standards-sdk.es82.js +98 -44
- package/dist/es/standards-sdk.es82.js.map +1 -1
- package/dist/es/standards-sdk.es83.js +331 -84
- package/dist/es/standards-sdk.es83.js.map +1 -1
- package/dist/es/standards-sdk.es84.js +93 -160
- package/dist/es/standards-sdk.es84.js.map +1 -1
- package/dist/es/standards-sdk.es85.js +55 -275
- package/dist/es/standards-sdk.es85.js.map +1 -1
- package/dist/es/standards-sdk.es86.js +43 -55
- package/dist/es/standards-sdk.es86.js.map +1 -1
- package/dist/es/standards-sdk.es87.js +145 -22
- package/dist/es/standards-sdk.es87.js.map +1 -1
- package/dist/es/standards-sdk.es88.js +34 -47
- package/dist/es/standards-sdk.es88.js.map +1 -1
- package/dist/es/standards-sdk.es89.js +22 -57
- package/dist/es/standards-sdk.es89.js.map +1 -1
- package/dist/es/standards-sdk.es9.js +104 -80
- package/dist/es/standards-sdk.es9.js.map +1 -1
- package/dist/es/standards-sdk.es90.js +23 -28
- package/dist/es/standards-sdk.es90.js.map +1 -1
- package/dist/es/standards-sdk.es91.js +238 -23
- package/dist/es/standards-sdk.es91.js.map +1 -1
- package/dist/es/standards-sdk.es92.js +265 -152
- package/dist/es/standards-sdk.es92.js.map +1 -1
- package/dist/es/standards-sdk.es93.js +95 -68
- package/dist/es/standards-sdk.es93.js.map +1 -1
- package/dist/es/standards-sdk.es94.js +124 -136
- package/dist/es/standards-sdk.es94.js.map +1 -1
- package/dist/es/standards-sdk.es95.js +42 -138
- package/dist/es/standards-sdk.es95.js.map +1 -1
- package/dist/es/standards-sdk.es96.js +259 -42
- package/dist/es/standards-sdk.es96.js.map +1 -1
- package/dist/es/standards-sdk.es97.js +82 -243
- package/dist/es/standards-sdk.es97.js.map +1 -1
- package/dist/es/standards-sdk.es98.js +48 -47
- package/dist/es/standards-sdk.es98.js.map +1 -1
- package/dist/es/standards-sdk.es99.js +29 -100
- package/dist/es/standards-sdk.es99.js.map +1 -1
- package/dist/es/utils/crypto-abstraction.d.ts.map +1 -1
- package/dist/es/utils/crypto-env.d.ts.map +1 -1
- package/dist/es/utils/dynamic-import.d.ts +5 -1
- package/dist/es/utils/dynamic-import.d.ts.map +1 -1
- package/dist/es/utils/hash-adapter.d.ts.map +1 -1
- package/package.json +8 -7
- package/dist/cjs/patches/topic-autorenew-patch.d.ts +0 -2
- package/dist/cjs/patches/topic-autorenew-patch.d.ts.map +0 -1
- package/dist/es/patches/topic-autorenew-patch.d.ts +0 -2
- package/dist/es/patches/topic-autorenew-patch.d.ts.map +0 -1
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import {
|
|
3
|
-
import { AccountCreationError, TopicCreationError, ConnectionConfirmationError, PayloadSizeError } from "./standards-sdk.es18.js";
|
|
4
|
-
import { InscriptionSDK } from "./standards-sdk.es147.js";
|
|
5
|
-
import { Logger } from "./standards-sdk.es106.js";
|
|
6
|
-
import { accountIdsToExemptKeys } from "./standards-sdk.es108.js";
|
|
7
|
-
import { ProgressReporter } from "./standards-sdk.es109.js";
|
|
1
|
+
import { KeyList, TopicCreateTransaction, AccountId, Transaction, TopicMessageSubmitTransaction, Hbar } from "@hashgraph/sdk";
|
|
2
|
+
import { Logger } from "./standards-sdk.es105.js";
|
|
8
3
|
import "axios";
|
|
9
4
|
import "@hashgraph/proto";
|
|
5
|
+
import { ProgressReporter } from "./standards-sdk.es108.js";
|
|
6
|
+
import "./standards-sdk.es127.js";
|
|
10
7
|
import "./standards-sdk.es128.js";
|
|
11
8
|
import "./standards-sdk.es129.js";
|
|
12
9
|
import "./standards-sdk.es130.js";
|
|
@@ -14,27 +11,24 @@ import "./standards-sdk.es131.js";
|
|
|
14
11
|
import "./standards-sdk.es132.js";
|
|
15
12
|
import "./standards-sdk.es133.js";
|
|
16
13
|
import "./standards-sdk.es134.js";
|
|
17
|
-
import "./standards-sdk.es135.js";
|
|
18
14
|
import "buffer";
|
|
19
15
|
import "crypto";
|
|
20
16
|
import "@noble/curves/secp256k1.js";
|
|
21
17
|
import "zod";
|
|
22
|
-
import "./standards-sdk.
|
|
18
|
+
import "./standards-sdk.es149.js";
|
|
19
|
+
import "./standards-sdk.es138.js";
|
|
23
20
|
import "ethers";
|
|
24
|
-
import "./standards-sdk.
|
|
25
|
-
import
|
|
26
|
-
import { getTopicId } from "./standards-sdk.
|
|
27
|
-
import {
|
|
28
|
-
import { HCS10BaseClient, Hcs10MemoType } from "./standards-sdk.
|
|
21
|
+
import "./standards-sdk.es122.js";
|
|
22
|
+
import "./standards-sdk.es113.js";
|
|
23
|
+
import { getTopicId } from "./standards-sdk.es114.js";
|
|
24
|
+
import { InscriptionSDK } from "./standards-sdk.es148.js";
|
|
25
|
+
import { HCS10BaseClient, Hcs10MemoType } from "./standards-sdk.es16.js";
|
|
29
26
|
import * as mime from "mime-types";
|
|
30
|
-
import { AgentBuilder } from "./standards-sdk.
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
import { buildTopicCreateTx, buildMessageTx } from "./standards-sdk.es146.js";
|
|
36
|
-
import { buildHcs10CreateInboundTopicTx, buildHcs10CreateConnectionTopicTx, buildHcs10ConfirmConnectionTx, buildHcs10SendMessageTx, buildHcs10RegistryRegisterTx, buildHcs10CreateOutboundTopicTx, buildHcs10CreateRegistryTopicTx } from "./standards-sdk.es23.js";
|
|
37
|
-
class HCS10Client extends HCS10BaseClient {
|
|
27
|
+
import { AgentBuilder } from "./standards-sdk.es23.js";
|
|
28
|
+
import { HCS11Client } from "./standards-sdk.es27.js";
|
|
29
|
+
import { inscribeWithSigner } from "./standards-sdk.es124.js";
|
|
30
|
+
const isBrowser = typeof window !== "undefined";
|
|
31
|
+
class BrowserHCSClient extends HCS10BaseClient {
|
|
38
32
|
constructor(config) {
|
|
39
33
|
super({
|
|
40
34
|
network: config.network,
|
|
@@ -42,237 +36,194 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
42
36
|
prettyPrint: config.prettyPrint,
|
|
43
37
|
feeAmount: config.feeAmount,
|
|
44
38
|
mirrorNode: config.mirrorNode,
|
|
45
|
-
silent: config.silent
|
|
46
|
-
keyType: config.keyType
|
|
39
|
+
silent: config.silent
|
|
47
40
|
});
|
|
41
|
+
this.hcs11Client = null;
|
|
42
|
+
this.hwc = config.hwc;
|
|
43
|
+
if (!config.guardedRegistryBaseUrl) {
|
|
44
|
+
this.guardedRegistryBaseUrl = "https://moonscape.tech";
|
|
45
|
+
} else {
|
|
46
|
+
this.guardedRegistryBaseUrl = config.guardedRegistryBaseUrl;
|
|
47
|
+
}
|
|
48
|
+
let logLevel;
|
|
49
|
+
if (config.logLevel) {
|
|
50
|
+
logLevel = config.logLevel;
|
|
51
|
+
} else {
|
|
52
|
+
logLevel = "info";
|
|
53
|
+
}
|
|
48
54
|
this.logger = Logger.getInstance({
|
|
49
|
-
level:
|
|
50
|
-
module: "HCS-
|
|
55
|
+
level: logLevel,
|
|
56
|
+
module: "HCS-Browser",
|
|
57
|
+
prettyPrint: config.prettyPrint,
|
|
51
58
|
silent: config.silent
|
|
52
59
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
silent: config.silent,
|
|
74
|
-
keyType: config.keyType
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
async ensureInitialized() {
|
|
78
|
-
await this.operatorCtx.ensureInitialized();
|
|
79
|
-
}
|
|
80
|
-
getClient() {
|
|
81
|
-
return this.client;
|
|
60
|
+
if (isBrowser) {
|
|
61
|
+
try {
|
|
62
|
+
const { accountId, signer } = this.getAccountAndSigner();
|
|
63
|
+
this.hcs11Client = new HCS11Client({
|
|
64
|
+
network: config.network,
|
|
65
|
+
auth: {
|
|
66
|
+
operatorId: accountId,
|
|
67
|
+
signer
|
|
68
|
+
},
|
|
69
|
+
logLevel: config.logLevel,
|
|
70
|
+
silent: config.silent
|
|
71
|
+
});
|
|
72
|
+
} catch (err) {
|
|
73
|
+
this.logger.warn(`Failed to initialize HCS11Client: ${err}`);
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
this.logger.error(
|
|
77
|
+
"BrowserHCSClient initialized in server environment - browser-specific features will not be available. Use HCS10Client instead."
|
|
78
|
+
);
|
|
79
|
+
}
|
|
82
80
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
81
|
+
async sendMessage(connectionTopicId, data, memo, submitKey, options) {
|
|
82
|
+
this.logger.info("Sending message");
|
|
83
|
+
const operatorId = await this.getOperatorId();
|
|
84
|
+
const payload = {
|
|
85
|
+
p: "hcs-10",
|
|
86
|
+
op: "message",
|
|
87
|
+
operator_id: operatorId,
|
|
88
|
+
data,
|
|
89
|
+
m: memo
|
|
90
|
+
};
|
|
91
|
+
const submissionCheck = await this.canSubmitToTopic(
|
|
92
|
+
connectionTopicId,
|
|
93
|
+
this.hwc.getAccountInfo().accountId
|
|
92
94
|
);
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (!newAccountId) {
|
|
99
|
-
this.logger.error("Account creation failed: accountId is null");
|
|
100
|
-
throw new AccountCreationError(
|
|
101
|
-
"Failed to create account: accountId is null"
|
|
95
|
+
const payloadString = JSON.stringify(payload);
|
|
96
|
+
const isLargePayload = Buffer.from(payloadString).length > 1e3;
|
|
97
|
+
if (isLargePayload) {
|
|
98
|
+
this.logger.info(
|
|
99
|
+
"Message payload exceeds 1000 bytes, storing via inscription"
|
|
102
100
|
);
|
|
101
|
+
try {
|
|
102
|
+
const contentBuffer = Buffer.from(data);
|
|
103
|
+
const fileName = `message-${Date.now()}.json`;
|
|
104
|
+
const inscriptionResult = await this.inscribeFile(
|
|
105
|
+
contentBuffer,
|
|
106
|
+
fileName,
|
|
107
|
+
{
|
|
108
|
+
progressCallback: options?.progressCallback,
|
|
109
|
+
waitMaxAttempts: options?.waitMaxAttempts,
|
|
110
|
+
waitIntervalMs: options?.waitIntervalMs
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
if (getTopicId(inscriptionResult)) {
|
|
114
|
+
payload.data = `hcs://1/${getTopicId(inscriptionResult)}`;
|
|
115
|
+
this.logger.info(
|
|
116
|
+
`Large message inscribed with topic ID: ${getTopicId(inscriptionResult)}`
|
|
117
|
+
);
|
|
118
|
+
} else {
|
|
119
|
+
throw new Error("Failed to inscribe large message content");
|
|
120
|
+
}
|
|
121
|
+
} catch (error) {
|
|
122
|
+
this.logger.error("Error inscribing large message:", error);
|
|
123
|
+
throw new Error(
|
|
124
|
+
`Failed to handle large message: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
103
127
|
}
|
|
104
|
-
this.
|
|
105
|
-
|
|
128
|
+
return await this.submitPayload(
|
|
129
|
+
connectionTopicId,
|
|
130
|
+
payload,
|
|
131
|
+
submitKey,
|
|
132
|
+
submissionCheck.requiresFee
|
|
106
133
|
);
|
|
107
|
-
return {
|
|
108
|
-
accountId: newAccountId.toString(),
|
|
109
|
-
privateKey: newKey.toString()
|
|
110
|
-
};
|
|
111
134
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
async createInboundTopic(accountId, topicType, ttl = 60, feeConfigBuilder) {
|
|
121
|
-
await this.ensureInitialized();
|
|
122
|
-
this._generateHcs10Memo(Hcs10MemoType.INBOUND, {
|
|
123
|
-
accountId,
|
|
124
|
-
ttl
|
|
125
|
-
});
|
|
126
|
-
let submitKey;
|
|
127
|
-
let finalFeeConfig;
|
|
128
|
-
switch (topicType) {
|
|
129
|
-
case InboundTopicType.PUBLIC:
|
|
130
|
-
submitKey = false;
|
|
131
|
-
break;
|
|
132
|
-
case InboundTopicType.CONTROLLED:
|
|
133
|
-
submitKey = true;
|
|
134
|
-
break;
|
|
135
|
-
case InboundTopicType.FEE_BASED:
|
|
136
|
-
submitKey = false;
|
|
137
|
-
if (!feeConfigBuilder) {
|
|
138
|
-
throw new Error(
|
|
139
|
-
"Fee configuration builder is required for fee-based topics"
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
const internalFees = feeConfigBuilder.customFees;
|
|
143
|
-
internalFees.forEach((fee) => {
|
|
144
|
-
if (!fee.feeCollectorAccountId) {
|
|
145
|
-
fee.feeCollectorAccountId = accountId;
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
finalFeeConfig = feeConfigBuilder.build();
|
|
149
|
-
finalFeeConfig.customFees = finalFeeConfig.customFees.map((f) => ({
|
|
150
|
-
...f,
|
|
151
|
-
feeCollectorAccountId: f.feeCollectorAccountId || accountId
|
|
152
|
-
}));
|
|
153
|
-
break;
|
|
154
|
-
default:
|
|
155
|
-
throw new Error(`Unsupported inbound topic type: ${topicType}`);
|
|
135
|
+
async getPublicKey(accountId) {
|
|
136
|
+
return await this.mirrorNode.getPublicKey(accountId);
|
|
137
|
+
}
|
|
138
|
+
async handleConnectionRequest(inboundTopicId, requestingAccountId, connectionId, connectionMemo = "Connection accepted. Looking forward to collaborating!", ttl = 60) {
|
|
139
|
+
this.logger.info("Handling connection request");
|
|
140
|
+
const userAccountId = this.hwc.getAccountInfo().accountId;
|
|
141
|
+
if (!userAccountId) {
|
|
142
|
+
throw new Error("Failed to retrieve user account ID");
|
|
156
143
|
}
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
|
|
144
|
+
const requesterKey = await this.mirrorNode.getPublicKey(requestingAccountId);
|
|
145
|
+
const accountKey = await this.mirrorNode.getPublicKey(userAccountId);
|
|
146
|
+
if (!accountKey) {
|
|
147
|
+
throw new Error("Failed to retrieve public key");
|
|
148
|
+
}
|
|
149
|
+
const thresholdKey = new KeyList([accountKey, requesterKey], 1);
|
|
150
|
+
const memo = this._generateHcs10Memo(Hcs10MemoType.CONNECTION, {
|
|
160
151
|
ttl,
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
operatorPublicKey
|
|
152
|
+
inboundTopicId,
|
|
153
|
+
connectionId
|
|
164
154
|
});
|
|
165
|
-
|
|
166
|
-
|
|
155
|
+
const transaction = new TopicCreateTransaction().setTopicMemo(memo).setAutoRenewAccountId(AccountId.fromString(userAccountId)).setAdminKey(thresholdKey).setSubmitKey(thresholdKey);
|
|
156
|
+
this.logger.debug("Executing topic creation transaction");
|
|
157
|
+
const txResponse = await this.hwc.executeTransactionWithErrorHandling(
|
|
167
158
|
transaction,
|
|
168
|
-
|
|
159
|
+
false
|
|
160
|
+
);
|
|
161
|
+
if (txResponse?.error) {
|
|
162
|
+
this.logger.error(txResponse.error);
|
|
163
|
+
throw new Error(txResponse.error);
|
|
164
|
+
}
|
|
165
|
+
const resultReceipt = txResponse?.result;
|
|
166
|
+
if (!resultReceipt?.topicId) {
|
|
167
|
+
this.logger.error("Failed to create topic: topicId is null");
|
|
168
|
+
throw new Error("Failed to create topic: topicId is null");
|
|
169
|
+
}
|
|
170
|
+
const connectionTopicId = resultReceipt.topicId.toString();
|
|
171
|
+
const operatorId = `${inboundTopicId}@${userAccountId}`;
|
|
172
|
+
const confirmedConnectionSequenceNumber = await this.confirmConnection(
|
|
173
|
+
inboundTopicId,
|
|
174
|
+
connectionTopicId,
|
|
175
|
+
requestingAccountId,
|
|
176
|
+
connectionId,
|
|
177
|
+
operatorId,
|
|
178
|
+
connectionMemo
|
|
179
|
+
);
|
|
180
|
+
const accountTopics = await this.retrieveCommunicationTopics(userAccountId);
|
|
181
|
+
const requestingAccountTopics = await this.retrieveCommunicationTopics(requestingAccountId);
|
|
182
|
+
const requestingAccountOperatorId = `${requestingAccountTopics.inboundTopic}@${requestingAccountId}`;
|
|
183
|
+
await this.recordOutboundConnectionConfirmation({
|
|
184
|
+
outboundTopicId: accountTopics.outboundTopic,
|
|
185
|
+
requestorOutboundTopicId: requestingAccountTopics.outboundTopic,
|
|
186
|
+
connectionRequestId: connectionId,
|
|
187
|
+
confirmedRequestId: confirmedConnectionSequenceNumber,
|
|
188
|
+
connectionTopicId,
|
|
189
|
+
operatorId: requestingAccountOperatorId,
|
|
190
|
+
memo: `Connection established with ${requestingAccountId}`
|
|
169
191
|
});
|
|
170
|
-
return
|
|
192
|
+
return {
|
|
193
|
+
connectionTopicId,
|
|
194
|
+
confirmedConnectionSequenceNumber,
|
|
195
|
+
operatorId
|
|
196
|
+
};
|
|
171
197
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const result = await this._createEntityTopics(
|
|
187
|
-
ttl,
|
|
188
|
-
{
|
|
189
|
-
outboundTopicId: existingState?.outboundTopicId || "",
|
|
190
|
-
inboundTopicId: existingState?.inboundTopicId || "",
|
|
191
|
-
pfpTopicId: existingState?.pfpTopicId || config.existingPfpTopicId || "",
|
|
192
|
-
profileTopicId: existingState?.profileTopicId || ""
|
|
193
|
-
},
|
|
194
|
-
accountId,
|
|
195
|
-
config.inboundTopicType,
|
|
196
|
-
config.feeConfig,
|
|
197
|
-
config.pfpBuffer,
|
|
198
|
-
config.pfpFileName,
|
|
199
|
-
progressCallback
|
|
198
|
+
async confirmConnection(inboundTopicId, connectionTopicId, connectedAccountId, connectionId, operatorId, memo) {
|
|
199
|
+
this.logger.info("Confirming connection");
|
|
200
|
+
const payload = {
|
|
201
|
+
p: "hcs-10",
|
|
202
|
+
op: "connection_created",
|
|
203
|
+
connection_topic_id: connectionTopicId,
|
|
204
|
+
connected_account_id: connectedAccountId,
|
|
205
|
+
operator_id: operatorId,
|
|
206
|
+
connection_id: connectionId,
|
|
207
|
+
m: memo
|
|
208
|
+
};
|
|
209
|
+
const transactionResponse = await this.submitPayload(
|
|
210
|
+
inboundTopicId,
|
|
211
|
+
payload
|
|
200
212
|
);
|
|
201
|
-
if (!
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
stage: "preparing",
|
|
205
|
-
message: "Creating agent profile",
|
|
206
|
-
progressPercent: 60,
|
|
207
|
-
details: {
|
|
208
|
-
outboundTopicId: result.outboundTopicId,
|
|
209
|
-
inboundTopicId: result.inboundTopicId,
|
|
210
|
-
pfpTopicId: result.pfpTopicId,
|
|
211
|
-
state: {
|
|
212
|
-
currentStage: "profile",
|
|
213
|
-
completedPercentage: 60
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
const profileResult = await this.storeHCS11Profile(
|
|
219
|
-
config.name,
|
|
220
|
-
config.bio,
|
|
221
|
-
result.inboundTopicId,
|
|
222
|
-
result.outboundTopicId,
|
|
223
|
-
config.capabilities,
|
|
224
|
-
config.metadata,
|
|
225
|
-
config.pfpBuffer && config.pfpBuffer.length > 0 && !result.pfpTopicId ? config.pfpBuffer : void 0,
|
|
226
|
-
config.pfpFileName,
|
|
227
|
-
result.pfpTopicId
|
|
228
|
-
);
|
|
229
|
-
result.profileTopicId = profileResult.profileTopicId;
|
|
230
|
-
this.logger.info(
|
|
231
|
-
`Profile stored with topic ID: ${result.profileTopicId}`
|
|
232
|
-
);
|
|
233
|
-
if (progressCallback) {
|
|
234
|
-
progressCallback({
|
|
235
|
-
stage: "preparing",
|
|
236
|
-
message: "Agent profile created",
|
|
237
|
-
progressPercent: 70,
|
|
238
|
-
details: {
|
|
239
|
-
outboundTopicId: result.outboundTopicId,
|
|
240
|
-
inboundTopicId: result.inboundTopicId,
|
|
241
|
-
pfpTopicId: result.pfpTopicId,
|
|
242
|
-
profileTopicId: result.profileTopicId,
|
|
243
|
-
state: {
|
|
244
|
-
currentStage: "profile",
|
|
245
|
-
completedPercentage: 70
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
} else {
|
|
251
|
-
this.logger.info(
|
|
252
|
-
`Using existing profile topic ID: ${result.profileTopicId}`
|
|
213
|
+
if (!transactionResponse?.topicSequenceNumber) {
|
|
214
|
+
this.logger.error(
|
|
215
|
+
"Failed to confirm connection: sequence number is null"
|
|
253
216
|
);
|
|
217
|
+
throw new Error("Failed to confirm connection: sequence number is null");
|
|
254
218
|
}
|
|
255
|
-
return
|
|
219
|
+
return transactionResponse.topicSequenceNumber.toNumber();
|
|
256
220
|
}
|
|
257
|
-
/**
|
|
258
|
-
* Creates a profile (person or agent) with HCS-10 topics and HCS-11 profile.
|
|
259
|
-
* This method provides a unified interface for creating both person and agent profiles.
|
|
260
|
-
*
|
|
261
|
-
* @param builder - AgentBuilder or PersonBuilder instance
|
|
262
|
-
* @param options - Optional configuration including progress callback and state
|
|
263
|
-
* @returns Promise resolving to profile creation result
|
|
264
|
-
*/
|
|
265
221
|
async create(builder, options) {
|
|
266
222
|
const progressCallback = options?.progressCallback;
|
|
267
223
|
const progressReporter = new ProgressReporter({
|
|
268
224
|
module: "ProfileCreate",
|
|
269
225
|
logger: this.logger,
|
|
270
|
-
callback: progressCallback
|
|
271
|
-
stage: d.stage,
|
|
272
|
-
message: d.message,
|
|
273
|
-
progressPercent: d.progressPercent,
|
|
274
|
-
details: d.details
|
|
275
|
-
}) : void 0
|
|
226
|
+
callback: progressCallback
|
|
276
227
|
});
|
|
277
228
|
try {
|
|
278
229
|
const isAgentBuilder = builder instanceof AgentBuilder;
|
|
@@ -300,19 +251,11 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
300
251
|
state
|
|
301
252
|
}
|
|
302
253
|
);
|
|
303
|
-
const accountId = this.client.operatorAccountId?.toString();
|
|
304
|
-
if (!accountId) {
|
|
305
|
-
throw new Error("Failed to retrieve operator account ID");
|
|
306
|
-
}
|
|
307
254
|
const {
|
|
308
255
|
inboundTopicId,
|
|
309
256
|
outboundTopicId,
|
|
310
257
|
state: updatedState
|
|
311
|
-
} = await this.createCommunicationTopics(
|
|
312
|
-
accountId,
|
|
313
|
-
options,
|
|
314
|
-
progressReporter
|
|
315
|
-
);
|
|
258
|
+
} = await this.createCommunicationTopics(options, progressReporter);
|
|
316
259
|
state = updatedState;
|
|
317
260
|
builder.setInboundTopicId(inboundTopicId);
|
|
318
261
|
builder.setOutboundTopicId(outboundTopicId);
|
|
@@ -410,1289 +353,57 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
410
353
|
};
|
|
411
354
|
}
|
|
412
355
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
356
|
+
async handleProfilePictureCreation(pfpBuffer, pfpFileName, state, progressReporter) {
|
|
357
|
+
state.currentStage = "pfp";
|
|
358
|
+
progressReporter.preparing("Creating profile picture", 30, {
|
|
359
|
+
state
|
|
360
|
+
});
|
|
361
|
+
const pfpProgress = progressReporter.createSubProgress({
|
|
362
|
+
minPercent: 30,
|
|
363
|
+
maxPercent: 50,
|
|
364
|
+
logPrefix: "PFP"
|
|
365
|
+
});
|
|
366
|
+
const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName, {
|
|
367
|
+
progressCallback: (data) => pfpProgress.report({
|
|
368
|
+
...data,
|
|
369
|
+
progressPercent: data.progressPercent ?? 0,
|
|
370
|
+
details: { ...data.details, state }
|
|
371
|
+
})
|
|
372
|
+
});
|
|
373
|
+
if (!pfpResult.success) {
|
|
374
|
+
let errorMessage = "Failed to inscribe profile picture";
|
|
375
|
+
if (pfpResult.error) {
|
|
376
|
+
errorMessage = pfpResult.error;
|
|
433
377
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
success: true
|
|
441
|
-
};
|
|
442
|
-
} catch (e) {
|
|
443
|
-
const error = e;
|
|
444
|
-
const logMessage = `Error inscribing profile picture: ${error.message}`;
|
|
445
|
-
this.logger.error(logMessage);
|
|
446
|
-
return {
|
|
447
|
-
pfpTopicId: "",
|
|
448
|
-
transactionId: "",
|
|
449
|
-
success: false,
|
|
450
|
-
error: error.message
|
|
451
|
-
};
|
|
378
|
+
throw new Error(errorMessage);
|
|
379
|
+
}
|
|
380
|
+
const pfpTopicId = pfpResult.pfpTopicId;
|
|
381
|
+
state.pfpTopicId = pfpTopicId;
|
|
382
|
+
if (state.createdResources) {
|
|
383
|
+
state.createdResources.push(`pfp:${state.pfpTopicId}`);
|
|
452
384
|
}
|
|
385
|
+
progressReporter.preparing("Profile picture created", 50, { state });
|
|
386
|
+
return pfpTopicId;
|
|
453
387
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
try {
|
|
468
|
-
let pfpTopicId = existingPfpTopicId || "";
|
|
469
|
-
if (!pfpTopicId && pfpBuffer && pfpFileName) {
|
|
470
|
-
this.logger.info("Inscribing profile picture for HCS-11 profile");
|
|
471
|
-
const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName);
|
|
472
|
-
if (!pfpResult.success) {
|
|
473
|
-
this.logger.warn(
|
|
474
|
-
`Failed to inscribe profile picture: ${pfpResult.error}, proceeding without pfp`
|
|
475
|
-
);
|
|
476
|
-
} else {
|
|
477
|
-
pfpTopicId = pfpResult.pfpTopicId;
|
|
478
|
-
}
|
|
479
|
-
} else if (existingPfpTopicId) {
|
|
480
|
-
this.logger.info(
|
|
481
|
-
`Using existing profile picture with topic ID: ${existingPfpTopicId} for HCS-11 profile`
|
|
388
|
+
async createAndInscribeProfile(isAgentBuilder, builder, pfpTopicId, state, inboundTopicId, outboundTopicId, options, progressReporter) {
|
|
389
|
+
if (!this.hcs11Client) {
|
|
390
|
+
if (progressReporter) {
|
|
391
|
+
progressReporter.failed("HCS11Client is not available");
|
|
392
|
+
}
|
|
393
|
+
throw new Error("HCS11Client is not available");
|
|
394
|
+
}
|
|
395
|
+
this.logger.info("Creating and inscribing profile");
|
|
396
|
+
if (!state.profileTopicId) {
|
|
397
|
+
if (progressReporter) {
|
|
398
|
+
progressReporter.preparing(
|
|
399
|
+
`Storing HCS-11 ${isAgentBuilder ? "agent" : "person"} profile`,
|
|
400
|
+
80
|
|
482
401
|
);
|
|
483
|
-
pfpTopicId = existingPfpTopicId;
|
|
484
402
|
}
|
|
485
|
-
const
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
platform,
|
|
490
|
-
handle
|
|
491
|
-
})) : void 0;
|
|
492
|
-
const profile = this.hcs11Client.createAIAgentProfile(
|
|
493
|
-
agentName,
|
|
494
|
-
agentType,
|
|
495
|
-
capabilities,
|
|
496
|
-
metadata.model || "unknown",
|
|
497
|
-
{
|
|
498
|
-
alias: agentName.toLowerCase().replace(/\s+/g, "_"),
|
|
499
|
-
bio: agentBio,
|
|
500
|
-
profileImage: pfpTopicId ? `hcs://1/${pfpTopicId}` : void 0,
|
|
501
|
-
socials: formattedSocials,
|
|
502
|
-
properties: metadata.properties,
|
|
503
|
-
inboundTopicId,
|
|
504
|
-
outboundTopicId,
|
|
505
|
-
creator: metadata.creator
|
|
506
|
-
}
|
|
507
|
-
);
|
|
508
|
-
const profileResult = await this.hcs11Client.createAndInscribeProfile(
|
|
509
|
-
profile,
|
|
510
|
-
true
|
|
511
|
-
);
|
|
512
|
-
if (!profileResult.success) {
|
|
513
|
-
this.logger.error(`Failed to inscribe profile: ${profileResult.error}`);
|
|
514
|
-
throw new Error(profileResult.error || "Failed to inscribe profile");
|
|
515
|
-
}
|
|
516
|
-
this.logger.info(
|
|
517
|
-
`Profile inscribed with topic ID: ${profileResult.profileTopicId}, transaction ID: ${profileResult.transactionId}`
|
|
518
|
-
);
|
|
519
|
-
return {
|
|
520
|
-
profileTopicId: profileResult.profileTopicId,
|
|
521
|
-
pfpTopicId,
|
|
522
|
-
transactionId: profileResult.transactionId,
|
|
523
|
-
success: true
|
|
524
|
-
};
|
|
525
|
-
} catch (e) {
|
|
526
|
-
const error = e;
|
|
527
|
-
const logMessage = `Error storing HCS-11 profile: ${error.message}`;
|
|
528
|
-
this.logger.error(logMessage);
|
|
529
|
-
return {
|
|
530
|
-
profileTopicId: "",
|
|
531
|
-
pfpTopicId: "",
|
|
532
|
-
transactionId: "",
|
|
533
|
-
success: false,
|
|
534
|
-
error: error.message
|
|
535
|
-
};
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
async setupFees(transaction, feeConfig, additionalExemptAccounts = []) {
|
|
539
|
-
let modifiedTransaction = transaction;
|
|
540
|
-
if (!this.client.operatorPublicKey) {
|
|
541
|
-
return modifiedTransaction;
|
|
542
|
-
}
|
|
543
|
-
if (!feeConfig.customFees || feeConfig.customFees.length === 0) {
|
|
544
|
-
this.logger.warn("No custom fees provided in fee config for setupFees");
|
|
545
|
-
return modifiedTransaction;
|
|
546
|
-
}
|
|
547
|
-
if (feeConfig.customFees.length > 10) {
|
|
548
|
-
this.logger.warn(
|
|
549
|
-
"More than 10 custom fees provided, only the first 10 will be used"
|
|
550
|
-
);
|
|
551
|
-
feeConfig.customFees = feeConfig.customFees.slice(0, 10);
|
|
552
|
-
}
|
|
553
|
-
const customFees = feeConfig.customFees.map((fee) => {
|
|
554
|
-
if (!fee.feeCollectorAccountId) {
|
|
555
|
-
this.logger.error(
|
|
556
|
-
"Internal Error: Fee collector ID missing in setupFees"
|
|
557
|
-
);
|
|
558
|
-
return null;
|
|
559
|
-
}
|
|
560
|
-
if (fee.type === "FIXED_FEE") {
|
|
561
|
-
const customFee = new CustomFixedFee().setAmount(Number(fee.feeAmount.amount)).setFeeCollectorAccountId(
|
|
562
|
-
AccountId.fromString(fee.feeCollectorAccountId)
|
|
563
|
-
);
|
|
564
|
-
if (fee.feeTokenId) {
|
|
565
|
-
customFee.setDenominatingTokenId(
|
|
566
|
-
TokenId.fromString(fee.feeTokenId)
|
|
567
|
-
);
|
|
568
|
-
}
|
|
569
|
-
return customFee;
|
|
570
|
-
}
|
|
571
|
-
return null;
|
|
572
|
-
}).filter(Boolean);
|
|
573
|
-
if (customFees.length === 0) {
|
|
574
|
-
this.logger.warn("No valid custom fees to apply in setupFees");
|
|
575
|
-
return modifiedTransaction;
|
|
576
|
-
}
|
|
577
|
-
const exemptAccountIds = [
|
|
578
|
-
...feeConfig.exemptAccounts || [],
|
|
579
|
-
...additionalExemptAccounts
|
|
580
|
-
];
|
|
581
|
-
if (exemptAccountIds.length > 0) {
|
|
582
|
-
modifiedTransaction = await this.setupExemptKeys(
|
|
583
|
-
transaction,
|
|
584
|
-
exemptAccountIds
|
|
585
|
-
);
|
|
586
|
-
}
|
|
587
|
-
return modifiedTransaction.setFeeScheduleKey(this.client.operatorPublicKey).setCustomFees(customFees);
|
|
588
|
-
}
|
|
589
|
-
async setupExemptKeys(transaction, exemptAccountIds) {
|
|
590
|
-
let modifiedTransaction = transaction;
|
|
591
|
-
const uniqueExemptAccountIds = Array.from(new Set(exemptAccountIds));
|
|
592
|
-
const filteredExemptAccounts = uniqueExemptAccountIds.filter(
|
|
593
|
-
(account) => account !== this.client.operatorAccountId?.toString()
|
|
594
|
-
);
|
|
595
|
-
let exemptKeys = [];
|
|
596
|
-
if (filteredExemptAccounts.length > 0) {
|
|
597
|
-
try {
|
|
598
|
-
exemptKeys = await accountIdsToExemptKeys(
|
|
599
|
-
filteredExemptAccounts,
|
|
600
|
-
this.network,
|
|
601
|
-
this.logger
|
|
602
|
-
);
|
|
603
|
-
} catch (e) {
|
|
604
|
-
const error = e;
|
|
605
|
-
const logMessage = `Error getting exempt keys: ${error.message}, continuing without exempt keys`;
|
|
606
|
-
this.logger.warn(logMessage);
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
if (exemptKeys.length > 0) {
|
|
610
|
-
modifiedTransaction = modifiedTransaction.setFeeExemptKeys(exemptKeys);
|
|
611
|
-
}
|
|
612
|
-
return modifiedTransaction;
|
|
613
|
-
}
|
|
614
|
-
/**
|
|
615
|
-
* Handles a connection request from another account
|
|
616
|
-
* @param inboundTopicId Inbound topic ID of your agent
|
|
617
|
-
* @param requestingAccountId Requesting account ID
|
|
618
|
-
* @param connectionRequestId Connection request ID
|
|
619
|
-
* @param connectionFeeConfig Optional fee configuration for the connection topic
|
|
620
|
-
* @param ttl Optional ttl parameter with default
|
|
621
|
-
* @returns Response with connection details
|
|
622
|
-
*/
|
|
623
|
-
async handleConnectionRequest(inboundTopicId, requestingAccountId, connectionRequestId, connectionFeeConfig, ttl = 60) {
|
|
624
|
-
this.logger.info(
|
|
625
|
-
`Handling connection request ${connectionRequestId} from ${requestingAccountId}`
|
|
626
|
-
);
|
|
627
|
-
const accountId = this.getClient().operatorAccountId?.toString();
|
|
628
|
-
if (!accountId) {
|
|
629
|
-
throw new Error("Failed to retrieve operator account ID");
|
|
630
|
-
}
|
|
631
|
-
let requesterKey = await this.mirrorNode.getPublicKey(requestingAccountId);
|
|
632
|
-
const accountKey = await this.mirrorNode.getPublicKey(accountId);
|
|
633
|
-
if (!accountKey) {
|
|
634
|
-
throw new Error("Failed to retrieve public key");
|
|
635
|
-
}
|
|
636
|
-
const thresholdKey = new KeyList([accountKey, requesterKey], 1);
|
|
637
|
-
let connectionTopicId;
|
|
638
|
-
try {
|
|
639
|
-
const connectionTransaction = buildHcs10CreateConnectionTopicTx({
|
|
640
|
-
ttl,
|
|
641
|
-
inboundTopicId,
|
|
642
|
-
connectionId: connectionRequestId,
|
|
643
|
-
adminKey: thresholdKey,
|
|
644
|
-
submitKey: thresholdKey
|
|
645
|
-
});
|
|
646
|
-
if (connectionFeeConfig) {
|
|
647
|
-
const feeConfig = connectionFeeConfig.build();
|
|
648
|
-
const modifiedFeeConfig = {
|
|
649
|
-
...feeConfig,
|
|
650
|
-
exemptAccounts: [...feeConfig.exemptAccounts || []]
|
|
651
|
-
};
|
|
652
|
-
const { topicId } = await this.executeTopicCreateTransaction({
|
|
653
|
-
transaction: connectionTransaction,
|
|
654
|
-
feeConfig: modifiedFeeConfig
|
|
655
|
-
});
|
|
656
|
-
connectionTopicId = topicId;
|
|
657
|
-
} else {
|
|
658
|
-
const { topicId } = await this.executeTopicCreateTransaction({
|
|
659
|
-
transaction: connectionTransaction
|
|
660
|
-
});
|
|
661
|
-
connectionTopicId = topicId;
|
|
662
|
-
}
|
|
663
|
-
this.logger.info(`Created new connection topic ID: ${connectionTopicId}`);
|
|
664
|
-
} catch (error) {
|
|
665
|
-
const logMessage = `Failed to create connection topic: ${error}`;
|
|
666
|
-
this.logger.error(logMessage);
|
|
667
|
-
throw new TopicCreationError(logMessage);
|
|
668
|
-
}
|
|
669
|
-
const operatorId = `${inboundTopicId}@${accountId}`;
|
|
670
|
-
const confirmedConnectionSequenceNumber = await this.confirmConnection(
|
|
671
|
-
inboundTopicId,
|
|
672
|
-
connectionTopicId,
|
|
673
|
-
requestingAccountId,
|
|
674
|
-
connectionRequestId,
|
|
675
|
-
"Connection accepted. Looking forward to collaborating!"
|
|
676
|
-
);
|
|
677
|
-
const accountTopics = await this.retrieveCommunicationTopics(accountId);
|
|
678
|
-
const requestingAccountTopics = await this.retrieveCommunicationTopics(requestingAccountId);
|
|
679
|
-
const requestingAccountOperatorId = `${requestingAccountTopics.inboundTopic}@${requestingAccountId}`;
|
|
680
|
-
await this.recordOutboundConnectionConfirmation({
|
|
681
|
-
outboundTopicId: accountTopics.outboundTopic,
|
|
682
|
-
requestorOutboundTopicId: requestingAccountTopics.outboundTopic,
|
|
683
|
-
connectionRequestId,
|
|
684
|
-
confirmedRequestId: confirmedConnectionSequenceNumber,
|
|
685
|
-
connectionTopicId,
|
|
686
|
-
operatorId: requestingAccountOperatorId,
|
|
687
|
-
memo: `Connection established with ${requestingAccountId}`
|
|
688
|
-
});
|
|
689
|
-
return {
|
|
690
|
-
connectionTopicId,
|
|
691
|
-
confirmedConnectionSequenceNumber,
|
|
692
|
-
operatorId
|
|
693
|
-
};
|
|
694
|
-
}
|
|
695
|
-
/**
|
|
696
|
-
* Confirms a connection request from another account
|
|
697
|
-
* @param inboundTopicId Inbound topic ID
|
|
698
|
-
* @param connectionTopicId Connection topic ID
|
|
699
|
-
* @param connectedAccountId Connected account ID
|
|
700
|
-
* @param connectionId Connection ID
|
|
701
|
-
* @param memo Memo for the connection request
|
|
702
|
-
* @param submitKey Optional submit key
|
|
703
|
-
* @returns Sequence number of the confirmed connection
|
|
704
|
-
*/
|
|
705
|
-
async confirmConnection(inboundTopicId, connectionTopicId, connectedAccountId, connectionId, memo, submitKey) {
|
|
706
|
-
const operatorId = await this.getOperatorId();
|
|
707
|
-
this.logger.info(`Confirming connection with ID ${connectionId}`);
|
|
708
|
-
const submissionCheck = await this.canSubmitToTopic(
|
|
709
|
-
inboundTopicId,
|
|
710
|
-
this.client.operatorAccountId?.toString() || ""
|
|
711
|
-
);
|
|
712
|
-
const transaction = buildHcs10ConfirmConnectionTx({
|
|
713
|
-
inboundTopicId,
|
|
714
|
-
connectionTopicId,
|
|
715
|
-
connectedAccountId,
|
|
716
|
-
operatorId,
|
|
717
|
-
connectionId,
|
|
718
|
-
memo
|
|
719
|
-
});
|
|
720
|
-
const result = await this.submitPayload(
|
|
721
|
-
transaction,
|
|
722
|
-
void 0,
|
|
723
|
-
submitKey,
|
|
724
|
-
submissionCheck.requiresFee
|
|
725
|
-
);
|
|
726
|
-
const sequenceNumber = result.topicSequenceNumber?.toNumber();
|
|
727
|
-
if (!sequenceNumber) {
|
|
728
|
-
throw new ConnectionConfirmationError(
|
|
729
|
-
"Failed to confirm connection: sequence number is null"
|
|
730
|
-
);
|
|
731
|
-
}
|
|
732
|
-
return sequenceNumber;
|
|
733
|
-
}
|
|
734
|
-
async sendMessage(connectionTopicId, data, memo, submitKey, options) {
|
|
735
|
-
const submissionCheck = await this.canSubmitToTopic(
|
|
736
|
-
connectionTopicId,
|
|
737
|
-
this.client.operatorAccountId?.toString() || ""
|
|
738
|
-
);
|
|
739
|
-
const operatorId = await this.getOperatorId();
|
|
740
|
-
const payload = {
|
|
741
|
-
p: "hcs-10",
|
|
742
|
-
op: "message",
|
|
743
|
-
operator_id: operatorId,
|
|
744
|
-
data,
|
|
745
|
-
m: memo
|
|
746
|
-
};
|
|
747
|
-
const payloadString = JSON.stringify(payload);
|
|
748
|
-
const isLargePayload = Buffer.from(payloadString).length > 1e3;
|
|
749
|
-
if (isLargePayload) {
|
|
750
|
-
this.logger.info(
|
|
751
|
-
"Message payload exceeds 1000 bytes, storing via inscription"
|
|
752
|
-
);
|
|
753
|
-
try {
|
|
754
|
-
const contentBuffer = Buffer.from(data);
|
|
755
|
-
const fileName = `message-${Date.now()}.json`;
|
|
756
|
-
const inscriptionResult = await this.inscribeFile(
|
|
757
|
-
contentBuffer,
|
|
758
|
-
fileName,
|
|
759
|
-
{
|
|
760
|
-
progressCallback: options?.progressCallback,
|
|
761
|
-
waitMaxAttempts: options?.waitMaxAttempts,
|
|
762
|
-
waitIntervalMs: options?.waitIntervalMs
|
|
763
|
-
}
|
|
764
|
-
);
|
|
765
|
-
if (getTopicId(inscriptionResult)) {
|
|
766
|
-
payload.data = `hcs://1/${getTopicId(inscriptionResult)}`;
|
|
767
|
-
this.logger.info(
|
|
768
|
-
`Large message inscribed with topic ID: ${getTopicId(inscriptionResult)}`
|
|
769
|
-
);
|
|
770
|
-
} else {
|
|
771
|
-
throw new Error("Failed to inscribe large message content");
|
|
772
|
-
}
|
|
773
|
-
} catch (error) {
|
|
774
|
-
const err = error;
|
|
775
|
-
const logMessage = `Error inscribing large message: ${err.message}`;
|
|
776
|
-
this.logger.error(logMessage);
|
|
777
|
-
throw new Error(logMessage);
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
this.logger.info("Submitting message to connection topic", payload);
|
|
781
|
-
const transaction = buildHcs10SendMessageTx({
|
|
782
|
-
connectionTopicId,
|
|
783
|
-
operatorId,
|
|
784
|
-
data: payload.data,
|
|
785
|
-
memo
|
|
786
|
-
});
|
|
787
|
-
return await this.submitPayload(
|
|
788
|
-
transaction,
|
|
789
|
-
void 0,
|
|
790
|
-
submitKey,
|
|
791
|
-
submissionCheck.requiresFee
|
|
792
|
-
);
|
|
793
|
-
}
|
|
794
|
-
async executeTopicCreateTransaction(params) {
|
|
795
|
-
let workingTransaction = params.transaction;
|
|
796
|
-
if (params.feeConfig) {
|
|
797
|
-
workingTransaction = await this.setupFees(
|
|
798
|
-
workingTransaction,
|
|
799
|
-
params.feeConfig,
|
|
800
|
-
params.additionalExemptAccounts || []
|
|
801
|
-
);
|
|
802
|
-
}
|
|
803
|
-
try {
|
|
804
|
-
const response = await workingTransaction.execute(this.client);
|
|
805
|
-
const receipt = await response.getReceipt(this.client);
|
|
806
|
-
if (!receipt.topicId) {
|
|
807
|
-
this.logger.error("Failed to create topic: topicId is null");
|
|
808
|
-
throw new Error("Failed to create topic: topicId is null");
|
|
809
|
-
}
|
|
810
|
-
return {
|
|
811
|
-
topicId: receipt.topicId.toString(),
|
|
812
|
-
receipt,
|
|
813
|
-
response
|
|
814
|
-
};
|
|
815
|
-
} catch (error) {
|
|
816
|
-
this.logger.error("Topic creation failed", {
|
|
817
|
-
error: error.message,
|
|
818
|
-
transactionId: error.transactionId?.toString(),
|
|
819
|
-
operatorId: this.client.operatorAccountId?.toString()
|
|
820
|
-
});
|
|
821
|
-
throw error;
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
async createTopic(memo, adminKey, submitKey, feeConfig) {
|
|
825
|
-
this.logger.info("Creating topic");
|
|
826
|
-
const transaction = buildTopicCreateTx({
|
|
827
|
-
memo,
|
|
828
|
-
adminKey,
|
|
829
|
-
submitKey,
|
|
830
|
-
operatorPublicKey: this.client.operatorPublicKey || this.operatorCtx.operatorKey?.publicKey
|
|
831
|
-
});
|
|
832
|
-
const { topicId } = await this.executeTopicCreateTransaction({
|
|
833
|
-
transaction,
|
|
834
|
-
feeConfig
|
|
835
|
-
});
|
|
836
|
-
return topicId;
|
|
837
|
-
}
|
|
838
|
-
async submitPayload(topicOrTransaction, payload, submitKey, requiresFee = false) {
|
|
839
|
-
const isTransaction = topicOrTransaction instanceof TopicMessageSubmitTransaction || typeof topicOrTransaction !== "string" && typeof topicOrTransaction.getMessage === "function";
|
|
840
|
-
if (isTransaction) {
|
|
841
|
-
const transaction2 = topicOrTransaction instanceof TopicMessageSubmitTransaction ? topicOrTransaction : topicOrTransaction;
|
|
842
|
-
const messageBytes = transaction2.getMessage();
|
|
843
|
-
if (!messageBytes) {
|
|
844
|
-
throw new Error("Message payload is missing");
|
|
845
|
-
}
|
|
846
|
-
const payloadSizeInBytes2 = Buffer.from(messageBytes).length;
|
|
847
|
-
if (payloadSizeInBytes2 > 1e3) {
|
|
848
|
-
throw new PayloadSizeError(
|
|
849
|
-
"Payload size exceeds 1000 bytes limit",
|
|
850
|
-
payloadSizeInBytes2
|
|
851
|
-
);
|
|
852
|
-
}
|
|
853
|
-
if (requiresFee) {
|
|
854
|
-
this.logger.info(
|
|
855
|
-
"Topic requires fee payment, setting max transaction fee"
|
|
856
|
-
);
|
|
857
|
-
transaction2.setMaxTransactionFee(new Hbar(this.feeAmount));
|
|
858
|
-
}
|
|
859
|
-
let transactionResponse2;
|
|
860
|
-
if (submitKey) {
|
|
861
|
-
const frozenTransaction = transaction2.freezeWith(this.client);
|
|
862
|
-
const signedTransaction = await frozenTransaction.sign(submitKey);
|
|
863
|
-
transactionResponse2 = await signedTransaction.execute(this.client);
|
|
864
|
-
} else {
|
|
865
|
-
transactionResponse2 = await transaction2.execute(this.client);
|
|
866
|
-
}
|
|
867
|
-
const receipt2 = await transactionResponse2.getReceipt(this.client);
|
|
868
|
-
if (!receipt2) {
|
|
869
|
-
this.logger.error("Failed to submit message: receipt is null");
|
|
870
|
-
throw new Error("Failed to submit message: receipt is null");
|
|
871
|
-
}
|
|
872
|
-
this.logger.info("Message submitted successfully");
|
|
873
|
-
return receipt2;
|
|
874
|
-
}
|
|
875
|
-
const message = typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
876
|
-
const payloadSizeInBytes = Buffer.byteLength(message, "utf8");
|
|
877
|
-
if (payloadSizeInBytes > 1e3) {
|
|
878
|
-
throw new PayloadSizeError(
|
|
879
|
-
"Payload size exceeds 1000 bytes limit",
|
|
880
|
-
payloadSizeInBytes
|
|
881
|
-
);
|
|
882
|
-
}
|
|
883
|
-
const transactionMemo = this.getHcs10TransactionMemo(payload);
|
|
884
|
-
const transaction = buildMessageTx({
|
|
885
|
-
topicId: topicOrTransaction,
|
|
886
|
-
message,
|
|
887
|
-
transactionMemo: transactionMemo || void 0
|
|
888
|
-
});
|
|
889
|
-
if (requiresFee) {
|
|
890
|
-
this.logger.info(
|
|
891
|
-
"Topic requires fee payment, setting max transaction fee"
|
|
892
|
-
);
|
|
893
|
-
transaction.setMaxTransactionFee(new Hbar(this.feeAmount));
|
|
894
|
-
}
|
|
895
|
-
let transactionResponse;
|
|
896
|
-
if (submitKey) {
|
|
897
|
-
const frozenTransaction = transaction.freezeWith(this.client);
|
|
898
|
-
const signedTransaction = await frozenTransaction.sign(submitKey);
|
|
899
|
-
transactionResponse = await signedTransaction.execute(this.client);
|
|
900
|
-
} else {
|
|
901
|
-
transactionResponse = await transaction.execute(this.client);
|
|
902
|
-
}
|
|
903
|
-
const receipt = await transactionResponse.getReceipt(this.client);
|
|
904
|
-
if (!receipt) {
|
|
905
|
-
this.logger.error("Failed to submit message: receipt is null");
|
|
906
|
-
throw new Error("Failed to submit message: receipt is null");
|
|
907
|
-
}
|
|
908
|
-
this.logger.info("Message submitted successfully");
|
|
909
|
-
return receipt;
|
|
910
|
-
}
|
|
911
|
-
async inscribeFile(buffer, fileName, options) {
|
|
912
|
-
this.logger.info("Inscribing file");
|
|
913
|
-
if (!this.client.operatorAccountId) {
|
|
914
|
-
this.logger.error("Operator account ID is not set");
|
|
915
|
-
throw new Error("Operator account ID is not set");
|
|
916
|
-
}
|
|
917
|
-
if (!this.operatorCtx.operatorKey) {
|
|
918
|
-
this.logger.error("Operator private key is not set");
|
|
919
|
-
throw new Error("Operator private key is not set");
|
|
920
|
-
}
|
|
921
|
-
const mimeType = mime.lookup(fileName) || "application/octet-stream";
|
|
922
|
-
const privateKey = this.operatorCtx.operatorKey;
|
|
923
|
-
const sdk = await InscriptionSDK.createWithAuth({
|
|
924
|
-
type: "server",
|
|
925
|
-
accountId: this.client.operatorAccountId.toString(),
|
|
926
|
-
privateKey,
|
|
927
|
-
network: this.network
|
|
928
|
-
});
|
|
929
|
-
const inscriptionOptions = {
|
|
930
|
-
mode: "file",
|
|
931
|
-
waitForConfirmation: true,
|
|
932
|
-
waitMaxAttempts: options?.waitMaxAttempts || 30,
|
|
933
|
-
waitIntervalMs: options?.waitIntervalMs || 4e3,
|
|
934
|
-
progressCallback: options?.progressCallback,
|
|
935
|
-
logging: {
|
|
936
|
-
level: this.logger.getLevel ? this.logger.getLevel() : "info"
|
|
937
|
-
}
|
|
938
|
-
};
|
|
939
|
-
const response = await inscribe(
|
|
940
|
-
{
|
|
941
|
-
type: "buffer",
|
|
942
|
-
buffer,
|
|
943
|
-
fileName,
|
|
944
|
-
mimeType
|
|
945
|
-
},
|
|
946
|
-
{
|
|
947
|
-
accountId: this.client.operatorAccountId.toString(),
|
|
948
|
-
privateKey,
|
|
949
|
-
network: this.network
|
|
950
|
-
},
|
|
951
|
-
inscriptionOptions,
|
|
952
|
-
sdk
|
|
953
|
-
);
|
|
954
|
-
if (!response.confirmed || !response.inscription) {
|
|
955
|
-
throw new Error("Inscription was not confirmed");
|
|
956
|
-
}
|
|
957
|
-
return response.inscription;
|
|
958
|
-
}
|
|
959
|
-
/**
|
|
960
|
-
* Waits for confirmation of a connection request
|
|
961
|
-
* @param inboundTopicId Inbound topic ID
|
|
962
|
-
* @param connectionRequestId Connection request ID
|
|
963
|
-
* @param maxAttempts Maximum number of attempts
|
|
964
|
-
* @param delayMs Delay between attempts in milliseconds
|
|
965
|
-
* @returns Connection confirmation details
|
|
966
|
-
*/
|
|
967
|
-
async waitForConnectionConfirmation(inboundTopicId, connectionRequestId, maxAttempts = 60, delayMs = 2e3, recordConfirmation = true) {
|
|
968
|
-
this.logger.info(
|
|
969
|
-
`Waiting for connection confirmation on inbound topic ${inboundTopicId} for request ID ${connectionRequestId}`
|
|
970
|
-
);
|
|
971
|
-
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
972
|
-
this.logger.info(
|
|
973
|
-
`Attempt ${attempt + 1}/${maxAttempts} to find connection confirmation`
|
|
974
|
-
);
|
|
975
|
-
const messages = await this.mirrorNode.getTopicMessages(inboundTopicId);
|
|
976
|
-
const connectionCreatedMessages = messages.filter(
|
|
977
|
-
(m) => m.op === "connection_created"
|
|
978
|
-
);
|
|
979
|
-
this.logger.info(
|
|
980
|
-
`Found ${connectionCreatedMessages.length} connection_created messages`
|
|
981
|
-
);
|
|
982
|
-
if (connectionCreatedMessages.length > 0) {
|
|
983
|
-
for (const message of connectionCreatedMessages) {
|
|
984
|
-
if (Number(message.connection_id) === Number(connectionRequestId)) {
|
|
985
|
-
const confirmationResult = {
|
|
986
|
-
connectionTopicId: message.connection_topic_id,
|
|
987
|
-
sequence_number: Number(message.sequence_number),
|
|
988
|
-
confirmedBy: message.operator_id,
|
|
989
|
-
memo: message.m
|
|
990
|
-
};
|
|
991
|
-
const confirmedByAccountId = this.extractAccountFromOperatorId(
|
|
992
|
-
confirmationResult.confirmedBy
|
|
993
|
-
);
|
|
994
|
-
const account = this.getAccountAndSigner();
|
|
995
|
-
const confirmedByConnectionTopics = await this.retrieveCommunicationTopics(confirmedByAccountId);
|
|
996
|
-
const agentConnectionTopics = await this.retrieveCommunicationTopics(account.accountId);
|
|
997
|
-
this.logger.info(
|
|
998
|
-
"Connection confirmation found",
|
|
999
|
-
confirmationResult
|
|
1000
|
-
);
|
|
1001
|
-
if (recordConfirmation) {
|
|
1002
|
-
await this.recordOutboundConnectionConfirmation({
|
|
1003
|
-
requestorOutboundTopicId: confirmedByConnectionTopics.outboundTopic,
|
|
1004
|
-
outboundTopicId: agentConnectionTopics.outboundTopic,
|
|
1005
|
-
connectionRequestId,
|
|
1006
|
-
confirmedRequestId: confirmationResult.sequence_number,
|
|
1007
|
-
connectionTopicId: confirmationResult.connectionTopicId,
|
|
1008
|
-
operatorId: confirmationResult.confirmedBy,
|
|
1009
|
-
memo: confirmationResult.memo || "Connection confirmed"
|
|
1010
|
-
});
|
|
1011
|
-
}
|
|
1012
|
-
return confirmationResult;
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
if (attempt < maxAttempts - 1) {
|
|
1017
|
-
this.logger.info(
|
|
1018
|
-
`No matching confirmation found, waiting ${delayMs}ms before retrying...`
|
|
1019
|
-
);
|
|
1020
|
-
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
1021
|
-
}
|
|
1022
|
-
}
|
|
1023
|
-
throw new Error(
|
|
1024
|
-
`Connection confirmation not found after ${maxAttempts} attempts for request ID ${connectionRequestId}`
|
|
1025
|
-
);
|
|
1026
|
-
}
|
|
1027
|
-
getAccountAndSigner() {
|
|
1028
|
-
const PK = this.operatorCtx.operatorKey;
|
|
1029
|
-
return {
|
|
1030
|
-
accountId: this.client.operatorAccountId.toString(),
|
|
1031
|
-
signer: PK
|
|
1032
|
-
};
|
|
1033
|
-
}
|
|
1034
|
-
/**
|
|
1035
|
-
* Creates and registers an agent with a Guarded registry.
|
|
1036
|
-
*
|
|
1037
|
-
* This function performs the following steps:
|
|
1038
|
-
* 1. Creates a new account if no existing account is provided.
|
|
1039
|
-
* 2. Initializes an HCS10 client with the new account.
|
|
1040
|
-
* 3. Creates an agent on the client.
|
|
1041
|
-
* 4. Registers the agent with the Hashgraph Online Guarded Registry.
|
|
1042
|
-
*
|
|
1043
|
-
* @param builder The agent builder object
|
|
1044
|
-
* @param options Optional configuration including progress callback and state management
|
|
1045
|
-
* @returns Agent registration result
|
|
1046
|
-
*/
|
|
1047
|
-
async createAndRegisterAgent(builder, options) {
|
|
1048
|
-
try {
|
|
1049
|
-
const config = builder.build();
|
|
1050
|
-
const progressCallback = options?.progressCallback;
|
|
1051
|
-
const baseUrl = options?.baseUrl || this.guardedRegistryBaseUrl;
|
|
1052
|
-
let state = options?.existingState || {
|
|
1053
|
-
currentStage: "init",
|
|
1054
|
-
completedPercentage: 0,
|
|
1055
|
-
createdResources: []
|
|
1056
|
-
};
|
|
1057
|
-
state.agentMetadata = config.metadata;
|
|
1058
|
-
if (progressCallback) {
|
|
1059
|
-
progressCallback({
|
|
1060
|
-
stage: "preparing",
|
|
1061
|
-
message: "Starting agent creation process",
|
|
1062
|
-
progressPercent: 0,
|
|
1063
|
-
details: { state }
|
|
1064
|
-
});
|
|
1065
|
-
}
|
|
1066
|
-
let account = config.existingAccount;
|
|
1067
|
-
let agentClient;
|
|
1068
|
-
if (!state.inboundTopicId || !state.outboundTopicId || !state.profileTopicId) {
|
|
1069
|
-
if (!account) {
|
|
1070
|
-
if (state.createdResources && state.createdResources.some((r) => r.startsWith("account:"))) {
|
|
1071
|
-
const accountResource = state.createdResources.find(
|
|
1072
|
-
(r) => r.startsWith("account:")
|
|
1073
|
-
);
|
|
1074
|
-
const existingAccountId = accountResource?.split(":")[1];
|
|
1075
|
-
if (existingAccountId && config.existingAccount) {
|
|
1076
|
-
account = config.existingAccount;
|
|
1077
|
-
this.logger.info(
|
|
1078
|
-
`Resuming with existing account: ${existingAccountId}`
|
|
1079
|
-
);
|
|
1080
|
-
} else {
|
|
1081
|
-
account = await this.createAccount(options?.initialBalance);
|
|
1082
|
-
state.createdResources = state.createdResources || [];
|
|
1083
|
-
state.createdResources.push(`account:${account.accountId}`);
|
|
1084
|
-
}
|
|
1085
|
-
} else {
|
|
1086
|
-
account = await this.createAccount(options?.initialBalance);
|
|
1087
|
-
state.createdResources = state.createdResources || [];
|
|
1088
|
-
state.createdResources.push(`account:${account.accountId}`);
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
if (progressCallback) {
|
|
1092
|
-
progressCallback({
|
|
1093
|
-
stage: "preparing",
|
|
1094
|
-
message: "Created account or using existing account",
|
|
1095
|
-
progressPercent: 20,
|
|
1096
|
-
details: { state, account }
|
|
1097
|
-
});
|
|
1098
|
-
}
|
|
1099
|
-
const resolver = new NodeOperatorResolver({
|
|
1100
|
-
mirrorNode: this.mirrorNode,
|
|
1101
|
-
logger: this.logger
|
|
1102
|
-
});
|
|
1103
|
-
const keyInfo = await resolver.resolveOperatorKey(
|
|
1104
|
-
account.accountId,
|
|
1105
|
-
account.privateKey
|
|
1106
|
-
);
|
|
1107
|
-
const publicKey = keyInfo.privateKey.publicKey.toString();
|
|
1108
|
-
agentClient = new HCS10Client({
|
|
1109
|
-
network: config.network,
|
|
1110
|
-
operatorId: account.accountId,
|
|
1111
|
-
operatorPrivateKey: keyInfo.privateKey.toString(),
|
|
1112
|
-
operatorPublicKey: publicKey,
|
|
1113
|
-
keyType: keyInfo.keyType,
|
|
1114
|
-
logLevel: "info",
|
|
1115
|
-
guardedRegistryBaseUrl: baseUrl
|
|
1116
|
-
});
|
|
1117
|
-
if (progressCallback) {
|
|
1118
|
-
progressCallback({
|
|
1119
|
-
stage: "preparing",
|
|
1120
|
-
message: "Initialized agent client",
|
|
1121
|
-
progressPercent: 25,
|
|
1122
|
-
details: { state }
|
|
1123
|
-
});
|
|
1124
|
-
}
|
|
1125
|
-
let outboundTopicId = state.outboundTopicId;
|
|
1126
|
-
let inboundTopicId = state.inboundTopicId;
|
|
1127
|
-
let pfpTopicId = state.pfpTopicId;
|
|
1128
|
-
let profileTopicId = state.profileTopicId;
|
|
1129
|
-
if (!outboundTopicId || !inboundTopicId || !profileTopicId) {
|
|
1130
|
-
if (pfpTopicId) {
|
|
1131
|
-
builder.setExistingProfilePicture(pfpTopicId);
|
|
1132
|
-
}
|
|
1133
|
-
const createResult = await agentClient.createAgent(
|
|
1134
|
-
builder,
|
|
1135
|
-
60,
|
|
1136
|
-
state,
|
|
1137
|
-
(data) => {
|
|
1138
|
-
if (progressCallback) {
|
|
1139
|
-
progressCallback({
|
|
1140
|
-
stage: data.stage,
|
|
1141
|
-
message: data.message,
|
|
1142
|
-
progressPercent: data.progressPercent || 0,
|
|
1143
|
-
details: {
|
|
1144
|
-
...data.details,
|
|
1145
|
-
state: {
|
|
1146
|
-
...state,
|
|
1147
|
-
...data.details?.state
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
});
|
|
1151
|
-
}
|
|
1152
|
-
}
|
|
1153
|
-
);
|
|
1154
|
-
outboundTopicId = createResult.outboundTopicId;
|
|
1155
|
-
inboundTopicId = createResult.inboundTopicId;
|
|
1156
|
-
pfpTopicId = createResult.pfpTopicId;
|
|
1157
|
-
profileTopicId = createResult.profileTopicId;
|
|
1158
|
-
state.outboundTopicId = outboundTopicId;
|
|
1159
|
-
state.inboundTopicId = inboundTopicId;
|
|
1160
|
-
state.pfpTopicId = pfpTopicId;
|
|
1161
|
-
state.profileTopicId = profileTopicId;
|
|
1162
|
-
if (!state.createdResources) {
|
|
1163
|
-
state.createdResources = [];
|
|
1164
|
-
}
|
|
1165
|
-
if (pfpTopicId && !state.createdResources.includes(`pfp:${pfpTopicId}`)) {
|
|
1166
|
-
state.createdResources.push(`pfp:${pfpTopicId}`);
|
|
1167
|
-
}
|
|
1168
|
-
if (!state.createdResources.includes(`inbound:${inboundTopicId}`)) {
|
|
1169
|
-
state.createdResources.push(`inbound:${inboundTopicId}`);
|
|
1170
|
-
}
|
|
1171
|
-
if (!state.createdResources.includes(`outbound:${outboundTopicId}`)) {
|
|
1172
|
-
state.createdResources.push(`outbound:${outboundTopicId}`);
|
|
1173
|
-
}
|
|
1174
|
-
if (!state.createdResources.includes(`profile:${profileTopicId}`)) {
|
|
1175
|
-
state.createdResources.push(`profile:${profileTopicId}`);
|
|
1176
|
-
}
|
|
1177
|
-
}
|
|
1178
|
-
state.currentStage = "profile";
|
|
1179
|
-
state.completedPercentage = 60;
|
|
1180
|
-
if (progressCallback) {
|
|
1181
|
-
progressCallback({
|
|
1182
|
-
stage: "submitting",
|
|
1183
|
-
message: "Created agent with topics and profile",
|
|
1184
|
-
progressPercent: 60,
|
|
1185
|
-
details: {
|
|
1186
|
-
state,
|
|
1187
|
-
outboundTopicId,
|
|
1188
|
-
inboundTopicId,
|
|
1189
|
-
pfpTopicId,
|
|
1190
|
-
profileTopicId
|
|
1191
|
-
}
|
|
1192
|
-
});
|
|
1193
|
-
}
|
|
1194
|
-
} else {
|
|
1195
|
-
account = account || config.existingAccount;
|
|
1196
|
-
if (!account) {
|
|
1197
|
-
throw new Error(
|
|
1198
|
-
"Cannot resume registration without account information"
|
|
1199
|
-
);
|
|
1200
|
-
}
|
|
1201
|
-
const publicKey = this.operatorCtx.keyType === "ecdsa" ? PrivateKey.fromStringECDSA(
|
|
1202
|
-
account.privateKey
|
|
1203
|
-
).publicKey.toString() : PrivateKey.fromStringED25519(
|
|
1204
|
-
account.privateKey
|
|
1205
|
-
).publicKey.toString();
|
|
1206
|
-
agentClient = new HCS10Client({
|
|
1207
|
-
network: config.network,
|
|
1208
|
-
operatorId: account.accountId,
|
|
1209
|
-
operatorPrivateKey: account.privateKey,
|
|
1210
|
-
operatorPublicKey: publicKey,
|
|
1211
|
-
logLevel: "info",
|
|
1212
|
-
guardedRegistryBaseUrl: baseUrl
|
|
1213
|
-
});
|
|
1214
|
-
this.logger.info("Resuming registration with existing state", {
|
|
1215
|
-
inboundTopicId: state.inboundTopicId,
|
|
1216
|
-
outboundTopicId: state.outboundTopicId,
|
|
1217
|
-
profileTopicId: state.profileTopicId,
|
|
1218
|
-
pfpTopicId: state.pfpTopicId
|
|
1219
|
-
});
|
|
1220
|
-
}
|
|
1221
|
-
const operatorId = `${state.inboundTopicId}@${account.accountId}`;
|
|
1222
|
-
if (state.currentStage !== "complete" || !state.createdResources?.includes(
|
|
1223
|
-
`registration:${state.inboundTopicId}`
|
|
1224
|
-
)) {
|
|
1225
|
-
const registrationResult = await agentClient.registerAgentWithGuardedRegistry(
|
|
1226
|
-
account.accountId,
|
|
1227
|
-
config.network,
|
|
1228
|
-
{
|
|
1229
|
-
progressCallback: (data) => {
|
|
1230
|
-
const adjustedPercent = 60 + (data.progressPercent || 0) * 0.4;
|
|
1231
|
-
if (progressCallback) {
|
|
1232
|
-
progressCallback({
|
|
1233
|
-
stage: data.stage,
|
|
1234
|
-
message: data.message,
|
|
1235
|
-
progressPercent: adjustedPercent,
|
|
1236
|
-
details: {
|
|
1237
|
-
...data.details,
|
|
1238
|
-
outboundTopicId: state.outboundTopicId,
|
|
1239
|
-
inboundTopicId: state.inboundTopicId,
|
|
1240
|
-
pfpTopicId: state.pfpTopicId,
|
|
1241
|
-
profileTopicId: state.profileTopicId,
|
|
1242
|
-
operatorId,
|
|
1243
|
-
state: data.details?.state || state
|
|
1244
|
-
}
|
|
1245
|
-
});
|
|
1246
|
-
}
|
|
1247
|
-
},
|
|
1248
|
-
existingState: state
|
|
1249
|
-
}
|
|
1250
|
-
);
|
|
1251
|
-
if (!registrationResult.success) {
|
|
1252
|
-
return {
|
|
1253
|
-
...registrationResult,
|
|
1254
|
-
state
|
|
1255
|
-
};
|
|
1256
|
-
}
|
|
1257
|
-
state = registrationResult.state || state;
|
|
1258
|
-
}
|
|
1259
|
-
if (progressCallback) {
|
|
1260
|
-
progressCallback({
|
|
1261
|
-
stage: "completed",
|
|
1262
|
-
message: "Agent creation and registration complete",
|
|
1263
|
-
progressPercent: 100,
|
|
1264
|
-
details: {
|
|
1265
|
-
outboundTopicId: state.outboundTopicId,
|
|
1266
|
-
inboundTopicId: state.inboundTopicId,
|
|
1267
|
-
pfpTopicId: state.pfpTopicId,
|
|
1268
|
-
profileTopicId: state.profileTopicId,
|
|
1269
|
-
operatorId,
|
|
1270
|
-
state
|
|
1271
|
-
}
|
|
1272
|
-
});
|
|
1273
|
-
}
|
|
1274
|
-
return {
|
|
1275
|
-
success: true,
|
|
1276
|
-
state,
|
|
1277
|
-
metadata: {
|
|
1278
|
-
accountId: account.accountId,
|
|
1279
|
-
privateKey: account.privateKey,
|
|
1280
|
-
operatorId,
|
|
1281
|
-
inboundTopicId: state.inboundTopicId,
|
|
1282
|
-
outboundTopicId: state.outboundTopicId,
|
|
1283
|
-
profileTopicId: state.profileTopicId,
|
|
1284
|
-
pfpTopicId: state.pfpTopicId
|
|
1285
|
-
}
|
|
1286
|
-
};
|
|
1287
|
-
} catch (e) {
|
|
1288
|
-
const error = e;
|
|
1289
|
-
const logMessage = `Failed to create and register agent: ${error.message}`;
|
|
1290
|
-
this.logger.error(logMessage);
|
|
1291
|
-
return {
|
|
1292
|
-
error: error.message,
|
|
1293
|
-
success: false,
|
|
1294
|
-
state: options?.existingState || {
|
|
1295
|
-
currentStage: "init",
|
|
1296
|
-
completedPercentage: 0,
|
|
1297
|
-
error: error.message
|
|
1298
|
-
}
|
|
1299
|
-
};
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1302
|
-
/**
|
|
1303
|
-
* Registers an agent with the guarded registry
|
|
1304
|
-
* @param accountId Account ID to register
|
|
1305
|
-
* @param inboundTopicId Inbound topic ID for the agent
|
|
1306
|
-
* @param network Network type ('mainnet' or 'testnet')
|
|
1307
|
-
* @param options Optional configuration including progress callback and confirmation settings
|
|
1308
|
-
* @returns Registration result
|
|
1309
|
-
*/
|
|
1310
|
-
async registerAgentWithGuardedRegistry(accountId, network = this.network, options) {
|
|
1311
|
-
try {
|
|
1312
|
-
this.logger.info("Registering agent with guarded registry");
|
|
1313
|
-
const maxAttempts = options?.maxAttempts ?? 60;
|
|
1314
|
-
const delayMs = options?.delayMs ?? 2e3;
|
|
1315
|
-
const progressCallback = options?.progressCallback;
|
|
1316
|
-
let state = options?.existingState || {
|
|
1317
|
-
currentStage: "registration",
|
|
1318
|
-
completedPercentage: 0,
|
|
1319
|
-
createdResources: []
|
|
1320
|
-
};
|
|
1321
|
-
if (progressCallback) {
|
|
1322
|
-
progressCallback({
|
|
1323
|
-
stage: "preparing",
|
|
1324
|
-
message: "Preparing agent registration",
|
|
1325
|
-
progressPercent: 10,
|
|
1326
|
-
details: {
|
|
1327
|
-
state
|
|
1328
|
-
}
|
|
1329
|
-
});
|
|
1330
|
-
}
|
|
1331
|
-
const registrationResult = await this.executeRegistration(
|
|
1332
|
-
accountId,
|
|
1333
|
-
network,
|
|
1334
|
-
this.guardedRegistryBaseUrl,
|
|
1335
|
-
this.logger
|
|
1336
|
-
);
|
|
1337
|
-
if (!registrationResult.success) {
|
|
1338
|
-
return {
|
|
1339
|
-
...registrationResult,
|
|
1340
|
-
state
|
|
1341
|
-
};
|
|
1342
|
-
}
|
|
1343
|
-
if (progressCallback) {
|
|
1344
|
-
progressCallback({
|
|
1345
|
-
stage: "submitting",
|
|
1346
|
-
message: "Submitting registration to registry",
|
|
1347
|
-
progressPercent: 30,
|
|
1348
|
-
details: {
|
|
1349
|
-
transactionId: registrationResult.transactionId,
|
|
1350
|
-
state
|
|
1351
|
-
}
|
|
1352
|
-
});
|
|
1353
|
-
}
|
|
1354
|
-
if (registrationResult.transaction) {
|
|
1355
|
-
const transaction = Transaction.fromBytes(
|
|
1356
|
-
Buffer.from(registrationResult.transaction, "base64")
|
|
1357
|
-
);
|
|
1358
|
-
this.logger.info(`Processing registration transaction`);
|
|
1359
|
-
await transaction.execute(this.client);
|
|
1360
|
-
this.logger.info(`Successfully processed registration transaction`);
|
|
1361
|
-
}
|
|
1362
|
-
if (progressCallback) {
|
|
1363
|
-
progressCallback({
|
|
1364
|
-
stage: "confirming",
|
|
1365
|
-
message: "Confirming registration transaction",
|
|
1366
|
-
progressPercent: 60,
|
|
1367
|
-
details: {
|
|
1368
|
-
accountId,
|
|
1369
|
-
transactionId: registrationResult.transactionId,
|
|
1370
|
-
state
|
|
1371
|
-
}
|
|
1372
|
-
});
|
|
1373
|
-
}
|
|
1374
|
-
const confirmed = await this.waitForRegistrationConfirmation(
|
|
1375
|
-
registrationResult.transactionId,
|
|
1376
|
-
network,
|
|
1377
|
-
this.guardedRegistryBaseUrl,
|
|
1378
|
-
maxAttempts,
|
|
1379
|
-
delayMs,
|
|
1380
|
-
this.logger
|
|
1381
|
-
);
|
|
1382
|
-
state.currentStage = "complete";
|
|
1383
|
-
state.completedPercentage = 100;
|
|
1384
|
-
if (!state.createdResources) {
|
|
1385
|
-
state.createdResources = [];
|
|
1386
|
-
}
|
|
1387
|
-
if (registrationResult.transactionId) {
|
|
1388
|
-
state.createdResources.push(
|
|
1389
|
-
`registration:${registrationResult.transactionId}`
|
|
1390
|
-
);
|
|
1391
|
-
}
|
|
1392
|
-
if (progressCallback) {
|
|
1393
|
-
progressCallback({
|
|
1394
|
-
stage: "completed",
|
|
1395
|
-
message: "Agent registration complete",
|
|
1396
|
-
progressPercent: 100,
|
|
1397
|
-
details: {
|
|
1398
|
-
confirmed,
|
|
1399
|
-
transactionId: registrationResult.transactionId,
|
|
1400
|
-
state
|
|
1401
|
-
}
|
|
1402
|
-
});
|
|
1403
|
-
}
|
|
1404
|
-
return {
|
|
1405
|
-
...registrationResult,
|
|
1406
|
-
confirmed,
|
|
1407
|
-
state
|
|
1408
|
-
};
|
|
1409
|
-
} catch (e) {
|
|
1410
|
-
const error = e;
|
|
1411
|
-
const logMessage = `Failed to register agent: ${error.message}`;
|
|
1412
|
-
this.logger.error(logMessage);
|
|
1413
|
-
return {
|
|
1414
|
-
error: error.message,
|
|
1415
|
-
success: false
|
|
1416
|
-
};
|
|
1417
|
-
}
|
|
1418
|
-
}
|
|
1419
|
-
/**
|
|
1420
|
-
* Registers an agent with the guarded registry. Should be called by a registry.
|
|
1421
|
-
* @param registryTopicId - The topic ID of the guarded registry.
|
|
1422
|
-
* @param accountId - The account ID of the agent
|
|
1423
|
-
* @param inboundTopicId - The topic ID of the inbound topic
|
|
1424
|
-
* @param memo - The memo of the agent
|
|
1425
|
-
* @param submitKey - The submit key of the agent
|
|
1426
|
-
*/
|
|
1427
|
-
async registerAgent(registryTopicId, accountId, inboundTopicId, memo, submitKey) {
|
|
1428
|
-
this.logger.info("Registering agent");
|
|
1429
|
-
const transaction = buildHcs10RegistryRegisterTx({
|
|
1430
|
-
registryTopicId,
|
|
1431
|
-
accountId,
|
|
1432
|
-
inboundTopicId,
|
|
1433
|
-
memo
|
|
1434
|
-
});
|
|
1435
|
-
await this.submitPayload(transaction, void 0, submitKey);
|
|
1436
|
-
}
|
|
1437
|
-
async getInboundTopicType(topicId) {
|
|
1438
|
-
try {
|
|
1439
|
-
const topicInfo = await this.mirrorNode.getTopicInfo(topicId);
|
|
1440
|
-
if (!topicInfo) {
|
|
1441
|
-
throw new Error("Topic does not exist");
|
|
1442
|
-
}
|
|
1443
|
-
const hasSubmitKey = topicInfo.submit_key && topicInfo.submit_key.key;
|
|
1444
|
-
if (!hasSubmitKey) {
|
|
1445
|
-
return InboundTopicType.PUBLIC;
|
|
1446
|
-
}
|
|
1447
|
-
const hasFeeScheduleKey = topicInfo.fee_schedule_key && topicInfo.fee_schedule_key.key;
|
|
1448
|
-
if (hasFeeScheduleKey && topicInfo.custom_fees) {
|
|
1449
|
-
const customFees = topicInfo.custom_fees;
|
|
1450
|
-
if (customFees && customFees.fixed_fees && customFees.fixed_fees.length > 0) {
|
|
1451
|
-
this.logger.info(
|
|
1452
|
-
`Topic ${topicId} is fee-based with ${customFees.fixed_fees.length} custom fees`
|
|
1453
|
-
);
|
|
1454
|
-
return InboundTopicType.FEE_BASED;
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
return InboundTopicType.CONTROLLED;
|
|
1458
|
-
} catch (e) {
|
|
1459
|
-
const error = e;
|
|
1460
|
-
const logMessage = `Error determining topic type: ${error.message}`;
|
|
1461
|
-
this.logger.error(logMessage);
|
|
1462
|
-
throw new Error(logMessage);
|
|
1463
|
-
}
|
|
1464
|
-
}
|
|
1465
|
-
getNetwork() {
|
|
1466
|
-
return this.network;
|
|
1467
|
-
}
|
|
1468
|
-
getLogger() {
|
|
1469
|
-
return this.logger;
|
|
1470
|
-
}
|
|
1471
|
-
/**
|
|
1472
|
-
* Public method to get the operator account ID configured for this client instance.
|
|
1473
|
-
* @returns The operator account ID string, or null if not set.
|
|
1474
|
-
*/
|
|
1475
|
-
getOperatorAccountId() {
|
|
1476
|
-
return this.client.operatorAccountId?.toString() ?? null;
|
|
1477
|
-
}
|
|
1478
|
-
/**
|
|
1479
|
-
* Creates a scheduled transaction from a transaction object
|
|
1480
|
-
* @param transaction The transaction to schedule
|
|
1481
|
-
* @param memo Optional memo to include with the scheduled transaction
|
|
1482
|
-
* @param expirationTime Optional expiration time in seconds from now
|
|
1483
|
-
* @returns Object with schedule ID and transaction ID
|
|
1484
|
-
*/
|
|
1485
|
-
async createScheduledTransaction(transaction, memo, expirationTime, schedulePayerAccountId) {
|
|
1486
|
-
this.logger.info("Creating scheduled transaction");
|
|
1487
|
-
const scheduleTransaction = new ScheduleCreateTransaction().setScheduledTransaction(transaction).setPayerAccountId(
|
|
1488
|
-
schedulePayerAccountId ? AccountId.fromString(schedulePayerAccountId) : this.client.operatorAccountId
|
|
1489
|
-
);
|
|
1490
|
-
if (memo) {
|
|
1491
|
-
scheduleTransaction.setScheduleMemo(memo);
|
|
1492
|
-
}
|
|
1493
|
-
if (expirationTime) {
|
|
1494
|
-
const expirationDate = addSeconds(/* @__PURE__ */ new Date(), expirationTime);
|
|
1495
|
-
const timestamp = Timestamp.fromDate(expirationDate);
|
|
1496
|
-
scheduleTransaction.setExpirationTime(timestamp);
|
|
1497
|
-
}
|
|
1498
|
-
const scheduleResponse = await scheduleTransaction.execute(this.client);
|
|
1499
|
-
const scheduleReceipt = await scheduleResponse.getReceipt(this.client);
|
|
1500
|
-
if (!scheduleReceipt.scheduleId) {
|
|
1501
|
-
this.logger.error(
|
|
1502
|
-
"Failed to create scheduled transaction: scheduleId is null"
|
|
1503
|
-
);
|
|
1504
|
-
throw new Error(
|
|
1505
|
-
"Failed to create scheduled transaction: scheduleId is null"
|
|
1506
|
-
);
|
|
1507
|
-
}
|
|
1508
|
-
const scheduleId = scheduleReceipt.scheduleId.toString();
|
|
1509
|
-
const transactionId = scheduleResponse.transactionId.toString();
|
|
1510
|
-
this.logger.info(
|
|
1511
|
-
`Scheduled transaction created successfully: ${scheduleId}`
|
|
1512
|
-
);
|
|
1513
|
-
return {
|
|
1514
|
-
scheduleId,
|
|
1515
|
-
transactionId
|
|
1516
|
-
};
|
|
1517
|
-
}
|
|
1518
|
-
/**
|
|
1519
|
-
* Sends a transaction operation on a connection topic
|
|
1520
|
-
* @param connectionTopicId Connection topic ID
|
|
1521
|
-
* @param scheduleId Schedule ID of the scheduled transaction
|
|
1522
|
-
* @param data Human-readable description of the transaction, can also be a JSON string or HRL
|
|
1523
|
-
* @param submitKey Optional submit key
|
|
1524
|
-
* @param options Optional parameters including memo (timestamp is no longer used here)
|
|
1525
|
-
* @returns Transaction receipt
|
|
1526
|
-
*/
|
|
1527
|
-
async sendTransactionOperation(connectionTopicId, scheduleId, data, submitKey, options) {
|
|
1528
|
-
const submissionCheck = await this.canSubmitToTopic(
|
|
1529
|
-
connectionTopicId,
|
|
1530
|
-
this.client.operatorAccountId?.toString() || ""
|
|
1531
|
-
);
|
|
1532
|
-
const operatorId = await this.getOperatorId();
|
|
1533
|
-
const payload = {
|
|
1534
|
-
p: "hcs-10",
|
|
1535
|
-
op: "transaction",
|
|
1536
|
-
operator_id: operatorId,
|
|
1537
|
-
schedule_id: scheduleId,
|
|
1538
|
-
data,
|
|
1539
|
-
m: options?.memo
|
|
1540
|
-
};
|
|
1541
|
-
this.logger.info(
|
|
1542
|
-
"Submitting transaction operation to connection topic",
|
|
1543
|
-
payload
|
|
1544
|
-
);
|
|
1545
|
-
return await this.submitPayload(
|
|
1546
|
-
connectionTopicId,
|
|
1547
|
-
payload,
|
|
1548
|
-
submitKey,
|
|
1549
|
-
submissionCheck.requiresFee
|
|
1550
|
-
);
|
|
1551
|
-
}
|
|
1552
|
-
/**
|
|
1553
|
-
* Creates and sends a transaction operation in one call
|
|
1554
|
-
* @param connectionTopicId Connection topic ID for sending the transaction operation
|
|
1555
|
-
* @param transaction The transaction to schedule
|
|
1556
|
-
* @param data Human-readable description of the transaction, can also be a JSON string or HRL
|
|
1557
|
-
* @param options Optional parameters for schedule creation and operation memo
|
|
1558
|
-
* @returns Object with schedule details (including scheduleId and its transactionId) and HCS-10 operation receipt
|
|
1559
|
-
*/
|
|
1560
|
-
async sendTransaction(connectionTopicId, transaction, data, options) {
|
|
1561
|
-
this.logger.info(
|
|
1562
|
-
"Creating scheduled transaction and sending transaction operation"
|
|
1563
|
-
);
|
|
1564
|
-
const { scheduleId, transactionId } = await this.createScheduledTransaction(
|
|
1565
|
-
transaction,
|
|
1566
|
-
options?.scheduleMemo,
|
|
1567
|
-
options?.expirationTime,
|
|
1568
|
-
options?.schedulePayerAccountId
|
|
1569
|
-
);
|
|
1570
|
-
const receipt = await this.sendTransactionOperation(
|
|
1571
|
-
connectionTopicId,
|
|
1572
|
-
scheduleId,
|
|
1573
|
-
data,
|
|
1574
|
-
options?.submitKey,
|
|
1575
|
-
{
|
|
1576
|
-
memo: options?.operationMemo
|
|
1577
|
-
}
|
|
1578
|
-
);
|
|
1579
|
-
return {
|
|
1580
|
-
scheduleId,
|
|
1581
|
-
transactionId,
|
|
1582
|
-
receipt
|
|
1583
|
-
};
|
|
1584
|
-
}
|
|
1585
|
-
/**
|
|
1586
|
-
* Creates communication topics (inbound and outbound) for a profile.
|
|
1587
|
-
* Helper method used by the create method.
|
|
1588
|
-
*/
|
|
1589
|
-
async createCommunicationTopics(accountId, options, progressReporter) {
|
|
1590
|
-
let state = options?.existingState || {
|
|
1591
|
-
currentStage: "init",
|
|
1592
|
-
completedPercentage: 0,
|
|
1593
|
-
createdResources: []
|
|
1594
|
-
};
|
|
1595
|
-
if (progressReporter) {
|
|
1596
|
-
progressReporter.preparing("Starting communication topic creation", 0, {
|
|
1597
|
-
state
|
|
1598
|
-
});
|
|
1599
|
-
}
|
|
1600
|
-
if (!state.outboundTopicId) {
|
|
1601
|
-
state.currentStage = "topics";
|
|
1602
|
-
if (progressReporter) {
|
|
1603
|
-
progressReporter.preparing("Creating outbound topic", 5, {
|
|
1604
|
-
state
|
|
1605
|
-
});
|
|
1606
|
-
}
|
|
1607
|
-
const operatorPublicKey = this.client.operatorPublicKey || this.operatorCtx.operatorKey.publicKey;
|
|
1608
|
-
const outboundTopicTx = buildHcs10CreateOutboundTopicTx({
|
|
1609
|
-
ttl: options?.ttl ?? 60,
|
|
1610
|
-
adminKey: true,
|
|
1611
|
-
submitKey: true,
|
|
1612
|
-
operatorPublicKey
|
|
1613
|
-
});
|
|
1614
|
-
const { topicId: outboundTopicId } = await this.executeTopicCreateTransaction({
|
|
1615
|
-
transaction: outboundTopicTx
|
|
1616
|
-
});
|
|
1617
|
-
state.outboundTopicId = outboundTopicId;
|
|
1618
|
-
if (state.createdResources)
|
|
1619
|
-
state.createdResources.push(`outbound:${state.outboundTopicId}`);
|
|
1620
|
-
}
|
|
1621
|
-
if (!state.inboundTopicId) {
|
|
1622
|
-
state.currentStage = "topics";
|
|
1623
|
-
if (progressReporter) {
|
|
1624
|
-
progressReporter.preparing("Creating inbound topic", 10, {
|
|
1625
|
-
state
|
|
1626
|
-
});
|
|
1627
|
-
}
|
|
1628
|
-
const operatorPublicKey = this.client.operatorPublicKey || this.operatorCtx.operatorKey.publicKey;
|
|
1629
|
-
const inboundTopicTx = buildHcs10CreateInboundTopicTx({
|
|
1630
|
-
accountId,
|
|
1631
|
-
ttl: options?.ttl ?? 60,
|
|
1632
|
-
adminKey: true,
|
|
1633
|
-
submitKey: false,
|
|
1634
|
-
operatorPublicKey
|
|
1635
|
-
});
|
|
1636
|
-
const { topicId: inboundTopicId } = await this.executeTopicCreateTransaction({
|
|
1637
|
-
transaction: inboundTopicTx
|
|
1638
|
-
});
|
|
1639
|
-
state.inboundTopicId = inboundTopicId;
|
|
1640
|
-
if (state.createdResources)
|
|
1641
|
-
state.createdResources.push(`inbound:${state.inboundTopicId}`);
|
|
1642
|
-
}
|
|
1643
|
-
return {
|
|
1644
|
-
inboundTopicId: state.inboundTopicId,
|
|
1645
|
-
outboundTopicId: state.outboundTopicId,
|
|
1646
|
-
state
|
|
1647
|
-
};
|
|
1648
|
-
}
|
|
1649
|
-
/**
|
|
1650
|
-
* Handles profile picture creation by inscribing it.
|
|
1651
|
-
* Helper method used by the create method.
|
|
1652
|
-
*/
|
|
1653
|
-
async handleProfilePictureCreation(pfpBuffer, pfpFileName, state, progressReporter) {
|
|
1654
|
-
state.currentStage = "pfp";
|
|
1655
|
-
progressReporter.preparing("Creating profile picture", 30, {
|
|
1656
|
-
state
|
|
1657
|
-
});
|
|
1658
|
-
progressReporter.createSubProgress({
|
|
1659
|
-
minPercent: 30,
|
|
1660
|
-
maxPercent: 50,
|
|
1661
|
-
logPrefix: "PFP"
|
|
1662
|
-
});
|
|
1663
|
-
const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName);
|
|
1664
|
-
if (!pfpResult.success) {
|
|
1665
|
-
let errorMessage = "Failed to inscribe profile picture";
|
|
1666
|
-
if (pfpResult.error) {
|
|
1667
|
-
errorMessage = pfpResult.error;
|
|
1668
|
-
}
|
|
1669
|
-
throw new Error(errorMessage);
|
|
1670
|
-
}
|
|
1671
|
-
const pfpTopicId = pfpResult.pfpTopicId;
|
|
1672
|
-
state.pfpTopicId = pfpTopicId;
|
|
1673
|
-
if (state.createdResources) {
|
|
1674
|
-
state.createdResources.push(`pfp:${state.pfpTopicId}`);
|
|
1675
|
-
}
|
|
1676
|
-
progressReporter.preparing("Profile picture created", 50, { state });
|
|
1677
|
-
return pfpTopicId;
|
|
1678
|
-
}
|
|
1679
|
-
/**
|
|
1680
|
-
* Creates and inscribes the HCS-11 profile.
|
|
1681
|
-
* Helper method used by the create method.
|
|
1682
|
-
*/
|
|
1683
|
-
async createAndInscribeProfile(isAgentBuilder, builder, pfpTopicId, state, inboundTopicId, outboundTopicId, options, progressReporter) {
|
|
1684
|
-
this.logger.info("Creating and inscribing profile");
|
|
1685
|
-
if (!state.profileTopicId) {
|
|
1686
|
-
if (progressReporter) {
|
|
1687
|
-
progressReporter.preparing(
|
|
1688
|
-
`Storing HCS-11 ${isAgentBuilder ? "agent" : "person"} profile`,
|
|
1689
|
-
80
|
|
1690
|
-
);
|
|
1691
|
-
}
|
|
1692
|
-
progressReporter?.createSubProgress({
|
|
1693
|
-
minPercent: 80,
|
|
1694
|
-
maxPercent: 95,
|
|
1695
|
-
logPrefix: "StoreProfile"
|
|
403
|
+
const profileProgress = progressReporter?.createSubProgress({
|
|
404
|
+
minPercent: 80,
|
|
405
|
+
maxPercent: 95,
|
|
406
|
+
logPrefix: "StoreProfile"
|
|
1696
407
|
});
|
|
1697
408
|
let hcs11Profile;
|
|
1698
409
|
if (isAgentBuilder) {
|
|
@@ -1737,7 +448,13 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
1737
448
|
}
|
|
1738
449
|
const profileResult = await this.hcs11Client.createAndInscribeProfile(
|
|
1739
450
|
hcs11Profile,
|
|
1740
|
-
options?.updateAccountMemo ?? true
|
|
451
|
+
options?.updateAccountMemo ?? true,
|
|
452
|
+
{
|
|
453
|
+
progressCallback: (data) => profileProgress?.report({
|
|
454
|
+
...data,
|
|
455
|
+
progressPercent: data.progressPercent ?? 0
|
|
456
|
+
})
|
|
457
|
+
}
|
|
1741
458
|
);
|
|
1742
459
|
if (!profileResult.success) {
|
|
1743
460
|
if (progressReporter) {
|
|
@@ -1771,502 +488,249 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
1771
488
|
);
|
|
1772
489
|
}
|
|
1773
490
|
}
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
* @param existingState Optional existing state to resume from
|
|
1784
|
-
* @returns Object with topic IDs
|
|
1785
|
-
*/
|
|
1786
|
-
async createMCPServer(builder, ttl = 60, existingState, progressCallback) {
|
|
1787
|
-
await this.ensureInitialized();
|
|
1788
|
-
const config = builder.build();
|
|
1789
|
-
const accountId = this.client.operatorAccountId?.toString();
|
|
1790
|
-
if (!accountId) {
|
|
1791
|
-
throw new Error("Failed to retrieve operator account ID");
|
|
491
|
+
initializeRegistrationState(inboundTopicId, existingState) {
|
|
492
|
+
const state = existingState || {
|
|
493
|
+
inboundTopicId,
|
|
494
|
+
currentStage: "registration",
|
|
495
|
+
completedPercentage: 0,
|
|
496
|
+
createdResources: []
|
|
497
|
+
};
|
|
498
|
+
if (state.currentStage !== "registration" && state.currentStage !== "complete") {
|
|
499
|
+
state.currentStage = "registration";
|
|
1792
500
|
}
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
this.logger.info("Creating and storing HCS-11 MCP server profile");
|
|
1810
|
-
if (progressCallback) {
|
|
1811
|
-
progressCallback({
|
|
1812
|
-
stage: "preparing",
|
|
1813
|
-
message: "Creating MCP server profile",
|
|
1814
|
-
progressPercent: 60,
|
|
1815
|
-
details: {
|
|
1816
|
-
outboundTopicId: result.outboundTopicId,
|
|
1817
|
-
inboundTopicId: result.inboundTopicId,
|
|
1818
|
-
pfpTopicId: result.pfpTopicId,
|
|
1819
|
-
state: {
|
|
1820
|
-
currentStage: "profile",
|
|
1821
|
-
completedPercentage: 60
|
|
1822
|
-
}
|
|
1823
|
-
}
|
|
1824
|
-
});
|
|
1825
|
-
}
|
|
1826
|
-
await this.hcs11Client.initializeOperator();
|
|
1827
|
-
const profile = this.hcs11Client.createMCPServerProfile(
|
|
1828
|
-
config.name,
|
|
1829
|
-
config.mcpServer,
|
|
1830
|
-
{
|
|
1831
|
-
alias: config.alias,
|
|
1832
|
-
bio: config.bio,
|
|
1833
|
-
socials: config.socials || [],
|
|
1834
|
-
inboundTopicId: result.inboundTopicId,
|
|
1835
|
-
outboundTopicId: result.outboundTopicId,
|
|
1836
|
-
profileImage: result.pfpTopicId ? `hcs://1/${result.pfpTopicId}` : void 0
|
|
1837
|
-
}
|
|
1838
|
-
);
|
|
1839
|
-
const profileResult = await this.hcs11Client.inscribeProfile(profile);
|
|
1840
|
-
if (!profileResult.success) {
|
|
1841
|
-
this.logger.error(
|
|
1842
|
-
`Failed to inscribe MCP server profile: ${profileResult.error}`
|
|
1843
|
-
);
|
|
1844
|
-
throw new Error(
|
|
1845
|
-
profileResult.error || "Failed to inscribe MCP server profile"
|
|
1846
|
-
);
|
|
1847
|
-
}
|
|
1848
|
-
result.profileTopicId = profileResult.profileTopicId;
|
|
1849
|
-
this.logger.info(
|
|
1850
|
-
`MCP server profile stored with topic ID: ${result.profileTopicId}`
|
|
1851
|
-
);
|
|
1852
|
-
const memoResult = await this.hcs11Client.updateAccountMemoWithProfile(
|
|
1853
|
-
accountId,
|
|
1854
|
-
result.profileTopicId
|
|
1855
|
-
);
|
|
1856
|
-
if (!memoResult.success) {
|
|
1857
|
-
this.logger.warn(
|
|
1858
|
-
`Failed to update account memo: ${memoResult.error}, but continuing with MCP server creation`
|
|
1859
|
-
);
|
|
501
|
+
return state;
|
|
502
|
+
}
|
|
503
|
+
updateStateForCompletedRegistration(state, inboundTopicId) {
|
|
504
|
+
state.currentStage = "complete";
|
|
505
|
+
state.completedPercentage = 100;
|
|
506
|
+
if (state.createdResources) {
|
|
507
|
+
state.createdResources.push(`registration:${inboundTopicId}`);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
async registerAgentWithGuardedRegistry(accountId, network = this.network, options) {
|
|
511
|
+
try {
|
|
512
|
+
this.logger.info("Registering agent with guarded registry");
|
|
513
|
+
let inboundTopicId;
|
|
514
|
+
if (options?.existingState?.inboundTopicId) {
|
|
515
|
+
this.logger.info("Using inboundTopicId from existing state");
|
|
516
|
+
inboundTopicId = options.existingState.inboundTopicId;
|
|
1860
517
|
} else {
|
|
1861
|
-
this.
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
pfpTopicId: result.pfpTopicId,
|
|
1872
|
-
profileTopicId: result.profileTopicId,
|
|
518
|
+
const profileResponse = await this.retrieveProfile(accountId, false, {
|
|
519
|
+
maxRetries: 5,
|
|
520
|
+
retryDelay: 3e3
|
|
521
|
+
});
|
|
522
|
+
if (!profileResponse.success || !profileResponse.profile || !profileResponse.topicInfo) {
|
|
523
|
+
const errorMessage = profileResponse.error || `Failed to retrieve profile for account ${accountId}. Make sure the agent profile is created and memo is updated before registration.`;
|
|
524
|
+
this.logger.error(errorMessage);
|
|
525
|
+
return {
|
|
526
|
+
error: errorMessage,
|
|
527
|
+
success: false,
|
|
1873
528
|
state: {
|
|
1874
|
-
currentStage: "
|
|
1875
|
-
completedPercentage:
|
|
529
|
+
currentStage: "registration",
|
|
530
|
+
completedPercentage: 0,
|
|
531
|
+
error: errorMessage
|
|
1876
532
|
}
|
|
1877
|
-
}
|
|
1878
|
-
}
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
inboundTopicId = profileResponse.topicInfo.inboundTopic;
|
|
1879
536
|
}
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
537
|
+
const state = this.initializeRegistrationState(
|
|
538
|
+
inboundTopicId,
|
|
539
|
+
options?.existingState
|
|
1883
540
|
);
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
* Creates the base topic structure for an entity (agent or MCP server).
|
|
1889
|
-
*
|
|
1890
|
-
* @param ttl Time-To-Live for topic memos
|
|
1891
|
-
* @param existingTopics Object containing any existing topic IDs to reuse
|
|
1892
|
-
* @param accountId The account ID associated with the entity
|
|
1893
|
-
* @param inboundTopicType Type of inbound topic
|
|
1894
|
-
* @param feeConfig Optional fee configuration for fee-based topics
|
|
1895
|
-
* @param pfpBuffer Optional profile picture buffer
|
|
1896
|
-
* @param pfpFileName Optional profile picture filename
|
|
1897
|
-
* @param progressCallback Optional callback for reporting progress
|
|
1898
|
-
* @returns Object with created topic IDs
|
|
1899
|
-
*/
|
|
1900
|
-
async _createEntityTopics(ttl, existingTopics, accountId, inboundTopicType, feeConfig, pfpBuffer, pfpFileName, progressCallback) {
|
|
1901
|
-
let { outboundTopicId, inboundTopicId, pfpTopicId, profileTopicId } = existingTopics;
|
|
1902
|
-
if (!outboundTopicId) {
|
|
1903
|
-
const operatorPublicKey = this.client.operatorPublicKey || this.operatorCtx.operatorKey.publicKey;
|
|
1904
|
-
const outboundTransaction = buildHcs10CreateOutboundTopicTx({
|
|
1905
|
-
ttl,
|
|
1906
|
-
adminKey: true,
|
|
1907
|
-
submitKey: true,
|
|
1908
|
-
operatorPublicKey
|
|
541
|
+
const progressReporter = new ProgressReporter({
|
|
542
|
+
module: "AgentRegistration",
|
|
543
|
+
logger: this.logger,
|
|
544
|
+
callback: options?.progressCallback
|
|
1909
545
|
});
|
|
1910
|
-
|
|
1911
|
-
|
|
546
|
+
progressReporter.preparing("Preparing agent registration", 10, {
|
|
547
|
+
inboundTopicId,
|
|
548
|
+
accountId
|
|
1912
549
|
});
|
|
1913
|
-
|
|
1914
|
-
this.logger.info(`Created new outbound topic ID: ${outboundTopicId}`);
|
|
1915
|
-
if (progressCallback) {
|
|
1916
|
-
progressCallback({
|
|
1917
|
-
stage: "preparing",
|
|
1918
|
-
message: "Created outbound topic",
|
|
1919
|
-
progressPercent: 30,
|
|
1920
|
-
details: {
|
|
1921
|
-
outboundTopicId,
|
|
1922
|
-
state: {
|
|
1923
|
-
currentStage: "topics",
|
|
1924
|
-
completedPercentage: 30
|
|
1925
|
-
}
|
|
1926
|
-
}
|
|
1927
|
-
});
|
|
1928
|
-
}
|
|
1929
|
-
} else {
|
|
1930
|
-
this.logger.info(`Using existing outbound topic ID: ${outboundTopicId}`);
|
|
1931
|
-
}
|
|
1932
|
-
if (!inboundTopicId) {
|
|
1933
|
-
inboundTopicId = await this.createInboundTopic(
|
|
550
|
+
const registrationResult = await this.executeRegistration(
|
|
1934
551
|
accountId,
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
552
|
+
network,
|
|
553
|
+
this.guardedRegistryBaseUrl,
|
|
554
|
+
this.logger
|
|
1938
555
|
);
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
progressPercent: 40,
|
|
1945
|
-
details: {
|
|
1946
|
-
outboundTopicId,
|
|
1947
|
-
inboundTopicId,
|
|
1948
|
-
state: {
|
|
1949
|
-
currentStage: "topics",
|
|
1950
|
-
completedPercentage: 40
|
|
1951
|
-
}
|
|
1952
|
-
}
|
|
1953
|
-
});
|
|
1954
|
-
}
|
|
1955
|
-
} else {
|
|
1956
|
-
this.logger.info(`Using existing inbound topic ID: ${inboundTopicId}`);
|
|
1957
|
-
}
|
|
1958
|
-
if (!pfpTopicId && pfpBuffer && pfpBuffer.length > 0 && pfpFileName) {
|
|
1959
|
-
this.logger.info("Inscribing new profile picture");
|
|
1960
|
-
if (progressCallback) {
|
|
1961
|
-
progressCallback({
|
|
1962
|
-
stage: "preparing",
|
|
1963
|
-
message: "Inscribing profile picture",
|
|
1964
|
-
progressPercent: 50,
|
|
1965
|
-
details: {
|
|
1966
|
-
outboundTopicId,
|
|
1967
|
-
inboundTopicId,
|
|
1968
|
-
state: {
|
|
1969
|
-
currentStage: "pfp",
|
|
1970
|
-
completedPercentage: 50
|
|
1971
|
-
}
|
|
1972
|
-
}
|
|
1973
|
-
});
|
|
556
|
+
if (!registrationResult.success) {
|
|
557
|
+
return {
|
|
558
|
+
...registrationResult,
|
|
559
|
+
state
|
|
560
|
+
};
|
|
1974
561
|
}
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
}
|
|
1994
|
-
}
|
|
562
|
+
progressReporter.submitting("Submitting registration to registry", 30, {
|
|
563
|
+
transactionId: registrationResult.transactionId
|
|
564
|
+
});
|
|
565
|
+
if (registrationResult.transaction) {
|
|
566
|
+
const transaction = Transaction.fromBytes(
|
|
567
|
+
Buffer.from(registrationResult.transaction, "base64")
|
|
568
|
+
);
|
|
569
|
+
this.logger.info(`Processing registration transaction`);
|
|
570
|
+
const txResult = await this.hwc.executeTransactionWithErrorHandling(
|
|
571
|
+
transaction,
|
|
572
|
+
true
|
|
573
|
+
);
|
|
574
|
+
if (txResult.error) {
|
|
575
|
+
return {
|
|
576
|
+
...registrationResult,
|
|
577
|
+
error: txResult.error,
|
|
578
|
+
success: false,
|
|
579
|
+
state
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
this.logger.info(`Successfully processed registration transaction`);
|
|
1995
583
|
}
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
584
|
+
progressReporter.confirming("Confirming registration transaction", 60, {
|
|
585
|
+
accountId,
|
|
586
|
+
inboundTopicId,
|
|
587
|
+
transactionId: registrationResult.transactionId
|
|
588
|
+
});
|
|
589
|
+
const maxAttempts = options?.maxAttempts ?? 60;
|
|
590
|
+
const delayMs = options?.delayMs ?? 2e3;
|
|
591
|
+
const confirmed = await this.waitForRegistrationConfirmation(
|
|
592
|
+
registrationResult.transactionId,
|
|
593
|
+
network,
|
|
594
|
+
this.guardedRegistryBaseUrl,
|
|
595
|
+
maxAttempts,
|
|
596
|
+
delayMs,
|
|
597
|
+
this.logger
|
|
1999
598
|
);
|
|
599
|
+
this.updateStateForCompletedRegistration(state, inboundTopicId);
|
|
600
|
+
progressReporter.completed("Agent registration complete", {
|
|
601
|
+
transactionId: registrationResult.transactionId,
|
|
602
|
+
inboundTopicId,
|
|
603
|
+
state,
|
|
604
|
+
confirmed
|
|
605
|
+
});
|
|
606
|
+
return {
|
|
607
|
+
...registrationResult,
|
|
608
|
+
confirmed,
|
|
609
|
+
state
|
|
610
|
+
};
|
|
611
|
+
} catch (error) {
|
|
612
|
+
this.logger.error(`Registration error: ${error.message}`);
|
|
613
|
+
return {
|
|
614
|
+
error: `Error during registration: ${error.message}`,
|
|
615
|
+
success: false,
|
|
616
|
+
state: {
|
|
617
|
+
currentStage: "registration",
|
|
618
|
+
completedPercentage: 0,
|
|
619
|
+
error: error.message
|
|
620
|
+
}
|
|
621
|
+
};
|
|
2000
622
|
}
|
|
2001
|
-
return {
|
|
2002
|
-
inboundTopicId,
|
|
2003
|
-
outboundTopicId,
|
|
2004
|
-
pfpTopicId,
|
|
2005
|
-
profileTopicId
|
|
2006
|
-
};
|
|
2007
623
|
}
|
|
2008
|
-
|
|
2009
|
-
* Creates and registers an MCP server with a Guarded registry.
|
|
2010
|
-
*
|
|
2011
|
-
* This function creates a new account if needed, initializes an HCS10 client,
|
|
2012
|
-
* creates an MCP server with inbound and outbound topics, and registers
|
|
2013
|
-
* it with the Hashgraph Online Guarded Registry.
|
|
2014
|
-
*
|
|
2015
|
-
* @param builder The MCP server builder object with configuration
|
|
2016
|
-
* @param options Optional settings for registration process
|
|
2017
|
-
* @returns Registration result with success status and metadata
|
|
2018
|
-
*/
|
|
2019
|
-
async createAndRegisterMCPServer(builder, options) {
|
|
624
|
+
async createAndRegisterAgent(builder, options) {
|
|
2020
625
|
try {
|
|
2021
|
-
const
|
|
626
|
+
const agentConfig = builder.build();
|
|
2022
627
|
const progressCallback = options?.progressCallback;
|
|
2023
|
-
const
|
|
628
|
+
const progressReporter = new ProgressReporter({
|
|
629
|
+
module: "AgentCreateRegister",
|
|
630
|
+
logger: this.logger,
|
|
631
|
+
callback: progressCallback
|
|
632
|
+
});
|
|
2024
633
|
let state = options?.existingState || {
|
|
2025
634
|
currentStage: "init",
|
|
2026
635
|
completedPercentage: 0,
|
|
2027
636
|
createdResources: []
|
|
2028
637
|
};
|
|
2029
|
-
state.
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
if (existingAccountId && config.existingAccount) {
|
|
2052
|
-
account = config.existingAccount;
|
|
2053
|
-
this.logger.info(
|
|
2054
|
-
`Resuming with existing account: ${existingAccountId}`
|
|
2055
|
-
);
|
|
2056
|
-
} else {
|
|
2057
|
-
account = await this.createAccount(options?.initialBalance);
|
|
2058
|
-
state.createdResources = state.createdResources || [];
|
|
2059
|
-
state.createdResources.push(`account:${account.accountId}`);
|
|
2060
|
-
}
|
|
2061
|
-
} else {
|
|
2062
|
-
account = await this.createAccount(options?.initialBalance);
|
|
2063
|
-
state.createdResources = state.createdResources || [];
|
|
2064
|
-
state.createdResources.push(`account:${account.accountId}`);
|
|
2065
|
-
}
|
|
2066
|
-
}
|
|
2067
|
-
if (progressCallback) {
|
|
2068
|
-
progressCallback({
|
|
2069
|
-
stage: "preparing",
|
|
2070
|
-
message: "Created account or using existing account",
|
|
2071
|
-
progressPercent: 20,
|
|
2072
|
-
details: { state, account }
|
|
2073
|
-
});
|
|
2074
|
-
}
|
|
2075
|
-
const resolver = new NodeOperatorResolver({
|
|
2076
|
-
mirrorNode: this.mirrorNode,
|
|
2077
|
-
logger: this.logger
|
|
2078
|
-
});
|
|
2079
|
-
const keyInfo = await resolver.resolveOperatorKey(
|
|
2080
|
-
account.accountId,
|
|
2081
|
-
account.privateKey
|
|
2082
|
-
);
|
|
2083
|
-
builder.setExistingAccount(account.accountId, account.privateKey);
|
|
2084
|
-
const privateKey = keyInfo.keyType === "ed25519" ? PrivateKey.fromStringED25519(account.privateKey) : PrivateKey.fromStringECDSA(account.privateKey);
|
|
2085
|
-
const publicKey = privateKey.publicKey.toString();
|
|
2086
|
-
serverClient = new HCS10Client({
|
|
2087
|
-
network: config.network,
|
|
2088
|
-
operatorId: account.accountId,
|
|
2089
|
-
operatorPrivateKey: account.privateKey,
|
|
2090
|
-
operatorPublicKey: publicKey,
|
|
2091
|
-
logLevel: "info",
|
|
2092
|
-
guardedRegistryBaseUrl: baseUrl
|
|
2093
|
-
});
|
|
2094
|
-
if (progressCallback) {
|
|
2095
|
-
progressCallback({
|
|
2096
|
-
stage: "preparing",
|
|
2097
|
-
message: "Initialized MCP server client",
|
|
2098
|
-
progressPercent: 25,
|
|
2099
|
-
details: { state }
|
|
2100
|
-
});
|
|
2101
|
-
}
|
|
2102
|
-
let outboundTopicId = state.outboundTopicId;
|
|
2103
|
-
let inboundTopicId = state.inboundTopicId;
|
|
2104
|
-
let pfpTopicId = state.pfpTopicId;
|
|
2105
|
-
let profileTopicId = state.profileTopicId;
|
|
2106
|
-
if (!outboundTopicId || !inboundTopicId || !profileTopicId) {
|
|
2107
|
-
if (pfpTopicId) {
|
|
2108
|
-
builder.setExistingProfilePicture(pfpTopicId);
|
|
2109
|
-
}
|
|
2110
|
-
const createResult = await serverClient.createMCPServer(
|
|
2111
|
-
builder,
|
|
2112
|
-
60,
|
|
2113
|
-
state,
|
|
2114
|
-
(data) => {
|
|
2115
|
-
if (progressCallback) {
|
|
2116
|
-
progressCallback({
|
|
2117
|
-
stage: data.stage,
|
|
2118
|
-
message: data.message,
|
|
2119
|
-
progressPercent: data.progressPercent || 0,
|
|
2120
|
-
details: {
|
|
2121
|
-
...data.details,
|
|
2122
|
-
state: {
|
|
2123
|
-
...state,
|
|
2124
|
-
...data.details?.state
|
|
2125
|
-
}
|
|
2126
|
-
}
|
|
2127
|
-
});
|
|
2128
|
-
}
|
|
2129
|
-
}
|
|
2130
|
-
);
|
|
2131
|
-
outboundTopicId = createResult.outboundTopicId;
|
|
2132
|
-
inboundTopicId = createResult.inboundTopicId;
|
|
2133
|
-
pfpTopicId = createResult.pfpTopicId;
|
|
2134
|
-
profileTopicId = createResult.profileTopicId;
|
|
2135
|
-
state.outboundTopicId = outboundTopicId;
|
|
2136
|
-
state.inboundTopicId = inboundTopicId;
|
|
2137
|
-
state.pfpTopicId = pfpTopicId;
|
|
2138
|
-
state.profileTopicId = profileTopicId;
|
|
2139
|
-
if (!state.createdResources) {
|
|
2140
|
-
state.createdResources = [];
|
|
2141
|
-
}
|
|
2142
|
-
if (pfpTopicId && !state.createdResources.includes(`pfp:${pfpTopicId}`)) {
|
|
2143
|
-
state.createdResources.push(`pfp:${pfpTopicId}`);
|
|
2144
|
-
}
|
|
2145
|
-
if (!state.createdResources.includes(`inbound:${inboundTopicId}`)) {
|
|
2146
|
-
state.createdResources.push(`inbound:${inboundTopicId}`);
|
|
2147
|
-
}
|
|
2148
|
-
if (!state.createdResources.includes(`outbound:${outboundTopicId}`)) {
|
|
2149
|
-
state.createdResources.push(`outbound:${outboundTopicId}`);
|
|
2150
|
-
}
|
|
2151
|
-
if (!state.createdResources.includes(`profile:${profileTopicId}`)) {
|
|
2152
|
-
state.createdResources.push(`profile:${profileTopicId}`);
|
|
2153
|
-
}
|
|
2154
|
-
}
|
|
2155
|
-
state.currentStage = "profile";
|
|
2156
|
-
state.completedPercentage = 60;
|
|
2157
|
-
if (progressCallback) {
|
|
2158
|
-
progressCallback({
|
|
2159
|
-
stage: "submitting",
|
|
2160
|
-
message: "Created MCP server with topics and profile",
|
|
2161
|
-
progressPercent: 60,
|
|
2162
|
-
details: {
|
|
2163
|
-
state,
|
|
2164
|
-
outboundTopicId,
|
|
2165
|
-
inboundTopicId,
|
|
2166
|
-
pfpTopicId,
|
|
2167
|
-
profileTopicId
|
|
2168
|
-
}
|
|
2169
|
-
});
|
|
638
|
+
state.agentMetadata = agentConfig.metadata;
|
|
639
|
+
progressReporter.preparing("Starting agent creation process", 0, {
|
|
640
|
+
state
|
|
641
|
+
});
|
|
642
|
+
if (state.currentStage !== "complete" || !state.inboundTopicId || !state.outboundTopicId || !state.profileTopicId) {
|
|
643
|
+
const createResult = await this.create(builder, {
|
|
644
|
+
progressCallback: (progress) => {
|
|
645
|
+
const adjustedPercent = (progress.progressPercent || 0) * 0.3;
|
|
646
|
+
progressReporter.report({
|
|
647
|
+
...progress,
|
|
648
|
+
progressPercent: adjustedPercent,
|
|
649
|
+
details: {
|
|
650
|
+
...progress.details,
|
|
651
|
+
state: progress.details?.state || state
|
|
652
|
+
}
|
|
653
|
+
});
|
|
654
|
+
},
|
|
655
|
+
existingState: state,
|
|
656
|
+
updateAccountMemo: true
|
|
657
|
+
});
|
|
658
|
+
if (!("state" in createResult)) {
|
|
659
|
+
throw new Error("Create method did not return expected agent state.");
|
|
2170
660
|
}
|
|
2171
|
-
|
|
2172
|
-
account = account || config.existingAccount;
|
|
2173
|
-
if (!account) {
|
|
661
|
+
if (!createResult.success) {
|
|
2174
662
|
throw new Error(
|
|
2175
|
-
"
|
|
663
|
+
createResult.error || "Failed to create agent resources"
|
|
2176
664
|
);
|
|
2177
665
|
}
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
network: config.network,
|
|
2183
|
-
operatorId: account.accountId,
|
|
2184
|
-
operatorPrivateKey: account.privateKey,
|
|
2185
|
-
operatorPublicKey: publicKey,
|
|
2186
|
-
keyType: keyType.detectedType,
|
|
2187
|
-
logLevel: "info",
|
|
2188
|
-
guardedRegistryBaseUrl: baseUrl
|
|
2189
|
-
});
|
|
2190
|
-
this.logger.info("Resuming registration with existing state", {
|
|
2191
|
-
inboundTopicId: state.inboundTopicId,
|
|
2192
|
-
outboundTopicId: state.outboundTopicId,
|
|
2193
|
-
profileTopicId: state.profileTopicId,
|
|
2194
|
-
pfpTopicId: state.pfpTopicId
|
|
2195
|
-
});
|
|
666
|
+
state = createResult.state;
|
|
667
|
+
state.agentMetadata = agentConfig.metadata;
|
|
668
|
+
this.logger.info("Waiting for account memo update to propagate...");
|
|
669
|
+
await new Promise((resolve) => setTimeout(resolve, 5e3));
|
|
2196
670
|
}
|
|
2197
|
-
|
|
671
|
+
progressReporter.preparing(
|
|
672
|
+
`Agent creation status: ${state.currentStage}, ${state.completedPercentage}%`,
|
|
673
|
+
30,
|
|
674
|
+
{ state }
|
|
675
|
+
);
|
|
676
|
+
const { accountId } = this.getAccountAndSigner();
|
|
2198
677
|
if (state.currentStage !== "complete" || !state.createdResources?.includes(
|
|
2199
678
|
`registration:${state.inboundTopicId}`
|
|
2200
679
|
)) {
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
680
|
+
if (options?.baseUrl) {
|
|
681
|
+
this.guardedRegistryBaseUrl = options.baseUrl;
|
|
682
|
+
}
|
|
683
|
+
const registrationResult = await this.registerAgentWithGuardedRegistry(
|
|
684
|
+
accountId,
|
|
685
|
+
agentConfig.network,
|
|
2204
686
|
{
|
|
2205
|
-
progressCallback: (
|
|
2206
|
-
const adjustedPercent =
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
inboundTopicId: state.inboundTopicId,
|
|
2216
|
-
pfpTopicId: state.pfpTopicId,
|
|
2217
|
-
profileTopicId: state.profileTopicId,
|
|
2218
|
-
operatorId,
|
|
2219
|
-
state: data.details?.state || state
|
|
2220
|
-
}
|
|
2221
|
-
});
|
|
2222
|
-
}
|
|
687
|
+
progressCallback: (progress) => {
|
|
688
|
+
const adjustedPercent = 30 + (progress.progressPercent || 0) * 0.7;
|
|
689
|
+
progressReporter.report({
|
|
690
|
+
...progress,
|
|
691
|
+
progressPercent: adjustedPercent,
|
|
692
|
+
details: {
|
|
693
|
+
...progress.details,
|
|
694
|
+
state: progress.details?.state || state
|
|
695
|
+
}
|
|
696
|
+
});
|
|
2223
697
|
},
|
|
698
|
+
maxAttempts: options?.maxAttempts,
|
|
699
|
+
delayMs: options?.delayMs,
|
|
2224
700
|
existingState: state
|
|
2225
701
|
}
|
|
2226
702
|
);
|
|
2227
703
|
if (!registrationResult.success) {
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
};
|
|
704
|
+
throw new Error(
|
|
705
|
+
registrationResult.error || "Failed to register agent with registry"
|
|
706
|
+
);
|
|
2232
707
|
}
|
|
2233
|
-
state = registrationResult.state
|
|
2234
|
-
}
|
|
2235
|
-
if (progressCallback) {
|
|
2236
|
-
progressCallback({
|
|
2237
|
-
stage: "completed",
|
|
2238
|
-
message: "MCP server creation and registration complete",
|
|
2239
|
-
progressPercent: 100,
|
|
2240
|
-
details: {
|
|
2241
|
-
outboundTopicId: state.outboundTopicId,
|
|
2242
|
-
inboundTopicId: state.inboundTopicId,
|
|
2243
|
-
pfpTopicId: state.pfpTopicId,
|
|
2244
|
-
profileTopicId: state.profileTopicId,
|
|
2245
|
-
operatorId,
|
|
2246
|
-
state
|
|
2247
|
-
}
|
|
2248
|
-
});
|
|
708
|
+
state = registrationResult.state;
|
|
2249
709
|
}
|
|
710
|
+
progressReporter.completed("Agent creation and registration complete", {
|
|
711
|
+
state
|
|
712
|
+
});
|
|
2250
713
|
return {
|
|
2251
714
|
success: true,
|
|
2252
715
|
state,
|
|
2253
716
|
metadata: {
|
|
2254
|
-
accountId
|
|
2255
|
-
|
|
2256
|
-
operatorId,
|
|
717
|
+
accountId,
|
|
718
|
+
operatorId: `${state.inboundTopicId}@${accountId}`,
|
|
2257
719
|
inboundTopicId: state.inboundTopicId,
|
|
2258
720
|
outboundTopicId: state.outboundTopicId,
|
|
2259
721
|
profileTopicId: state.profileTopicId,
|
|
2260
|
-
pfpTopicId: state.pfpTopicId
|
|
722
|
+
pfpTopicId: state.pfpTopicId,
|
|
723
|
+
privateKey: null,
|
|
724
|
+
...state.agentMetadata
|
|
2261
725
|
}
|
|
2262
726
|
};
|
|
2263
|
-
} catch (
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
727
|
+
} catch (error) {
|
|
728
|
+
this.logger.error(
|
|
729
|
+
`Failed to create and register agent: ${error.message}`
|
|
730
|
+
);
|
|
2267
731
|
return {
|
|
2268
|
-
error: error.message,
|
|
2269
732
|
success: false,
|
|
733
|
+
error: `Failed to create and register agent: ${error.message}`,
|
|
2270
734
|
state: options?.existingState || {
|
|
2271
735
|
currentStage: "init",
|
|
2272
736
|
completedPercentage: 0,
|
|
@@ -2275,137 +739,419 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
2275
739
|
};
|
|
2276
740
|
}
|
|
2277
741
|
}
|
|
2278
|
-
|
|
2279
|
-
* Creates a new HCS-10 registry topic with optional metadata stored via HCS-1.
|
|
2280
|
-
*
|
|
2281
|
-
* Registry topics serve as directories for AI agent discovery and follow the
|
|
2282
|
-
* HCS-10 memo format: hcs-10:0:{ttl}:3:[metadataTopicId]
|
|
2283
|
-
*
|
|
2284
|
-
* @param options Configuration options for registry creation
|
|
2285
|
-
* @returns Promise resolving to registry creation result
|
|
2286
|
-
*/
|
|
2287
|
-
async createRegistryTopic(options = {}) {
|
|
2288
|
-
const {
|
|
2289
|
-
ttl = 86400,
|
|
2290
|
-
metadata,
|
|
2291
|
-
adminKey = false,
|
|
2292
|
-
submitKey = false,
|
|
2293
|
-
waitForConfirmation = true,
|
|
2294
|
-
waitMaxAttempts = 30,
|
|
2295
|
-
waitIntervalMs = 4e3,
|
|
2296
|
-
progressCallback
|
|
2297
|
-
} = options;
|
|
742
|
+
async storeHCS11Profile(agentName, agentBio, inboundTopicId, outboundTopicId, capabilities = [], metadata = {}, pfpBuffer, pfpFileName, existingPfpTopicId, options) {
|
|
2298
743
|
try {
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
744
|
+
const progressCallback = options?.progressCallback;
|
|
745
|
+
const progressReporter = new ProgressReporter({
|
|
746
|
+
module: "StoreHCS11Profile",
|
|
747
|
+
logger: this.logger,
|
|
748
|
+
callback: progressCallback
|
|
749
|
+
});
|
|
750
|
+
progressReporter.preparing("Preparing agent profile data", 0);
|
|
751
|
+
let pfpTopicId = existingPfpTopicId;
|
|
752
|
+
if (!pfpTopicId && pfpBuffer && pfpFileName) {
|
|
753
|
+
const pfpProgress = progressReporter.createSubProgress({
|
|
754
|
+
minPercent: 0,
|
|
755
|
+
maxPercent: 60,
|
|
756
|
+
logPrefix: "PFP"
|
|
2306
757
|
});
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
progressPercent: 30,
|
|
2316
|
-
details: { metadataName: metadata.name }
|
|
2317
|
-
});
|
|
2318
|
-
}
|
|
2319
|
-
const metadataBuffer = Buffer.from(JSON.stringify(metadata, null, 2));
|
|
2320
|
-
const inscriptionOptions = {
|
|
2321
|
-
mode: "file",
|
|
2322
|
-
waitForConfirmation,
|
|
2323
|
-
waitMaxAttempts,
|
|
2324
|
-
waitIntervalMs,
|
|
2325
|
-
logging: {
|
|
2326
|
-
level: this.logger.getLevel ? this.logger.getLevel() : "info"
|
|
758
|
+
const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName, {
|
|
759
|
+
progressCallback: (data) => {
|
|
760
|
+
pfpProgress.report({
|
|
761
|
+
stage: data.stage,
|
|
762
|
+
message: data.message,
|
|
763
|
+
progressPercent: data.progressPercent || 0,
|
|
764
|
+
details: data.details
|
|
765
|
+
});
|
|
2327
766
|
}
|
|
2328
|
-
};
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
},
|
|
2336
|
-
{
|
|
2337
|
-
accountId: this.client.operatorAccountId.toString(),
|
|
2338
|
-
privateKey: this.operatorCtx.operatorKey,
|
|
2339
|
-
network: this.network
|
|
2340
|
-
},
|
|
2341
|
-
inscriptionOptions
|
|
2342
|
-
);
|
|
2343
|
-
if (!inscription.confirmed || !inscription.inscription) {
|
|
2344
|
-
throw new Error("Metadata inscription was not confirmed");
|
|
767
|
+
});
|
|
768
|
+
if (!pfpResult.success) {
|
|
769
|
+
progressReporter.failed(
|
|
770
|
+
"Failed to inscribe profile picture, continuing without PFP"
|
|
771
|
+
);
|
|
772
|
+
} else {
|
|
773
|
+
pfpTopicId = pfpResult.pfpTopicId;
|
|
2345
774
|
}
|
|
2346
|
-
|
|
2347
|
-
|
|
775
|
+
} else if (existingPfpTopicId) {
|
|
776
|
+
progressReporter.preparing(
|
|
777
|
+
`Using existing profile picture: ${existingPfpTopicId}`,
|
|
778
|
+
30
|
|
779
|
+
);
|
|
780
|
+
} else {
|
|
781
|
+
progressReporter.preparing("No profile picture provided", 30);
|
|
2348
782
|
}
|
|
2349
|
-
if (
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
783
|
+
if (!this.hcs11Client) {
|
|
784
|
+
progressReporter.failed(
|
|
785
|
+
"HCS11Client is not available in this environment"
|
|
786
|
+
);
|
|
787
|
+
return {
|
|
788
|
+
profileTopicId: "",
|
|
789
|
+
success: false,
|
|
790
|
+
error: "HCS11Client is not available in this environment",
|
|
791
|
+
transactionId: ""
|
|
792
|
+
};
|
|
2356
793
|
}
|
|
2357
|
-
const
|
|
2358
|
-
|
|
2359
|
-
const transaction = buildHcs10CreateRegistryTopicTx({
|
|
2360
|
-
ttl,
|
|
2361
|
-
metadataTopicId,
|
|
2362
|
-
adminKey,
|
|
2363
|
-
submitKey,
|
|
2364
|
-
operatorPublicKey
|
|
794
|
+
const agentType = this.hcs11Client.getAgentTypeFromMetadata({
|
|
795
|
+
type: metadata.type || "autonomous"
|
|
2365
796
|
});
|
|
2366
|
-
|
|
2367
|
-
|
|
797
|
+
progressReporter.preparing("Building agent profile", 65);
|
|
798
|
+
const formattedSocials = metadata.socials ? Object.entries(metadata.socials).filter(([_, handle]) => handle).map(([platform, handle]) => ({
|
|
799
|
+
platform,
|
|
800
|
+
handle
|
|
801
|
+
})) : void 0;
|
|
802
|
+
const profile = this.hcs11Client.createAIAgentProfile(
|
|
803
|
+
agentName,
|
|
804
|
+
agentType,
|
|
805
|
+
capabilities,
|
|
806
|
+
metadata.model || "unknown",
|
|
807
|
+
{
|
|
808
|
+
alias: agentName.toLowerCase().replace(/\s+/g, "_"),
|
|
809
|
+
bio: agentBio,
|
|
810
|
+
profileImage: pfpTopicId ? `hcs://1/${pfpTopicId}` : void 0,
|
|
811
|
+
socials: formattedSocials,
|
|
812
|
+
properties: {
|
|
813
|
+
version: metadata.version || "1.0.0",
|
|
814
|
+
creator: metadata.creator || "Unknown",
|
|
815
|
+
supported_languages: metadata.supported_languages || ["en"],
|
|
816
|
+
permissions: metadata.permissions || [],
|
|
817
|
+
model_details: metadata.model_details,
|
|
818
|
+
training: metadata.training,
|
|
819
|
+
capabilities_description: metadata.capabilities_description,
|
|
820
|
+
...metadata
|
|
821
|
+
},
|
|
822
|
+
inboundTopicId,
|
|
823
|
+
outboundTopicId,
|
|
824
|
+
creator: metadata.creator
|
|
825
|
+
}
|
|
826
|
+
);
|
|
827
|
+
const profileProgress = progressReporter.createSubProgress({
|
|
828
|
+
minPercent: 65,
|
|
829
|
+
maxPercent: 100,
|
|
830
|
+
logPrefix: "Profile"
|
|
2368
831
|
});
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
832
|
+
const profileResult = await this.hcs11Client.createAndInscribeProfile(
|
|
833
|
+
profile,
|
|
834
|
+
options?.updateAccountMemo ?? true,
|
|
835
|
+
{
|
|
836
|
+
progressCallback: (profileData) => {
|
|
837
|
+
profileProgress.report({
|
|
838
|
+
stage: profileData.stage,
|
|
839
|
+
message: profileData.message,
|
|
840
|
+
progressPercent: profileData.progressPercent || 0,
|
|
841
|
+
details: profileData.details
|
|
842
|
+
});
|
|
2378
843
|
}
|
|
2379
|
-
}
|
|
844
|
+
}
|
|
845
|
+
);
|
|
846
|
+
if (!profileResult.success) {
|
|
847
|
+
progressReporter.failed("Failed to inscribe profile");
|
|
848
|
+
return {
|
|
849
|
+
profileTopicId: "",
|
|
850
|
+
success: false,
|
|
851
|
+
error: profileResult.error || "Failed to inscribe profile",
|
|
852
|
+
transactionId: profileResult.transactionId || ""
|
|
853
|
+
};
|
|
2380
854
|
}
|
|
2381
|
-
|
|
855
|
+
progressReporter.completed("Profile stored successfully", {
|
|
856
|
+
profileTopicId: profileResult.profileTopicId
|
|
857
|
+
});
|
|
2382
858
|
return {
|
|
859
|
+
profileTopicId: profileResult.profileTopicId,
|
|
860
|
+
pfpTopicId,
|
|
2383
861
|
success: true,
|
|
2384
|
-
|
|
2385
|
-
transactionId: txResponse.transactionId.toString(),
|
|
2386
|
-
metadataTopicId
|
|
862
|
+
transactionId: profileResult.transactionId || ""
|
|
2387
863
|
};
|
|
2388
864
|
} catch (error) {
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
865
|
+
this.logger.error(`Error storing HCS11 profile: ${error.message}`);
|
|
866
|
+
return {
|
|
867
|
+
profileTopicId: "",
|
|
868
|
+
success: false,
|
|
869
|
+
error: error.message,
|
|
870
|
+
transactionId: ""
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
async createTopic(memo, adminKey, submitKey) {
|
|
875
|
+
this.logger.info("Creating topic");
|
|
876
|
+
const { accountId, signer } = this.getAccountAndSigner();
|
|
877
|
+
const transaction = new TopicCreateTransaction().setTopicMemo(memo);
|
|
878
|
+
const publicKey = await this.mirrorNode.getPublicKey(accountId);
|
|
879
|
+
if (adminKey && publicKey) {
|
|
880
|
+
transaction.setAdminKey(publicKey);
|
|
881
|
+
transaction.setAutoRenewAccountId(accountId);
|
|
882
|
+
}
|
|
883
|
+
if (submitKey && publicKey) {
|
|
884
|
+
transaction.setSubmitKey(publicKey);
|
|
885
|
+
}
|
|
886
|
+
const transactionResponse = await this.hwc.executeTransactionWithErrorHandling(
|
|
887
|
+
transaction,
|
|
888
|
+
false
|
|
889
|
+
);
|
|
890
|
+
const error = transactionResponse.error;
|
|
891
|
+
if (error) {
|
|
892
|
+
this.logger.error(error);
|
|
893
|
+
return {
|
|
894
|
+
success: false,
|
|
895
|
+
error
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
const resultReceipt = transactionResponse.result;
|
|
899
|
+
if (!resultReceipt?.topicId) {
|
|
900
|
+
this.logger.error("Failed to create topic: topicId is null");
|
|
901
|
+
return {
|
|
902
|
+
success: false,
|
|
903
|
+
error: "Failed to create topic: topicId is null"
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
return {
|
|
907
|
+
success: true,
|
|
908
|
+
topicId: resultReceipt.topicId.toString()
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
async submitPayload(topicId, payload, submitKey, requiresFee) {
|
|
912
|
+
this.logger.debug(`Submitting payload to topic ${topicId}`);
|
|
913
|
+
let message;
|
|
914
|
+
if (typeof payload === "string") {
|
|
915
|
+
message = payload;
|
|
916
|
+
} else {
|
|
917
|
+
message = JSON.stringify(payload);
|
|
918
|
+
}
|
|
919
|
+
const transaction = new TopicMessageSubmitTransaction().setTopicId(topicId).setMessage(message);
|
|
920
|
+
const transactionMemo = this.getHcs10TransactionMemo(payload);
|
|
921
|
+
if (transactionMemo) {
|
|
922
|
+
transaction.setTransactionMemo(transactionMemo);
|
|
923
|
+
}
|
|
924
|
+
let transactionResponse;
|
|
925
|
+
if (requiresFee) {
|
|
926
|
+
this.logger.info(
|
|
927
|
+
"Topic requires fee payment, setting max transaction fee"
|
|
928
|
+
);
|
|
929
|
+
transaction.setMaxTransactionFee(new Hbar(this.feeAmount));
|
|
930
|
+
}
|
|
931
|
+
if (submitKey) {
|
|
932
|
+
const { signer } = this.getAccountAndSigner();
|
|
933
|
+
transaction.freezeWithSigner(signer);
|
|
934
|
+
const signedTransaction = await transaction.sign(submitKey);
|
|
935
|
+
transactionResponse = await this.hwc.executeTransactionWithErrorHandling(
|
|
936
|
+
signedTransaction,
|
|
937
|
+
true
|
|
938
|
+
);
|
|
939
|
+
} else {
|
|
940
|
+
transactionResponse = await this.hwc.executeTransactionWithErrorHandling(
|
|
941
|
+
transaction,
|
|
942
|
+
false
|
|
943
|
+
);
|
|
944
|
+
}
|
|
945
|
+
if (transactionResponse?.error) {
|
|
946
|
+
this.logger.error(
|
|
947
|
+
`Failed to submit payload: ${transactionResponse.error}`
|
|
948
|
+
);
|
|
949
|
+
throw new Error(`Failed to submit payload: ${transactionResponse.error}`);
|
|
950
|
+
}
|
|
951
|
+
if (!transactionResponse?.result) {
|
|
952
|
+
this.logger.error(
|
|
953
|
+
"Failed to submit message: receipt is null or undefined"
|
|
954
|
+
);
|
|
955
|
+
throw new Error("Failed to submit message: receipt is null or undefined");
|
|
956
|
+
}
|
|
957
|
+
this.logger.debug("Payload submitted successfully via HWC");
|
|
958
|
+
return transactionResponse.result;
|
|
959
|
+
}
|
|
960
|
+
async inscribeFile(buffer, fileName, options) {
|
|
961
|
+
const { accountId, signer } = this.getAccountAndSigner();
|
|
962
|
+
const mimeType = mime.lookup(fileName) || "application/octet-stream";
|
|
963
|
+
const sdk = await InscriptionSDK.createWithAuth({
|
|
964
|
+
type: "client",
|
|
965
|
+
accountId,
|
|
966
|
+
signer,
|
|
967
|
+
network: this.network
|
|
968
|
+
});
|
|
969
|
+
const inscriptionOptions = {
|
|
970
|
+
mode: "file",
|
|
971
|
+
waitForConfirmation: true,
|
|
972
|
+
waitMaxAttempts: options?.waitMaxAttempts || 30,
|
|
973
|
+
waitIntervalMs: options?.waitIntervalMs || 4e3,
|
|
974
|
+
progressCallback: options?.progressCallback,
|
|
975
|
+
logging: {
|
|
976
|
+
level: this.logger.getLevel ? this.logger.getLevel() : "info"
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
const response = await inscribeWithSigner(
|
|
980
|
+
{
|
|
981
|
+
type: "buffer",
|
|
982
|
+
buffer,
|
|
983
|
+
fileName,
|
|
984
|
+
mimeType
|
|
985
|
+
},
|
|
986
|
+
signer,
|
|
987
|
+
{
|
|
988
|
+
...inscriptionOptions,
|
|
989
|
+
network: this.network
|
|
990
|
+
},
|
|
991
|
+
sdk
|
|
992
|
+
);
|
|
993
|
+
if (!response.confirmed || !response.inscription) {
|
|
994
|
+
throw new Error("Inscription was not confirmed");
|
|
995
|
+
}
|
|
996
|
+
return response.inscription;
|
|
997
|
+
}
|
|
998
|
+
getAccountAndSigner() {
|
|
999
|
+
const accountInfo = this?.hwc?.getAccountInfo();
|
|
1000
|
+
const accountId = accountInfo?.accountId?.toString();
|
|
1001
|
+
const signer = this?.hwc?.dAppConnector?.signers?.find((s) => {
|
|
1002
|
+
return s.getAccountId().toString() === accountId;
|
|
1003
|
+
});
|
|
1004
|
+
if (!signer) {
|
|
1005
|
+
this.logger.error("Failed to find signer", {
|
|
1006
|
+
accountId,
|
|
1007
|
+
signers: this?.hwc?.dAppConnector?.signers,
|
|
1008
|
+
accountInfo
|
|
1009
|
+
});
|
|
1010
|
+
throw new Error("Failed to find signer");
|
|
1011
|
+
}
|
|
1012
|
+
return { accountId, signer };
|
|
1013
|
+
}
|
|
1014
|
+
/**
|
|
1015
|
+
* Inscribes a profile picture (PFP) on HCS-11.
|
|
1016
|
+
*
|
|
1017
|
+
* @param buffer - The buffer containing the PFP image.
|
|
1018
|
+
* @param fileName - The name of the file containing the PFP image.
|
|
1019
|
+
* @param options - Optional configuration options.
|
|
1020
|
+
* @returns A promise that resolves to the topic ID of the inscribed PFP.
|
|
1021
|
+
*/
|
|
1022
|
+
async inscribePfp(buffer, fileName, options) {
|
|
1023
|
+
try {
|
|
1024
|
+
const progressCallback = options?.progressCallback;
|
|
1025
|
+
const progressReporter = new ProgressReporter({
|
|
1026
|
+
module: "PFP-Inscription",
|
|
1027
|
+
logger: this.logger,
|
|
1028
|
+
callback: progressCallback
|
|
1029
|
+
});
|
|
1030
|
+
if (!this.hcs11Client) {
|
|
1031
|
+
progressReporter.failed(
|
|
1032
|
+
"HCS11Client is not available in this environment"
|
|
1033
|
+
);
|
|
1034
|
+
return {
|
|
1035
|
+
pfpTopicId: "",
|
|
1036
|
+
success: false,
|
|
1037
|
+
error: "HCS11Client is not available in this environment",
|
|
1038
|
+
transactionId: ""
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
progressReporter.preparing("Preparing to inscribe profile picture", 10);
|
|
1042
|
+
this.logger.info("Inscribing profile picture using HCS-11 client");
|
|
1043
|
+
const wrappedProgressCallback = (data) => {
|
|
1044
|
+
progressReporter.report({
|
|
1045
|
+
stage: data.stage || "confirming",
|
|
1046
|
+
message: data.message || "Processing PFP inscription",
|
|
1047
|
+
progressPercent: data.progressPercent || 50,
|
|
1048
|
+
details: data.details
|
|
2396
1049
|
});
|
|
1050
|
+
};
|
|
1051
|
+
const imageResult = await this.hcs11Client.inscribeImage(
|
|
1052
|
+
buffer,
|
|
1053
|
+
fileName,
|
|
1054
|
+
{ progressCallback: wrappedProgressCallback }
|
|
1055
|
+
);
|
|
1056
|
+
if (!imageResult.success) {
|
|
1057
|
+
let errorMessage = "Failed to inscribe profile picture";
|
|
1058
|
+
if (imageResult.error) {
|
|
1059
|
+
errorMessage = imageResult.error;
|
|
1060
|
+
}
|
|
1061
|
+
let txId = "";
|
|
1062
|
+
if (imageResult.transactionId) {
|
|
1063
|
+
txId = imageResult.transactionId;
|
|
1064
|
+
}
|
|
1065
|
+
return {
|
|
1066
|
+
pfpTopicId: "",
|
|
1067
|
+
success: false,
|
|
1068
|
+
error: errorMessage,
|
|
1069
|
+
transactionId: txId
|
|
1070
|
+
};
|
|
2397
1071
|
}
|
|
2398
|
-
|
|
2399
|
-
|
|
1072
|
+
progressReporter.completed("Successfully inscribed profile picture", {
|
|
1073
|
+
pfpTopicId: imageResult.imageTopicId
|
|
2400
1074
|
});
|
|
1075
|
+
this.logger.info(
|
|
1076
|
+
`Successfully inscribed profile picture with topic ID: ${imageResult.imageTopicId}`
|
|
1077
|
+
);
|
|
1078
|
+
return {
|
|
1079
|
+
pfpTopicId: imageResult.imageTopicId,
|
|
1080
|
+
success: true,
|
|
1081
|
+
transactionId: imageResult.transactionId || ""
|
|
1082
|
+
};
|
|
1083
|
+
} catch (error) {
|
|
1084
|
+
this.logger.error(`Error inscribing profile picture: ${error.message}`);
|
|
2401
1085
|
return {
|
|
1086
|
+
pfpTopicId: "",
|
|
2402
1087
|
success: false,
|
|
2403
|
-
error:
|
|
1088
|
+
error: error.message,
|
|
1089
|
+
transactionId: ""
|
|
2404
1090
|
};
|
|
2405
1091
|
}
|
|
2406
1092
|
}
|
|
1093
|
+
async createCommunicationTopics(options, progressReporter) {
|
|
1094
|
+
let state = options?.existingState || {
|
|
1095
|
+
currentStage: "init",
|
|
1096
|
+
completedPercentage: 0,
|
|
1097
|
+
createdResources: []
|
|
1098
|
+
};
|
|
1099
|
+
if (progressReporter) {
|
|
1100
|
+
progressReporter.preparing("Starting communication topic creation", 0, {
|
|
1101
|
+
state
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
const { accountId } = this.getAccountAndSigner();
|
|
1105
|
+
if (!state.outboundTopicId) {
|
|
1106
|
+
state.currentStage = "topics";
|
|
1107
|
+
if (progressReporter) {
|
|
1108
|
+
progressReporter.preparing("Creating outbound topic", 5, {
|
|
1109
|
+
state
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
const outboundMemo = this._generateHcs10Memo(Hcs10MemoType.OUTBOUND, {
|
|
1113
|
+
ttl: options?.ttl,
|
|
1114
|
+
accountId
|
|
1115
|
+
});
|
|
1116
|
+
const outboundResult = await this.createTopic(outboundMemo, true, true);
|
|
1117
|
+
if (!outboundResult.success || !outboundResult.topicId) {
|
|
1118
|
+
throw new Error(
|
|
1119
|
+
outboundResult.error || "Failed to create outbound topic"
|
|
1120
|
+
);
|
|
1121
|
+
}
|
|
1122
|
+
state.outboundTopicId = outboundResult.topicId;
|
|
1123
|
+
if (state.createdResources)
|
|
1124
|
+
state.createdResources.push(`outbound:${state.outboundTopicId}`);
|
|
1125
|
+
}
|
|
1126
|
+
if (!state.inboundTopicId) {
|
|
1127
|
+
state.currentStage = "topics";
|
|
1128
|
+
if (progressReporter) {
|
|
1129
|
+
progressReporter.preparing("Creating inbound topic", 10, {
|
|
1130
|
+
state
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
const inboundMemo = this._generateHcs10Memo(Hcs10MemoType.INBOUND, {
|
|
1134
|
+
ttl: options?.ttl,
|
|
1135
|
+
accountId
|
|
1136
|
+
});
|
|
1137
|
+
const inboundResult = await this.createTopic(inboundMemo, true, false);
|
|
1138
|
+
if (!inboundResult.success || !inboundResult.topicId) {
|
|
1139
|
+
throw new Error(
|
|
1140
|
+
inboundResult.error || "Failed to create inbound topic"
|
|
1141
|
+
);
|
|
1142
|
+
}
|
|
1143
|
+
state.inboundTopicId = inboundResult.topicId;
|
|
1144
|
+
if (state.createdResources)
|
|
1145
|
+
state.createdResources.push(`inbound:${state.inboundTopicId}`);
|
|
1146
|
+
}
|
|
1147
|
+
return {
|
|
1148
|
+
inboundTopicId: state.inboundTopicId,
|
|
1149
|
+
outboundTopicId: state.outboundTopicId,
|
|
1150
|
+
state
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
2407
1153
|
}
|
|
2408
1154
|
export {
|
|
2409
|
-
|
|
1155
|
+
BrowserHCSClient
|
|
2410
1156
|
};
|
|
2411
1157
|
//# sourceMappingURL=standards-sdk.es19.js.map
|