@hashgraphonline/standards-agent-kit 0.2.136 → 0.2.138
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/README.md +3 -4
- package/dist/cjs/builders/hcs10/hcs10-builder.d.ts +1 -0
- package/dist/cjs/builders/hcs2/hcs2-builder.d.ts +8 -7
- package/dist/cjs/builders/hcs6/hcs6-builder.d.ts +5 -4
- package/dist/cjs/builders/inscriber/inscriber-builder.d.ts +32 -1
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/signing/bytes-registry.d.ts +17 -0
- package/dist/cjs/signing/signer-provider.d.ts +45 -0
- package/dist/cjs/standards-agent-kit.cjs +1 -1
- package/dist/cjs/standards-agent-kit.cjs.map +1 -1
- package/dist/cjs/tools/hcs10/InitiateConnectionTool.d.ts +4 -4
- package/dist/cjs/tools/hcs2/CreateRegistryTool.d.ts +2 -2
- package/dist/cjs/tools/hcs2/DeleteEntryTool.d.ts +2 -2
- package/dist/cjs/tools/hcs2/UpdateEntryTool.d.ts +2 -2
- package/dist/cjs/tools/hcs6/RegisterDynamicHashinalTool.d.ts +10 -10
- package/dist/cjs/tools/hcs6/UpdateDynamicHashinalTool.d.ts +8 -8
- package/dist/cjs/tools/inscriber/InscribeFromBufferTool.d.ts +5 -4
- package/dist/cjs/tools/inscriber/InscribeFromFileTool.d.ts +2 -2
- package/dist/cjs/tools/inscriber/InscribeFromUrlTool.d.ts +4 -4
- package/dist/cjs/tools/inscriber/InscribeHashinalTool.d.ts +3 -3
- package/dist/cjs/types/inscription-response.d.ts +8 -0
- package/dist/cjs/types/tx-results.d.ts +15 -0
- package/dist/cjs/utils/CodedError.d.ts +4 -0
- package/dist/cjs/utils/inscription-utils.d.ts +21 -0
- package/dist/cjs/validation/hip412-schemas.d.ts +2 -2
- package/dist/es/builders/hcs10/hcs10-builder.d.ts +1 -0
- package/dist/es/builders/hcs2/hcs2-builder.d.ts +8 -7
- package/dist/es/builders/hcs6/hcs6-builder.d.ts +5 -4
- package/dist/es/builders/inscriber/inscriber-builder.d.ts +32 -1
- package/dist/es/index.d.ts +4 -0
- package/dist/es/signing/bytes-registry.d.ts +17 -0
- package/dist/es/signing/signer-provider.d.ts +45 -0
- package/dist/es/standards-agent-kit.es.js +46 -42
- package/dist/es/standards-agent-kit.es.js.map +1 -1
- package/dist/es/standards-agent-kit.es10.js +24 -83
- package/dist/es/standards-agent-kit.es10.js.map +1 -1
- package/dist/es/standards-agent-kit.es11.js +224 -20
- package/dist/es/standards-agent-kit.es11.js.map +1 -1
- package/dist/es/standards-agent-kit.es12.js +78 -27
- package/dist/es/standards-agent-kit.es12.js.map +1 -1
- package/dist/es/standards-agent-kit.es13.js +26 -36
- package/dist/es/standards-agent-kit.es13.js.map +1 -1
- package/dist/es/standards-agent-kit.es14.js +17 -39
- package/dist/es/standards-agent-kit.es14.js.map +1 -1
- package/dist/es/standards-agent-kit.es15.js +36 -58
- package/dist/es/standards-agent-kit.es15.js.map +1 -1
- package/dist/es/standards-agent-kit.es16.js +45 -18
- package/dist/es/standards-agent-kit.es16.js.map +1 -1
- package/dist/es/standards-agent-kit.es17.js +53 -16
- package/dist/es/standards-agent-kit.es17.js.map +1 -1
- package/dist/es/standards-agent-kit.es18.js +18 -28
- package/dist/es/standards-agent-kit.es18.js.map +1 -1
- package/dist/es/standards-agent-kit.es19.js +26 -12
- package/dist/es/standards-agent-kit.es19.js.map +1 -1
- package/dist/es/standards-agent-kit.es20.js +38 -136
- package/dist/es/standards-agent-kit.es20.js.map +1 -1
- package/dist/es/standards-agent-kit.es21.js +13 -24
- package/dist/es/standards-agent-kit.es21.js.map +1 -1
- package/dist/es/standards-agent-kit.es22.js +136 -39
- package/dist/es/standards-agent-kit.es22.js.map +1 -1
- package/dist/es/standards-agent-kit.es23.js +25 -41
- package/dist/es/standards-agent-kit.es23.js.map +1 -1
- package/dist/es/standards-agent-kit.es24.js +49 -31
- package/dist/es/standards-agent-kit.es24.js.map +1 -1
- package/dist/es/standards-agent-kit.es25.js +34 -18
- package/dist/es/standards-agent-kit.es25.js.map +1 -1
- package/dist/es/standards-agent-kit.es26.js +35 -19
- package/dist/es/standards-agent-kit.es26.js.map +1 -1
- package/dist/es/standards-agent-kit.es27.js +45 -32
- package/dist/es/standards-agent-kit.es27.js.map +1 -1
- package/dist/es/standards-agent-kit.es28.js +54 -25
- package/dist/es/standards-agent-kit.es28.js.map +1 -1
- package/dist/es/standards-agent-kit.es29.js +35 -23
- package/dist/es/standards-agent-kit.es29.js.map +1 -1
- package/dist/es/standards-agent-kit.es3.js +41 -1545
- package/dist/es/standards-agent-kit.es3.js.map +1 -1
- package/dist/es/standards-agent-kit.es30.js +23 -39
- package/dist/es/standards-agent-kit.es30.js.map +1 -1
- package/dist/es/standards-agent-kit.es31.js +30 -28
- package/dist/es/standards-agent-kit.es31.js.map +1 -1
- package/dist/es/standards-agent-kit.es32.js +45 -32
- package/dist/es/standards-agent-kit.es32.js.map +1 -1
- package/dist/es/standards-agent-kit.es33.js +50 -89
- package/dist/es/standards-agent-kit.es33.js.map +1 -1
- package/dist/es/standards-agent-kit.es34.js +35 -228
- package/dist/es/standards-agent-kit.es34.js.map +1 -1
- package/dist/es/standards-agent-kit.es35.js +87 -212
- package/dist/es/standards-agent-kit.es35.js.map +1 -1
- package/dist/es/standards-agent-kit.es36.js +188 -128
- package/dist/es/standards-agent-kit.es36.js.map +1 -1
- package/dist/es/standards-agent-kit.es37.js +167 -561
- package/dist/es/standards-agent-kit.es37.js.map +1 -1
- package/dist/es/standards-agent-kit.es38.js +236 -31
- package/dist/es/standards-agent-kit.es38.js.map +1 -1
- package/dist/es/standards-agent-kit.es39.js +483 -206
- package/dist/es/standards-agent-kit.es39.js.map +1 -1
- package/dist/es/standards-agent-kit.es4.js +359 -81
- package/dist/es/standards-agent-kit.es4.js.map +1 -1
- package/dist/es/standards-agent-kit.es40.js +39 -135
- package/dist/es/standards-agent-kit.es40.js.map +1 -1
- package/dist/es/standards-agent-kit.es41.js +244 -28
- package/dist/es/standards-agent-kit.es41.js.map +1 -1
- package/dist/es/standards-agent-kit.es42.js +132 -418
- package/dist/es/standards-agent-kit.es42.js.map +1 -1
- package/dist/es/standards-agent-kit.es43.js +28 -184
- package/dist/es/standards-agent-kit.es43.js.map +1 -1
- package/dist/es/standards-agent-kit.es44.js +423 -3
- package/dist/es/standards-agent-kit.es44.js.map +1 -1
- package/dist/es/standards-agent-kit.es45.js +185 -24
- package/dist/es/standards-agent-kit.es45.js.map +1 -1
- package/dist/es/standards-agent-kit.es46.js +3 -3
- package/dist/es/standards-agent-kit.es46.js.map +1 -1
- package/dist/es/standards-agent-kit.es47.js +21 -50
- package/dist/es/standards-agent-kit.es47.js.map +1 -1
- package/dist/es/standards-agent-kit.es48.js +8 -3
- package/dist/es/standards-agent-kit.es48.js.map +1 -1
- package/dist/es/standards-agent-kit.es49.js +3 -39
- package/dist/es/standards-agent-kit.es49.js.map +1 -1
- package/dist/es/standards-agent-kit.es5.js +1747 -73
- package/dist/es/standards-agent-kit.es5.js.map +1 -1
- package/dist/es/standards-agent-kit.es50.js +18 -16
- package/dist/es/standards-agent-kit.es50.js.map +1 -1
- package/dist/es/standards-agent-kit.es51.js +49 -49
- package/dist/es/standards-agent-kit.es51.js.map +1 -1
- package/dist/es/standards-agent-kit.es52.js +6 -0
- package/dist/es/standards-agent-kit.es52.js.map +1 -0
- package/dist/es/standards-agent-kit.es53.js +43 -0
- package/dist/es/standards-agent-kit.es53.js.map +1 -0
- package/dist/es/standards-agent-kit.es54.js +22 -0
- package/dist/es/standards-agent-kit.es54.js.map +1 -0
- package/dist/es/standards-agent-kit.es55.js +77 -0
- package/dist/es/standards-agent-kit.es55.js.map +1 -0
- package/dist/es/standards-agent-kit.es56.js +7 -0
- package/dist/es/standards-agent-kit.es56.js.map +1 -0
- package/dist/es/standards-agent-kit.es6.js +347 -32
- package/dist/es/standards-agent-kit.es6.js.map +1 -1
- package/dist/es/standards-agent-kit.es7.js +142 -293
- package/dist/es/standards-agent-kit.es7.js.map +1 -1
- package/dist/es/standards-agent-kit.es8.js +201 -21
- package/dist/es/standards-agent-kit.es8.js.map +1 -1
- package/dist/es/standards-agent-kit.es9.js +301 -213
- package/dist/es/standards-agent-kit.es9.js.map +1 -1
- package/dist/es/tools/hcs10/InitiateConnectionTool.d.ts +4 -4
- package/dist/es/tools/hcs2/CreateRegistryTool.d.ts +2 -2
- package/dist/es/tools/hcs2/DeleteEntryTool.d.ts +2 -2
- package/dist/es/tools/hcs2/UpdateEntryTool.d.ts +2 -2
- package/dist/es/tools/hcs6/RegisterDynamicHashinalTool.d.ts +10 -10
- package/dist/es/tools/hcs6/UpdateDynamicHashinalTool.d.ts +8 -8
- package/dist/es/tools/inscriber/InscribeFromBufferTool.d.ts +5 -4
- package/dist/es/tools/inscriber/InscribeFromFileTool.d.ts +2 -2
- package/dist/es/tools/inscriber/InscribeFromUrlTool.d.ts +4 -4
- package/dist/es/tools/inscriber/InscribeHashinalTool.d.ts +3 -3
- package/dist/es/types/inscription-response.d.ts +8 -0
- package/dist/es/types/tx-results.d.ts +15 -0
- package/dist/es/utils/CodedError.d.ts +4 -0
- package/dist/es/utils/inscription-utils.d.ts +21 -0
- package/dist/es/validation/hip412-schemas.d.ts +2 -2
- package/dist/umd/builders/hcs10/hcs10-builder.d.ts +1 -0
- package/dist/umd/builders/hcs2/hcs2-builder.d.ts +8 -7
- package/dist/umd/builders/hcs6/hcs6-builder.d.ts +5 -4
- package/dist/umd/builders/inscriber/inscriber-builder.d.ts +32 -1
- package/dist/umd/index.d.ts +4 -0
- package/dist/umd/signing/bytes-registry.d.ts +17 -0
- package/dist/umd/signing/signer-provider.d.ts +45 -0
- package/dist/umd/standards-agent-kit.umd.js +1 -1
- package/dist/umd/standards-agent-kit.umd.js.map +1 -1
- package/dist/umd/tools/hcs10/InitiateConnectionTool.d.ts +4 -4
- package/dist/umd/tools/hcs2/CreateRegistryTool.d.ts +2 -2
- package/dist/umd/tools/hcs2/DeleteEntryTool.d.ts +2 -2
- package/dist/umd/tools/hcs2/UpdateEntryTool.d.ts +2 -2
- package/dist/umd/tools/hcs6/RegisterDynamicHashinalTool.d.ts +10 -10
- package/dist/umd/tools/hcs6/UpdateDynamicHashinalTool.d.ts +8 -8
- package/dist/umd/tools/inscriber/InscribeFromBufferTool.d.ts +5 -4
- package/dist/umd/tools/inscriber/InscribeFromFileTool.d.ts +2 -2
- package/dist/umd/tools/inscriber/InscribeFromUrlTool.d.ts +4 -4
- package/dist/umd/tools/inscriber/InscribeHashinalTool.d.ts +3 -3
- package/dist/umd/types/inscription-response.d.ts +8 -0
- package/dist/umd/types/tx-results.d.ts +15 -0
- package/dist/umd/utils/CodedError.d.ts +4 -0
- package/dist/umd/utils/inscription-utils.d.ts +21 -0
- package/dist/umd/validation/hip412-schemas.d.ts +2 -2
- package/package.json +10 -5
- package/src/builders/hcs10/hcs10-builder.ts +239 -6
- package/src/builders/hcs2/hcs2-builder.ts +302 -9
- package/src/builders/hcs6/hcs6-builder.ts +79 -4
- package/src/builders/inscriber/inscriber-builder.ts +235 -2
- package/src/hcs10/HCS10Client.ts +1 -1
- package/src/index.ts +5 -1
- package/src/lib/zod-render/schema-extension.ts +0 -1
- package/src/signing/bytes-registry.ts +501 -0
- package/src/signing/signer-provider.ts +120 -0
- package/src/tools/hcs2/CreateRegistryTool.ts +30 -5
- package/src/tools/hcs2/DeleteEntryTool.ts +16 -2
- package/src/tools/hcs2/MigrateRegistryTool.ts +16 -2
- package/src/tools/hcs2/QueryRegistryTool.ts +11 -2
- package/src/tools/hcs2/RegisterEntryTool.ts +17 -3
- package/src/tools/hcs2/UpdateEntryTool.ts +16 -2
- package/src/tools/hcs6/CreateDynamicRegistryTool.ts +17 -3
- package/src/tools/hcs6/RegisterDynamicHashinalTool.ts +17 -3
- package/src/tools/hcs6/UpdateDynamicHashinalTool.ts +17 -3
- package/src/tools/inscriber/InscribeFromBufferTool.ts +126 -21
- package/src/tools/inscriber/InscribeFromFileTool.ts +10 -13
- package/src/tools/inscriber/InscribeFromUrlTool.ts +15 -11
- package/src/tools/inscriber/InscribeHashinalTool.ts +40 -168
- package/src/tools/inscriber/RetrieveInscriptionTool.ts +15 -16
- package/src/types/inscription-response.ts +27 -0
- package/src/types/tx-results.ts +18 -0
- package/src/utils/CodedError.ts +8 -0
- package/src/utils/Encryption.ts +0 -2
- package/src/utils/ensure-agent-has-hbar.ts +4 -5
- package/src/utils/inscription-utils.ts +53 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseServiceBuilder } from 'hedera-agent-kit';
|
|
2
2
|
import type { HederaAgentKit } from 'hedera-agent-kit';
|
|
3
3
|
import { PrivateKey, TransactionReceipt } from '@hashgraph/sdk';
|
|
4
|
+
import { SignerProviderRegistry, type DAppSigner, type NetworkString } from '../../signing/signer-provider';
|
|
4
5
|
import { ActiveConnection, IStateManager } from '../../state/state-types';
|
|
5
6
|
import { ExecuteResult } from '../types';
|
|
6
7
|
import {
|
|
@@ -150,6 +151,7 @@ export class HCS10Builder extends BaseServiceBuilder {
|
|
|
150
151
|
}
|
|
151
152
|
) {
|
|
152
153
|
super(hederaKit);
|
|
154
|
+
|
|
153
155
|
this.stateManager = stateManager;
|
|
154
156
|
|
|
155
157
|
const network = this.hederaKit.client.network;
|
|
@@ -162,10 +164,27 @@ export class HCS10Builder extends BaseServiceBuilder {
|
|
|
162
164
|
? this.hederaKit.signer.getOperatorPrivateKey().toStringRaw()
|
|
163
165
|
: '';
|
|
164
166
|
|
|
165
|
-
this.sdkLogger =
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
this.sdkLogger = ((): SDKLogger => {
|
|
168
|
+
try {
|
|
169
|
+
if (typeof SDKLogger === 'function') {
|
|
170
|
+
return new SDKLogger({
|
|
171
|
+
module: 'HCS10Builder',
|
|
172
|
+
level: options?.logLevel || 'info',
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
} catch {}
|
|
176
|
+
return {
|
|
177
|
+
debug: () => {},
|
|
178
|
+
info: () => {},
|
|
179
|
+
warn: () => {},
|
|
180
|
+
error: () => {},
|
|
181
|
+
trace: () => {},
|
|
182
|
+
setLogLevel: () => {},
|
|
183
|
+
getLevel: () => 'info',
|
|
184
|
+
setSilent: () => {},
|
|
185
|
+
setModule: () => {},
|
|
186
|
+
} as unknown as SDKLogger;
|
|
187
|
+
})();
|
|
169
188
|
|
|
170
189
|
this.standardClient = new HCS10Client({
|
|
171
190
|
network: this.network,
|
|
@@ -278,6 +297,41 @@ export class HCS10Builder extends BaseServiceBuilder {
|
|
|
278
297
|
inboundTopicId: string,
|
|
279
298
|
memo: string
|
|
280
299
|
): Promise<TransactionReceipt> {
|
|
300
|
+
const start = SignerProviderRegistry.startHCSDelegate;
|
|
301
|
+
const exec = SignerProviderRegistry.walletExecutor;
|
|
302
|
+
const preferWallet = SignerProviderRegistry.preferWalletOnly;
|
|
303
|
+
const network: NetworkString = this.network;
|
|
304
|
+
|
|
305
|
+
try {
|
|
306
|
+
const { ByteBuildRegistry } = await import('../../signing/bytes-registry');
|
|
307
|
+
if (exec && ByteBuildRegistry.has('submitConnectionRequest')) {
|
|
308
|
+
const built = await ByteBuildRegistry.build('submitConnectionRequest', this.hederaKit, { inboundTopicId, memo });
|
|
309
|
+
if (built && built.transactionBytes) {
|
|
310
|
+
const { transactionId } = await exec(built.transactionBytes, network);
|
|
311
|
+
return ({ transactionId } as unknown) as TransactionReceipt;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
} catch {}
|
|
315
|
+
|
|
316
|
+
if (start && exec) {
|
|
317
|
+
try {
|
|
318
|
+
const request: Record<string, unknown> = { inboundTopicId, memo };
|
|
319
|
+
const { transactionBytes } = await start('submitConnectionRequest', request, network);
|
|
320
|
+
const { transactionId } = await exec(transactionBytes, network);
|
|
321
|
+
return ({ transactionId } as unknown) as TransactionReceipt;
|
|
322
|
+
} catch (err) {
|
|
323
|
+
if (preferWallet) {
|
|
324
|
+
const e = new Error(`wallet_submit_failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
325
|
+
(e as unknown as { code: string }).code = 'wallet_submit_failed';
|
|
326
|
+
throw e;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
} else if (preferWallet) {
|
|
330
|
+
const e = new Error('wallet_unavailable: connect a wallet or configure StartHCSDelegate and WalletExecutor');
|
|
331
|
+
(e as unknown as { code: string }).code = 'wallet_unavailable';
|
|
332
|
+
throw e;
|
|
333
|
+
}
|
|
334
|
+
|
|
281
335
|
return this.standardClient.submitConnectionRequest(
|
|
282
336
|
inboundTopicId,
|
|
283
337
|
memo
|
|
@@ -294,6 +348,39 @@ export class HCS10Builder extends BaseServiceBuilder {
|
|
|
294
348
|
feeConfig?: FeeConfigBuilderInterface
|
|
295
349
|
): Promise<HandleConnectionRequestResponse> {
|
|
296
350
|
try {
|
|
351
|
+
const start = SignerProviderRegistry.startHCSDelegate;
|
|
352
|
+
const exec = SignerProviderRegistry.walletExecutor;
|
|
353
|
+
const preferWallet = SignerProviderRegistry.preferWalletOnly;
|
|
354
|
+
const network: NetworkString = this.network;
|
|
355
|
+
|
|
356
|
+
if (start && exec) {
|
|
357
|
+
try {
|
|
358
|
+
const request: Record<string, unknown> = {
|
|
359
|
+
inboundTopicId,
|
|
360
|
+
requestingAccountId,
|
|
361
|
+
connectionRequestId,
|
|
362
|
+
feeConfig: feeConfig ? 'configured' : undefined,
|
|
363
|
+
};
|
|
364
|
+
const { transactionBytes } = await start('handleConnectionRequest', request, network);
|
|
365
|
+
const { transactionId } = await exec(transactionBytes, network);
|
|
366
|
+
const minimal = {
|
|
367
|
+
success: true,
|
|
368
|
+
transactionId,
|
|
369
|
+
} as unknown as HandleConnectionRequestResponse;
|
|
370
|
+
return minimal;
|
|
371
|
+
} catch (err) {
|
|
372
|
+
if (preferWallet) {
|
|
373
|
+
const e = new Error(`wallet_submit_failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
374
|
+
(e as unknown as { code: string }).code = 'wallet_submit_failed';
|
|
375
|
+
throw e;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
} else if (preferWallet) {
|
|
379
|
+
const e = new Error('wallet_unavailable: connect a wallet or configure StartHCSDelegate and WalletExecutor');
|
|
380
|
+
(e as unknown as { code: string }).code = 'wallet_unavailable';
|
|
381
|
+
throw e;
|
|
382
|
+
}
|
|
383
|
+
|
|
297
384
|
const result = await this.standardClient.handleConnectionRequest(
|
|
298
385
|
inboundTopicId,
|
|
299
386
|
requestingAccountId,
|
|
@@ -349,6 +436,58 @@ export class HCS10Builder extends BaseServiceBuilder {
|
|
|
349
436
|
}
|
|
350
437
|
|
|
351
438
|
try {
|
|
439
|
+
let prevMaxSeq = 0
|
|
440
|
+
try {
|
|
441
|
+
const prev = await this.getMessages(topicId)
|
|
442
|
+
prevMaxSeq = prev.messages.reduce((max, m) => Math.max(max, m.sequence_number || 0), 0)
|
|
443
|
+
} catch {}
|
|
444
|
+
|
|
445
|
+
const start = SignerProviderRegistry.startHCSDelegate;
|
|
446
|
+
const exec = SignerProviderRegistry.walletExecutor;
|
|
447
|
+
const preferWallet = SignerProviderRegistry.preferWalletOnly;
|
|
448
|
+
const network: NetworkString = this.network;
|
|
449
|
+
|
|
450
|
+
try {
|
|
451
|
+
const { ByteBuildRegistry } = await import('../../signing/bytes-registry');
|
|
452
|
+
if (exec && ByteBuildRegistry.has('sendMessage')) {
|
|
453
|
+
const built = await ByteBuildRegistry.build('sendMessage', this.hederaKit, { topicId, data, memo });
|
|
454
|
+
if (built && built.transactionBytes) {
|
|
455
|
+
const { transactionId } = await exec(built.transactionBytes, network);
|
|
456
|
+
const sequenceNumber = await this.pollForNewSequence(topicId, prevMaxSeq);
|
|
457
|
+
return {
|
|
458
|
+
sequenceNumber,
|
|
459
|
+
receipt: ({ transactionId } as unknown) as TransactionReceipt,
|
|
460
|
+
transactionId,
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
} catch {}
|
|
465
|
+
|
|
466
|
+
if (start && exec) {
|
|
467
|
+
try {
|
|
468
|
+
const request: Record<string, unknown> = { topicId, data, memo };
|
|
469
|
+
const { transactionBytes } = await start('sendMessage', request, network);
|
|
470
|
+
const { transactionId } = await exec(transactionBytes, network);
|
|
471
|
+
|
|
472
|
+
const sequenceNumber = await this.pollForNewSequence(topicId, prevMaxSeq);
|
|
473
|
+
return {
|
|
474
|
+
sequenceNumber,
|
|
475
|
+
receipt: ({ transactionId } as unknown) as TransactionReceipt,
|
|
476
|
+
transactionId,
|
|
477
|
+
};
|
|
478
|
+
} catch (err) {
|
|
479
|
+
if (preferWallet) {
|
|
480
|
+
const e = new Error(`wallet_submit_failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
481
|
+
(e as unknown as { code: string }).code = 'wallet_submit_failed';
|
|
482
|
+
throw e;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
} else if (preferWallet) {
|
|
486
|
+
const e = new Error('wallet_unavailable: connect a wallet or configure StartHCSDelegate and WalletExecutor');
|
|
487
|
+
(e as unknown as { code: string }).code = 'wallet_unavailable';
|
|
488
|
+
throw e;
|
|
489
|
+
}
|
|
490
|
+
|
|
352
491
|
const messageResponse = await this.standardClient.sendMessage(
|
|
353
492
|
topicId,
|
|
354
493
|
data,
|
|
@@ -544,6 +683,20 @@ export class HCS10Builder extends BaseServiceBuilder {
|
|
|
544
683
|
}
|
|
545
684
|
}
|
|
546
685
|
|
|
686
|
+
private async pollForNewSequence(topicId: string, prevMax: number): Promise<number | undefined> {
|
|
687
|
+
const maxAttempts = 10
|
|
688
|
+
const delayMs = 1000
|
|
689
|
+
for (let i = 0; i < maxAttempts; i++) {
|
|
690
|
+
try {
|
|
691
|
+
const res = await this.getMessages(topicId)
|
|
692
|
+
const maxSeq = res.messages.reduce((m, msg) => Math.max(m, msg.sequence_number || 0), prevMax)
|
|
693
|
+
if (maxSeq > prevMax) return maxSeq
|
|
694
|
+
} catch {}
|
|
695
|
+
await new Promise((r) => setTimeout(r, delayMs))
|
|
696
|
+
}
|
|
697
|
+
return undefined
|
|
698
|
+
}
|
|
699
|
+
|
|
547
700
|
/**
|
|
548
701
|
* Create and register an agent
|
|
549
702
|
*/
|
|
@@ -695,6 +848,64 @@ export class HCS10Builder extends BaseServiceBuilder {
|
|
|
695
848
|
);
|
|
696
849
|
}
|
|
697
850
|
|
|
851
|
+
const preferWallet = SignerProviderRegistry.preferWalletOnly;
|
|
852
|
+
const browserClient = SignerProviderRegistry.getBrowserHCSClient(this.network as NetworkString) as
|
|
853
|
+
| { create: (builder: unknown, opts?: Record<string, unknown>) => Promise<unknown> }
|
|
854
|
+
| null;
|
|
855
|
+
|
|
856
|
+
if (browserClient) {
|
|
857
|
+
try {
|
|
858
|
+
const aBuilder = new AgentBuilder()
|
|
859
|
+
.setNetwork(this.network)
|
|
860
|
+
.setName(registrationData.name)
|
|
861
|
+
.setAlias(registrationData.alias || `${registrationData.name}-${Date.now()}`)
|
|
862
|
+
.setBio(registrationData.bio || '')
|
|
863
|
+
.setType(registrationData.type || 'autonomous')
|
|
864
|
+
.setModel(registrationData.model || 'agent-model-2024');
|
|
865
|
+
|
|
866
|
+
if (registrationData.capabilities?.length) {
|
|
867
|
+
aBuilder.setCapabilities(registrationData.capabilities as unknown as number[]);
|
|
868
|
+
}
|
|
869
|
+
if (registrationData.creator) aBuilder.setCreator(registrationData.creator);
|
|
870
|
+
if (registrationData.existingProfilePictureTopicId) {
|
|
871
|
+
aBuilder.setExistingProfilePicture(registrationData.existingProfilePictureTopicId);
|
|
872
|
+
}
|
|
873
|
+
if (registrationData.socials) {
|
|
874
|
+
Object.entries(registrationData.socials).forEach(([platform, handle]) => {
|
|
875
|
+
if (handle && typeof handle === 'string') {
|
|
876
|
+
aBuilder.addSocial(platform as SocialPlatform, handle);
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
if (registrationData.properties) {
|
|
881
|
+
Object.entries(registrationData.properties).forEach(([key, value]) => {
|
|
882
|
+
if (value != null) aBuilder.addProperty(key, value as unknown as string);
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
const resp = await browserClient.create(aBuilder, {
|
|
887
|
+
progressCallback: (_: unknown) => {},
|
|
888
|
+
updateAccountMemo: true,
|
|
889
|
+
});
|
|
890
|
+
|
|
891
|
+
this.executeResult = {
|
|
892
|
+
success: true,
|
|
893
|
+
transactionId: undefined,
|
|
894
|
+
receipt: undefined,
|
|
895
|
+
scheduleId: undefined,
|
|
896
|
+
rawResult: { result: resp, name: registrationData.name },
|
|
897
|
+
} as unknown as ExecuteResult & { rawResult?: unknown };
|
|
898
|
+
|
|
899
|
+
return this;
|
|
900
|
+
} catch (walletErr) {
|
|
901
|
+
if (preferWallet) {
|
|
902
|
+
throw new Error(`wallet_registration_failed: ${walletErr instanceof Error ? walletErr.message : String(walletErr)}`);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
} else if (preferWallet) {
|
|
906
|
+
throw new Error('wallet_unavailable: BrowserHCSClient factory not provided');
|
|
907
|
+
}
|
|
908
|
+
|
|
698
909
|
const result = await this.createAndRegisterAgent(registrationData);
|
|
699
910
|
|
|
700
911
|
this.executeResult = {
|
|
@@ -886,6 +1097,21 @@ export class HCS10Builder extends BaseServiceBuilder {
|
|
|
886
1097
|
)?.toString();
|
|
887
1098
|
}
|
|
888
1099
|
|
|
1100
|
+
if (!connectionTopicId || typeof connectionTopicId !== 'string') {
|
|
1101
|
+
try {
|
|
1102
|
+
const refreshed = await this.stateManager?.getConnectionsManager()?.fetchConnectionData(currentAgent.accountId);
|
|
1103
|
+
const established = (refreshed || []).find(
|
|
1104
|
+
(c: unknown) => (c as { targetAccountId?: string; status?: string }).targetAccountId === targetAccountId &&
|
|
1105
|
+
(c as { status?: string }).status === 'established'
|
|
1106
|
+
) as { connectionTopicId?: string } | undefined;
|
|
1107
|
+
if (established?.connectionTopicId) {
|
|
1108
|
+
connectionTopicId = established.connectionTopicId;
|
|
1109
|
+
}
|
|
1110
|
+
} catch (e) {
|
|
1111
|
+
this.logger.debug('Could not refresh connections after acceptance to derive topic id:', e);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
|
|
889
1115
|
if (!connectionTopicId || typeof connectionTopicId !== 'string') {
|
|
890
1116
|
throw new Error(
|
|
891
1117
|
`Failed to create connection topic. Got: ${JSON.stringify(
|
|
@@ -1102,13 +1328,20 @@ export class HCS10Builder extends BaseServiceBuilder {
|
|
|
1102
1328
|
|
|
1103
1329
|
const operatorId = `${currentAgent.inboundTopicId}@${currentAgent.accountId}`;
|
|
1104
1330
|
|
|
1331
|
+
let baseSeq = 0
|
|
1332
|
+
try {
|
|
1333
|
+
const prev = await this.getMessages(connectionTopicId)
|
|
1334
|
+
baseSeq = prev.messages.reduce((max, m) => Math.max(max, m.sequence_number || 0), 0)
|
|
1335
|
+
} catch {}
|
|
1336
|
+
|
|
1105
1337
|
const messageResult = await this.sendMessage(
|
|
1106
1338
|
connectionTopicId,
|
|
1107
1339
|
params.message,
|
|
1108
1340
|
`Agent message from ${currentAgent.name}`
|
|
1109
1341
|
);
|
|
1110
1342
|
|
|
1111
|
-
|
|
1343
|
+
const effectiveSeq = messageResult.sequenceNumber ?? baseSeq
|
|
1344
|
+
if (effectiveSeq === 0) {
|
|
1112
1345
|
throw new Error('Failed to send message');
|
|
1113
1346
|
}
|
|
1114
1347
|
|
|
@@ -1117,7 +1350,7 @@ export class HCS10Builder extends BaseServiceBuilder {
|
|
|
1117
1350
|
reply = await this.monitorResponses(
|
|
1118
1351
|
connectionTopicId,
|
|
1119
1352
|
operatorId,
|
|
1120
|
-
|
|
1353
|
+
effectiveSeq
|
|
1121
1354
|
);
|
|
1122
1355
|
} else {
|
|
1123
1356
|
this.addNote(
|
|
@@ -13,7 +13,11 @@ import {
|
|
|
13
13
|
RegistryOperationResponse,
|
|
14
14
|
TopicRegistry,
|
|
15
15
|
NetworkType,
|
|
16
|
+
HederaMirrorNode,
|
|
16
17
|
} from '@hashgraphonline/standards-sdk';
|
|
18
|
+
import { SignerProviderRegistry, type NetworkString } from '../../signing/signer-provider';
|
|
19
|
+
import type { TopicRegistrationResult, RegistryOperationResult, SubmitMessageResult } from '../../types/tx-results';
|
|
20
|
+
import { CodedError } from '../../utils/CodedError';
|
|
17
21
|
|
|
18
22
|
/**
|
|
19
23
|
* Builder for HCS-2 operations that delegates to HCS2Client
|
|
@@ -40,10 +44,23 @@ export class HCS2Builder extends BaseServiceBuilder {
|
|
|
40
44
|
? 'mainnet'
|
|
41
45
|
: 'testnet';
|
|
42
46
|
|
|
47
|
+
let keyTypeHint: 'ed25519' | 'ecdsa' | undefined;
|
|
48
|
+
try {
|
|
49
|
+
const mirror = new HederaMirrorNode(networkType);
|
|
50
|
+
const info = await mirror.requestAccount(operatorId);
|
|
51
|
+
const t = (info as any)?.key?._type as string | undefined;
|
|
52
|
+
if (t) {
|
|
53
|
+
const upper = t.toUpperCase();
|
|
54
|
+
if (upper.includes('ED25519')) keyTypeHint = 'ed25519';
|
|
55
|
+
else if (upper.includes('ECDSA')) keyTypeHint = 'ecdsa';
|
|
56
|
+
}
|
|
57
|
+
} catch {}
|
|
58
|
+
|
|
43
59
|
const config: SDKHCS2ClientConfig = {
|
|
44
60
|
network: networkType,
|
|
45
61
|
operatorId: operatorId,
|
|
46
62
|
operatorKey: operatorPrivateKey,
|
|
63
|
+
...(keyTypeHint ? { keyType: keyTypeHint } : {}),
|
|
47
64
|
};
|
|
48
65
|
|
|
49
66
|
this.hcs2Client = new HCS2Client(config);
|
|
@@ -57,18 +74,96 @@ export class HCS2Builder extends BaseServiceBuilder {
|
|
|
57
74
|
*/
|
|
58
75
|
async createRegistry(
|
|
59
76
|
options: CreateRegistryOptions = {}
|
|
60
|
-
): Promise<
|
|
77
|
+
): Promise<TopicRegistrationResult> {
|
|
78
|
+
const exec = SignerProviderRegistry.walletExecutor;
|
|
79
|
+
const preferWallet = SignerProviderRegistry.preferWalletOnly;
|
|
80
|
+
const hasPrivateKey = !!(this.hederaKit?.signer?.getOperatorPrivateKey && this.hederaKit.signer.getOperatorPrivateKey());
|
|
81
|
+
|
|
82
|
+
if (exec) {
|
|
83
|
+
const start = SignerProviderRegistry.startHCSDelegate;
|
|
84
|
+
if (start) {
|
|
85
|
+
try {
|
|
86
|
+
const request: Record<string, unknown> = { options };
|
|
87
|
+
const network = (this.hederaKit.client.network.toString().includes('mainnet') ? 'mainnet' : 'testnet') as NetworkString;
|
|
88
|
+
const { transactionBytes } = await start('hcs2.createRegistry', request, network);
|
|
89
|
+
if (transactionBytes) {
|
|
90
|
+
return { success: true, transactionBytes };
|
|
91
|
+
}
|
|
92
|
+
} catch (err) {
|
|
93
|
+
if (preferWallet) {
|
|
94
|
+
throw new CodedError('wallet_submit_failed', `wallet_submit_failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (preferWallet) {
|
|
99
|
+
throw new CodedError('wallet_unavailable', 'WalletExecutor not configured for hcs2.createRegistry');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (!hasPrivateKey) {
|
|
104
|
+
throw new CodedError('wallet_unavailable', 'No wallet executor and no operator private key available for server execution');
|
|
105
|
+
}
|
|
61
106
|
const client = await this.getHCS2Client();
|
|
62
107
|
return await client.createRegistry(options);
|
|
63
108
|
}
|
|
64
|
-
|
|
65
109
|
/**
|
|
66
110
|
* Register a new entry in an HCS-2 registry
|
|
67
111
|
*/
|
|
68
112
|
async registerEntry(
|
|
69
113
|
registryTopicId: string,
|
|
70
114
|
options: RegisterEntryOptions
|
|
71
|
-
): Promise<
|
|
115
|
+
): Promise<RegistryOperationResult> {
|
|
116
|
+
const exec = SignerProviderRegistry.walletExecutor;
|
|
117
|
+
const preferWallet = SignerProviderRegistry.preferWalletOnly;
|
|
118
|
+
const network = (this.hederaKit.client.network.toString().includes('mainnet') ? 'mainnet' : 'testnet') as NetworkString;
|
|
119
|
+
const hasPrivateKey = !!(this.hederaKit?.signer?.getOperatorPrivateKey && this.hederaKit.signer.getOperatorPrivateKey());
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
const { ByteBuildRegistry } = await import('../../signing/bytes-registry');
|
|
123
|
+
if (ByteBuildRegistry.has('hcs2.registerEntry')) {
|
|
124
|
+
const built = await ByteBuildRegistry.build('hcs2.registerEntry', this.hederaKit, { registryTopicId, options });
|
|
125
|
+
if (built && built.transactionBytes) {
|
|
126
|
+
if (exec) {
|
|
127
|
+
return { success: true, transactionBytes: built.transactionBytes };
|
|
128
|
+
}
|
|
129
|
+
if (!hasPrivateKey) {
|
|
130
|
+
return { success: true, transactionBytes: built.transactionBytes };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
} catch {}
|
|
135
|
+
|
|
136
|
+
const start = SignerProviderRegistry.startHCSDelegate;
|
|
137
|
+
if (start) {
|
|
138
|
+
try {
|
|
139
|
+
const request: Record<string, unknown> = {
|
|
140
|
+
registryTopicId,
|
|
141
|
+
options,
|
|
142
|
+
};
|
|
143
|
+
const { transactionBytes } = await start('hcs2.registerEntry', request, network);
|
|
144
|
+
if (transactionBytes) {
|
|
145
|
+
if (exec) {
|
|
146
|
+
return { success: true, transactionBytes };
|
|
147
|
+
}
|
|
148
|
+
if (!hasPrivateKey) {
|
|
149
|
+
return { success: true, transactionBytes };
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
} catch (err) {
|
|
153
|
+
if (preferWallet) {
|
|
154
|
+
const msg = `wallet_submit_failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
155
|
+
throw new CodedError('wallet_submit_failed', msg);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (preferWallet) {
|
|
161
|
+
throw new CodedError('wallet_unavailable', 'WalletExecutor not configured for hcs2.registerEntry');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (!hasPrivateKey) {
|
|
165
|
+
throw new CodedError('wallet_unavailable', 'No wallet executor and no operator private key available for server execution');
|
|
166
|
+
}
|
|
72
167
|
const client = await this.getHCS2Client();
|
|
73
168
|
return await client.registerEntry(registryTopicId, options);
|
|
74
169
|
}
|
|
@@ -79,7 +174,58 @@ export class HCS2Builder extends BaseServiceBuilder {
|
|
|
79
174
|
async updateEntry(
|
|
80
175
|
registryTopicId: string,
|
|
81
176
|
options: UpdateEntryOptions
|
|
82
|
-
): Promise<
|
|
177
|
+
): Promise<RegistryOperationResult> {
|
|
178
|
+
const exec = SignerProviderRegistry.walletExecutor;
|
|
179
|
+
const preferWallet = SignerProviderRegistry.preferWalletOnly;
|
|
180
|
+
const network = (this.hederaKit.client.network.toString().includes('mainnet') ? 'mainnet' : 'testnet') as NetworkString;
|
|
181
|
+
const hasPrivateKey = !!(this.hederaKit?.signer?.getOperatorPrivateKey && this.hederaKit.signer.getOperatorPrivateKey());
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
const { ByteBuildRegistry } = await import('../../signing/bytes-registry');
|
|
185
|
+
if (ByteBuildRegistry.has('hcs2.updateEntry')) {
|
|
186
|
+
const built = await ByteBuildRegistry.build('hcs2.updateEntry', this.hederaKit, { registryTopicId, options });
|
|
187
|
+
if (built && built.transactionBytes) {
|
|
188
|
+
if (exec) {
|
|
189
|
+
return { success: true, transactionBytes: built.transactionBytes };
|
|
190
|
+
}
|
|
191
|
+
if (!hasPrivateKey) {
|
|
192
|
+
return { success: true, transactionBytes: built.transactionBytes };
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
} catch {}
|
|
197
|
+
|
|
198
|
+
const start = SignerProviderRegistry.startHCSDelegate;
|
|
199
|
+
if (start) {
|
|
200
|
+
try {
|
|
201
|
+
const request: Record<string, unknown> = {
|
|
202
|
+
registryTopicId,
|
|
203
|
+
options,
|
|
204
|
+
};
|
|
205
|
+
const { transactionBytes } = await start('hcs2.updateEntry', request, network);
|
|
206
|
+
if (transactionBytes) {
|
|
207
|
+
if (exec) {
|
|
208
|
+
return { success: true, transactionBytes };
|
|
209
|
+
}
|
|
210
|
+
if (!hasPrivateKey) {
|
|
211
|
+
return { success: true, transactionBytes };
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
} catch (err) {
|
|
215
|
+
if (preferWallet) {
|
|
216
|
+
const msg = `wallet_submit_failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
217
|
+
throw new CodedError('wallet_submit_failed', msg);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (preferWallet) {
|
|
223
|
+
throw new CodedError('wallet_unavailable', 'WalletExecutor not configured for hcs2.updateEntry');
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (!hasPrivateKey) {
|
|
227
|
+
throw new CodedError('wallet_unavailable', 'No wallet executor and no operator private key available for server execution');
|
|
228
|
+
}
|
|
83
229
|
const client = await this.getHCS2Client();
|
|
84
230
|
return await client.updateEntry(registryTopicId, options);
|
|
85
231
|
}
|
|
@@ -90,7 +236,58 @@ export class HCS2Builder extends BaseServiceBuilder {
|
|
|
90
236
|
async deleteEntry(
|
|
91
237
|
registryTopicId: string,
|
|
92
238
|
options: DeleteEntryOptions
|
|
93
|
-
): Promise<
|
|
239
|
+
): Promise<RegistryOperationResult> {
|
|
240
|
+
const exec = SignerProviderRegistry.walletExecutor;
|
|
241
|
+
const preferWallet = SignerProviderRegistry.preferWalletOnly;
|
|
242
|
+
const network = (this.hederaKit.client.network.toString().includes('mainnet') ? 'mainnet' : 'testnet') as NetworkString;
|
|
243
|
+
const hasPrivateKey = !!(this.hederaKit?.signer?.getOperatorPrivateKey && this.hederaKit.signer.getOperatorPrivateKey());
|
|
244
|
+
|
|
245
|
+
try {
|
|
246
|
+
const { ByteBuildRegistry } = await import('../../signing/bytes-registry');
|
|
247
|
+
if (ByteBuildRegistry.has('hcs2.deleteEntry')) {
|
|
248
|
+
const built = await ByteBuildRegistry.build('hcs2.deleteEntry', this.hederaKit, { registryTopicId, options });
|
|
249
|
+
if (built && built.transactionBytes) {
|
|
250
|
+
if (exec) {
|
|
251
|
+
return { success: true, transactionBytes: built.transactionBytes };
|
|
252
|
+
}
|
|
253
|
+
if (!hasPrivateKey) {
|
|
254
|
+
return { success: true, transactionBytes: built.transactionBytes };
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
} catch {}
|
|
259
|
+
|
|
260
|
+
const start = SignerProviderRegistry.startHCSDelegate;
|
|
261
|
+
if (start) {
|
|
262
|
+
try {
|
|
263
|
+
const request: Record<string, unknown> = {
|
|
264
|
+
registryTopicId,
|
|
265
|
+
options,
|
|
266
|
+
};
|
|
267
|
+
const { transactionBytes } = await start('hcs2.deleteEntry', request, network);
|
|
268
|
+
if (transactionBytes) {
|
|
269
|
+
if (exec) {
|
|
270
|
+
return { success: true, transactionBytes };
|
|
271
|
+
}
|
|
272
|
+
if (!hasPrivateKey) {
|
|
273
|
+
return { success: true, transactionBytes };
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
} catch (err) {
|
|
277
|
+
if (preferWallet) {
|
|
278
|
+
const msg = `wallet_submit_failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
279
|
+
throw new CodedError('wallet_submit_failed', msg);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (preferWallet) {
|
|
285
|
+
throw new CodedError('wallet_unavailable', 'WalletExecutor not configured for hcs2.deleteEntry');
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (!hasPrivateKey) {
|
|
289
|
+
throw new CodedError('wallet_unavailable', 'No wallet executor and no operator private key available for server execution');
|
|
290
|
+
}
|
|
94
291
|
const client = await this.getHCS2Client();
|
|
95
292
|
return await client.deleteEntry(registryTopicId, options);
|
|
96
293
|
}
|
|
@@ -101,7 +298,55 @@ export class HCS2Builder extends BaseServiceBuilder {
|
|
|
101
298
|
async migrateRegistry(
|
|
102
299
|
registryTopicId: string,
|
|
103
300
|
options: MigrateTopicOptions
|
|
104
|
-
): Promise<
|
|
301
|
+
): Promise<RegistryOperationResult> {
|
|
302
|
+
const exec = SignerProviderRegistry.walletExecutor;
|
|
303
|
+
const preferWallet = SignerProviderRegistry.preferWalletOnly;
|
|
304
|
+
const hasPrivateKey = !!(this.hederaKit?.signer?.getOperatorPrivateKey && this.hederaKit.signer.getOperatorPrivateKey());
|
|
305
|
+
|
|
306
|
+
try {
|
|
307
|
+
const { ByteBuildRegistry } = await import('../../signing/bytes-registry');
|
|
308
|
+
if (ByteBuildRegistry.has('hcs2.migrateRegistry')) {
|
|
309
|
+
const built = await ByteBuildRegistry.build('hcs2.migrateRegistry', this.hederaKit, { registryTopicId, options });
|
|
310
|
+
if (built && built.transactionBytes) {
|
|
311
|
+
if (exec) {
|
|
312
|
+
return { success: true, transactionBytes: built.transactionBytes };
|
|
313
|
+
}
|
|
314
|
+
if (!hasPrivateKey) {
|
|
315
|
+
return { success: true, transactionBytes: built.transactionBytes };
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
} catch {}
|
|
320
|
+
|
|
321
|
+
const start = SignerProviderRegistry.startHCSDelegate;
|
|
322
|
+
if (start) {
|
|
323
|
+
try {
|
|
324
|
+
const request: Record<string, unknown> = { registryTopicId, options };
|
|
325
|
+
const network = (this.hederaKit.client.network.toString().includes('mainnet') ? 'mainnet' : 'testnet') as NetworkString;
|
|
326
|
+
const { transactionBytes } = await start('hcs2.migrateRegistry', request, network);
|
|
327
|
+
if (transactionBytes) {
|
|
328
|
+
if (exec) {
|
|
329
|
+
return { success: true, transactionBytes };
|
|
330
|
+
}
|
|
331
|
+
if (!hasPrivateKey) {
|
|
332
|
+
return { success: true, transactionBytes };
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
} catch (err) {
|
|
336
|
+
if (preferWallet) {
|
|
337
|
+
const msg = `wallet_submit_failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
338
|
+
throw new CodedError('wallet_submit_failed', msg);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (preferWallet) {
|
|
344
|
+
throw new CodedError('wallet_unavailable', 'WalletExecutor not configured for hcs2.migrateRegistry');
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (!hasPrivateKey) {
|
|
348
|
+
throw new CodedError('wallet_unavailable', 'No wallet executor and no operator private key available for server execution');
|
|
349
|
+
}
|
|
105
350
|
const client = await this.getHCS2Client();
|
|
106
351
|
return await client.migrateRegistry(registryTopicId, options);
|
|
107
352
|
}
|
|
@@ -123,11 +368,59 @@ export class HCS2Builder extends BaseServiceBuilder {
|
|
|
123
368
|
async submitMessage(
|
|
124
369
|
topicId: string,
|
|
125
370
|
payload: any
|
|
126
|
-
): Promise<
|
|
371
|
+
): Promise<SubmitMessageResult> {
|
|
372
|
+
const exec = SignerProviderRegistry.walletExecutor;
|
|
373
|
+
const preferWallet = SignerProviderRegistry.preferWalletOnly;
|
|
374
|
+
const network = (this.hederaKit.client.network.toString().includes('mainnet') ? 'mainnet' : 'testnet') as NetworkString;
|
|
375
|
+
const hasPrivateKey = !!(this.hederaKit?.signer?.getOperatorPrivateKey && this.hederaKit.signer.getOperatorPrivateKey());
|
|
376
|
+
|
|
377
|
+
try {
|
|
378
|
+
const { ByteBuildRegistry } = await import('../../signing/bytes-registry');
|
|
379
|
+
if (ByteBuildRegistry.has('hcs2.submitMessage')) {
|
|
380
|
+
const built = await ByteBuildRegistry.build('hcs2.submitMessage', this.hederaKit, { topicId, payload });
|
|
381
|
+
if (built && built.transactionBytes) {
|
|
382
|
+
if (exec) {
|
|
383
|
+
return { success: true, transactionBytes: built.transactionBytes };
|
|
384
|
+
}
|
|
385
|
+
if (!hasPrivateKey) {
|
|
386
|
+
return { success: true, transactionBytes: built.transactionBytes };
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
} catch {}
|
|
391
|
+
|
|
392
|
+
const start = SignerProviderRegistry.startHCSDelegate;
|
|
393
|
+
if (start) {
|
|
394
|
+
try {
|
|
395
|
+
const request: Record<string, unknown> = { topicId, payload };
|
|
396
|
+
const { transactionBytes } = await start('hcs2.submitMessage', request, network);
|
|
397
|
+
if (transactionBytes) {
|
|
398
|
+
if (exec) {
|
|
399
|
+
return { success: true, transactionBytes };
|
|
400
|
+
}
|
|
401
|
+
if (!hasPrivateKey) {
|
|
402
|
+
return { success: true, transactionBytes };
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
} catch (err) {
|
|
406
|
+
if (preferWallet) {
|
|
407
|
+
const msg = `wallet_submit_failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
408
|
+
throw new CodedError('wallet_submit_failed', msg);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
if (preferWallet) {
|
|
414
|
+
throw new CodedError('wallet_unavailable', 'WalletExecutor not configured for hcs2.submitMessage');
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
if (!hasPrivateKey) {
|
|
418
|
+
throw new CodedError('wallet_unavailable', 'No wallet executor and no operator private key available for server execution');
|
|
419
|
+
}
|
|
127
420
|
const client = await this.getHCS2Client();
|
|
128
|
-
|
|
421
|
+
await client.submitMessage(topicId, payload);
|
|
422
|
+
return { success: true };
|
|
129
423
|
}
|
|
130
|
-
|
|
131
424
|
/**
|
|
132
425
|
* Get topic info from mirror node
|
|
133
426
|
*/
|