@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
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
import type { HederaAgentKit } from 'hedera-agent-kit';
|
|
2
|
+
import {
|
|
3
|
+
AccountId,
|
|
4
|
+
Client,
|
|
5
|
+
TopicCreateTransaction,
|
|
6
|
+
TopicId,
|
|
7
|
+
TopicMessageSubmitTransaction,
|
|
8
|
+
TransactionId,
|
|
9
|
+
} from '@hashgraph/sdk';
|
|
10
|
+
import {
|
|
11
|
+
buildHcs2CreateRegistryTx,
|
|
12
|
+
buildHcs2RegisterTx,
|
|
13
|
+
buildHcs2UpdateTx,
|
|
14
|
+
buildHcs2DeleteTx,
|
|
15
|
+
buildHcs2MigrateTx,
|
|
16
|
+
HCS2RegistryType,
|
|
17
|
+
buildHcs6CreateRegistryTx,
|
|
18
|
+
buildHcs6RegisterEntryTx,
|
|
19
|
+
buildHcs10SendMessageTx,
|
|
20
|
+
buildHcs10SubmitConnectionRequestTx,
|
|
21
|
+
buildHcs20DeployTx,
|
|
22
|
+
buildHcs20MintTx,
|
|
23
|
+
buildHcs20TransferTx,
|
|
24
|
+
buildHcs20BurnTx,
|
|
25
|
+
buildHcs20RegisterTx,
|
|
26
|
+
buildHcs12CreateRegistryTopicTx,
|
|
27
|
+
buildHcs12SubmitMessageTx,
|
|
28
|
+
buildHcs12RegisterAssemblyTx,
|
|
29
|
+
buildHcs12AddBlockToAssemblyTx,
|
|
30
|
+
buildHcs12AddActionToAssemblyTx,
|
|
31
|
+
buildHcs12UpdateAssemblyTx,
|
|
32
|
+
buildHcs7SubmitMessageTx,
|
|
33
|
+
buildHcs7EvmMessageTx,
|
|
34
|
+
buildHcs7WasmMessageTx,
|
|
35
|
+
} from '@hashgraphonline/standards-sdk';
|
|
36
|
+
|
|
37
|
+
export type ByteBuildHandler = (ctx: {
|
|
38
|
+
hederaKit: HederaAgentKit;
|
|
39
|
+
request: Record<string, unknown>;
|
|
40
|
+
}) => Promise<{ transactionBytes: string }>;
|
|
41
|
+
|
|
42
|
+
class ByteBuildRegistryImpl {
|
|
43
|
+
private handlers = new Map<string, ByteBuildHandler>();
|
|
44
|
+
|
|
45
|
+
register(op: string, handler: ByteBuildHandler): void {
|
|
46
|
+
this.handlers.set(op, handler);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
has(op: string): boolean {
|
|
50
|
+
return this.handlers.has(op);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async build(
|
|
54
|
+
op: string,
|
|
55
|
+
hederaKit: HederaAgentKit,
|
|
56
|
+
request: Record<string, unknown>
|
|
57
|
+
): Promise<{ transactionBytes: string } | null> {
|
|
58
|
+
const h = this.handlers.get(op);
|
|
59
|
+
if (!h) return null;
|
|
60
|
+
return await h({ hederaKit, request });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const ByteBuildRegistry = new ByteBuildRegistryImpl();
|
|
65
|
+
|
|
66
|
+
async function freezeTxToBytes(
|
|
67
|
+
hederaKit: HederaAgentKit,
|
|
68
|
+
tx: any,
|
|
69
|
+
): Promise<{ transactionBytes: string }> {
|
|
70
|
+
const network = hederaKit.client.network.toString().includes('mainnet')
|
|
71
|
+
? 'mainnet'
|
|
72
|
+
: 'testnet';
|
|
73
|
+
const client = network === 'mainnet' ? Client.forMainnet() : Client.forTestnet();
|
|
74
|
+
const operatorId = hederaKit.signer.getAccountId().toString();
|
|
75
|
+
const payer = AccountId.fromString(operatorId);
|
|
76
|
+
if (typeof tx.setTransactionId === 'function') {
|
|
77
|
+
tx.setTransactionId(TransactionId.generate(payer));
|
|
78
|
+
}
|
|
79
|
+
if (typeof tx.setAutoRenewAccountId === 'function') {
|
|
80
|
+
try { tx.setAutoRenewAccountId(operatorId); } catch {}
|
|
81
|
+
}
|
|
82
|
+
const frozen = await tx.freezeWith(client);
|
|
83
|
+
return { transactionBytes: Buffer.from(frozen.toBytes()).toString('base64') };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function buildTopicCreateBytes(
|
|
87
|
+
hederaKit: HederaAgentKit,
|
|
88
|
+
memo: string,
|
|
89
|
+
ttlSeconds?: number
|
|
90
|
+
): Promise<{ transactionBytes: string }> {
|
|
91
|
+
const network = hederaKit.client.network.toString().includes('mainnet')
|
|
92
|
+
? 'mainnet'
|
|
93
|
+
: 'testnet';
|
|
94
|
+
const client = network === 'mainnet' ? Client.forMainnet() : Client.forTestnet();
|
|
95
|
+
const operatorId = hederaKit.signer.getAccountId().toString();
|
|
96
|
+
const payer = AccountId.fromString(operatorId);
|
|
97
|
+
|
|
98
|
+
let tx = new TopicCreateTransaction()
|
|
99
|
+
.setTransactionId(TransactionId.generate(payer))
|
|
100
|
+
.setTopicMemo(memo);
|
|
101
|
+
if (ttlSeconds && Number.isFinite(ttlSeconds)) {
|
|
102
|
+
try {
|
|
103
|
+
tx = tx.setAutoRenewPeriod(ttlSeconds);
|
|
104
|
+
} catch {}
|
|
105
|
+
}
|
|
106
|
+
const frozen = await tx.freezeWith(client);
|
|
107
|
+
return { transactionBytes: Buffer.from(frozen.toBytes()).toString('base64') };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function buildTopicMessageBytes(
|
|
111
|
+
hederaKit: HederaAgentKit,
|
|
112
|
+
topicId: string,
|
|
113
|
+
message: string | Uint8Array,
|
|
114
|
+
memo?: string
|
|
115
|
+
): Promise<{ transactionBytes: string }> {
|
|
116
|
+
const network = hederaKit.client.network.toString().includes('mainnet')
|
|
117
|
+
? 'mainnet'
|
|
118
|
+
: 'testnet';
|
|
119
|
+
const client = network === 'mainnet' ? Client.forMainnet() : Client.forTestnet();
|
|
120
|
+
const operatorId = hederaKit.signer.getAccountId().toString();
|
|
121
|
+
const payer = AccountId.fromString(operatorId);
|
|
122
|
+
const tx = new TopicMessageSubmitTransaction()
|
|
123
|
+
.setTopicId(TopicId.fromString(topicId))
|
|
124
|
+
.setTransactionId(TransactionId.generate(payer))
|
|
125
|
+
.setMessage(message);
|
|
126
|
+
if (memo && memo.length > 0) {
|
|
127
|
+
tx.setTransactionMemo(memo);
|
|
128
|
+
}
|
|
129
|
+
const frozen = await tx.freezeWith(client);
|
|
130
|
+
return { transactionBytes: Buffer.from(frozen.toBytes()).toString('base64') };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
ByteBuildRegistry.register(
|
|
134
|
+
'hcs2.createRegistry',
|
|
135
|
+
async ({ hederaKit, request }) => {
|
|
136
|
+
const opts = (request?.options || {}) as {
|
|
137
|
+
registryType?: number;
|
|
138
|
+
ttl?: number;
|
|
139
|
+
adminKey?: string | boolean;
|
|
140
|
+
submitKey?: string | boolean;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
let operatorPublicKey: any | undefined;
|
|
144
|
+
try {
|
|
145
|
+
const priv = (hederaKit as any)?.signer?.getOperatorPrivateKey?.();
|
|
146
|
+
operatorPublicKey = priv?.publicKey;
|
|
147
|
+
} catch {}
|
|
148
|
+
|
|
149
|
+
const tx = buildHcs2CreateRegistryTx({
|
|
150
|
+
registryType: (opts.registryType ?? HCS2RegistryType.INDEXED) as any,
|
|
151
|
+
ttl: opts.ttl ?? 86400,
|
|
152
|
+
adminKey: opts.adminKey as any,
|
|
153
|
+
submitKey: opts.submitKey as any,
|
|
154
|
+
operatorPublicKey,
|
|
155
|
+
});
|
|
156
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
ByteBuildRegistry.register(
|
|
161
|
+
'hcs2.migrateRegistry',
|
|
162
|
+
async ({ hederaKit, request }) => {
|
|
163
|
+
if (!isRecord(request)) throw new Error('hcs2.migrateRegistry: invalid request payload');
|
|
164
|
+
const registryTopicId = getStringProp(request, 'registryTopicId') || '';
|
|
165
|
+
if (!registryTopicId) throw new Error('hcs2.migrateRegistry: registryTopicId is required');
|
|
166
|
+
const options = getObjectProp(request, 'options') || {};
|
|
167
|
+
const targetTopicId = getStringProp(options, 'targetTopicId') || '';
|
|
168
|
+
const metadata = getStringProp(options, 'metadata');
|
|
169
|
+
const memo = getStringProp(options, 'memo');
|
|
170
|
+
const tx = buildHcs2MigrateTx({
|
|
171
|
+
registryTopicId,
|
|
172
|
+
targetTopicId,
|
|
173
|
+
metadata,
|
|
174
|
+
memo,
|
|
175
|
+
});
|
|
176
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
function isRecord(x: unknown): x is Record<string, unknown> {
|
|
181
|
+
return typeof x === 'object' && x !== null;
|
|
182
|
+
}
|
|
183
|
+
function getStringProp(
|
|
184
|
+
obj: Record<string, unknown>,
|
|
185
|
+
key: string
|
|
186
|
+
): string | undefined {
|
|
187
|
+
const val = obj[key];
|
|
188
|
+
return typeof val === 'string' ? val : undefined;
|
|
189
|
+
}
|
|
190
|
+
function getNumberProp(
|
|
191
|
+
obj: Record<string, unknown>,
|
|
192
|
+
key: string
|
|
193
|
+
): number | undefined {
|
|
194
|
+
const val = obj[key];
|
|
195
|
+
return typeof val === 'number' && Number.isFinite(val) ? val : undefined;
|
|
196
|
+
}
|
|
197
|
+
function getObjectProp(
|
|
198
|
+
obj: Record<string, unknown>,
|
|
199
|
+
key: string
|
|
200
|
+
): Record<string, unknown> | undefined {
|
|
201
|
+
const val = obj[key];
|
|
202
|
+
return isRecord(val) ? val : undefined;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
ByteBuildRegistry.register(
|
|
206
|
+
'hcs2.submitMessage',
|
|
207
|
+
async ({ hederaKit, request }) => {
|
|
208
|
+
if (!isRecord(request))
|
|
209
|
+
throw new Error('hcs2.submitMessage: invalid request payload');
|
|
210
|
+
const topicId =
|
|
211
|
+
getStringProp(request, 'topicId') ||
|
|
212
|
+
getStringProp(request, 'registryTopicId') ||
|
|
213
|
+
'';
|
|
214
|
+
if (!topicId) throw new Error('hcs2.submitMessage: topicId is required');
|
|
215
|
+
const payload = request['payload'];
|
|
216
|
+
const message =
|
|
217
|
+
typeof payload === 'string' ? payload : JSON.stringify(payload ?? {});
|
|
218
|
+
return await buildTopicMessageBytes(hederaKit, topicId, message);
|
|
219
|
+
}
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
ByteBuildRegistry.register('hcs2.registerEntry', async ({ hederaKit, request }) => {
|
|
223
|
+
if (!isRecord(request)) throw new Error('hcs2.registerEntry: invalid request payload');
|
|
224
|
+
const registryTopicId = getStringProp(request, 'registryTopicId') || '';
|
|
225
|
+
if (!registryTopicId) throw new Error('hcs2.registerEntry: registryTopicId is required');
|
|
226
|
+
const options = getObjectProp(request, 'options') || {};
|
|
227
|
+
const targetTopicId = getStringProp(options, 'targetTopicId') || '';
|
|
228
|
+
const metadata = getStringProp(options, 'metadata');
|
|
229
|
+
const memo = getStringProp(options, 'memo');
|
|
230
|
+
const tx = buildHcs2RegisterTx({
|
|
231
|
+
registryTopicId,
|
|
232
|
+
targetTopicId,
|
|
233
|
+
metadata,
|
|
234
|
+
memo,
|
|
235
|
+
});
|
|
236
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
ByteBuildRegistry.register('hcs2.updateEntry', async ({ hederaKit, request }) => {
|
|
240
|
+
if (!isRecord(request)) throw new Error('hcs2.updateEntry: invalid request payload');
|
|
241
|
+
const registryTopicId = getStringProp(request, 'registryTopicId') || '';
|
|
242
|
+
if (!registryTopicId) throw new Error('hcs2.updateEntry: registryTopicId is required');
|
|
243
|
+
const options = getObjectProp(request, 'options') || {};
|
|
244
|
+
const targetTopicId = getStringProp(options, 'targetTopicId') || '';
|
|
245
|
+
const uid = getStringProp(options, 'uid') || '';
|
|
246
|
+
const metadata = getStringProp(options, 'metadata');
|
|
247
|
+
const memo = getStringProp(options, 'memo');
|
|
248
|
+
const tx = buildHcs2UpdateTx({
|
|
249
|
+
registryTopicId,
|
|
250
|
+
uid,
|
|
251
|
+
targetTopicId,
|
|
252
|
+
metadata,
|
|
253
|
+
memo,
|
|
254
|
+
});
|
|
255
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
ByteBuildRegistry.register('hcs2.deleteEntry', async ({ hederaKit, request }) => {
|
|
259
|
+
if (!isRecord(request)) throw new Error('hcs2.deleteEntry: invalid request payload');
|
|
260
|
+
const registryTopicId = getStringProp(request, 'registryTopicId') || '';
|
|
261
|
+
if (!registryTopicId) throw new Error('hcs2.deleteEntry: registryTopicId is required');
|
|
262
|
+
const options = getObjectProp(request, 'options') || {};
|
|
263
|
+
const uid = getStringProp(options, 'uid') || '';
|
|
264
|
+
const memo = getStringProp(options, 'memo');
|
|
265
|
+
const tx = buildHcs2DeleteTx({
|
|
266
|
+
registryTopicId,
|
|
267
|
+
uid,
|
|
268
|
+
memo,
|
|
269
|
+
});
|
|
270
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
ByteBuildRegistry.register(
|
|
274
|
+
'hcs6.createRegistry',
|
|
275
|
+
async ({ hederaKit, request }) => {
|
|
276
|
+
const opts = isRecord(request) ? getObjectProp(request, 'options') : undefined;
|
|
277
|
+
const ttl = opts ? getNumberProp(opts, 'ttl') : undefined;
|
|
278
|
+
|
|
279
|
+
let operatorPublicKey: any | undefined;
|
|
280
|
+
try {
|
|
281
|
+
const priv = (hederaKit as any)?.signer?.getOperatorPrivateKey?.();
|
|
282
|
+
operatorPublicKey = priv?.publicKey;
|
|
283
|
+
} catch {}
|
|
284
|
+
|
|
285
|
+
const tx = buildHcs6CreateRegistryTx({ ttl: ttl ?? 86400, operatorPublicKey });
|
|
286
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
287
|
+
}
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
ByteBuildRegistry.register(
|
|
291
|
+
'hcs6.registerEntry',
|
|
292
|
+
async ({ hederaKit, request }) => {
|
|
293
|
+
if (!isRecord(request))
|
|
294
|
+
throw new Error('hcs6.registerEntry: invalid request payload');
|
|
295
|
+
const registryTopicId = getStringProp(request, 'registryTopicId') || '';
|
|
296
|
+
if (!registryTopicId)
|
|
297
|
+
throw new Error('hcs6.registerEntry: registryTopicId is required');
|
|
298
|
+
const options = getObjectProp(request, 'options') || {};
|
|
299
|
+
const targetTopicId = getStringProp(options, 'targetTopicId') || '';
|
|
300
|
+
const memo = getStringProp(options, 'memo');
|
|
301
|
+
const tx = buildHcs6RegisterEntryTx({
|
|
302
|
+
registryTopicId,
|
|
303
|
+
targetTopicId,
|
|
304
|
+
memo,
|
|
305
|
+
});
|
|
306
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
307
|
+
}
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
ByteBuildRegistry.register(
|
|
311
|
+
'hcs6.submitMessage',
|
|
312
|
+
async ({ hederaKit, request }) => {
|
|
313
|
+
if (!isRecord(request))
|
|
314
|
+
throw new Error('hcs6.submitMessage: invalid request payload');
|
|
315
|
+
const topicId = getStringProp(request, 'topicId') || '';
|
|
316
|
+
if (!topicId) throw new Error('hcs6.submitMessage: topicId is required');
|
|
317
|
+
const payload = request['payload'];
|
|
318
|
+
const message =
|
|
319
|
+
typeof payload === 'string' ? payload : JSON.stringify(payload ?? {});
|
|
320
|
+
return await buildTopicMessageBytes(hederaKit, topicId, message);
|
|
321
|
+
}
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
ByteBuildRegistry.register('sendMessage', async ({ hederaKit, request }) => {
|
|
325
|
+
if (!isRecord(request))
|
|
326
|
+
throw new Error('sendMessage: invalid request payload');
|
|
327
|
+
const topicId = getStringProp(request, 'topicId') || '';
|
|
328
|
+
if (!topicId) throw new Error('sendMessage: topicId is required');
|
|
329
|
+
const dataVal = request['data'];
|
|
330
|
+
const memo = getStringProp(request, 'memo') || '';
|
|
331
|
+
const operatorId = hederaKit.signer.getAccountId().toString();
|
|
332
|
+
const data = typeof dataVal === 'string' ? dataVal : JSON.stringify(dataVal ?? {});
|
|
333
|
+
const tx = buildHcs10SendMessageTx({ connectionTopicId: topicId, operatorId, data, memo });
|
|
334
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
ByteBuildRegistry.register(
|
|
338
|
+
'submitConnectionRequest',
|
|
339
|
+
async ({ hederaKit, request }) => {
|
|
340
|
+
if (!isRecord(request))
|
|
341
|
+
throw new Error('submitConnectionRequest: invalid request payload');
|
|
342
|
+
const inboundTopicId = getStringProp(request, 'inboundTopicId') || '';
|
|
343
|
+
if (!inboundTopicId)
|
|
344
|
+
throw new Error('submitConnectionRequest: inboundTopicId is required');
|
|
345
|
+
const memo = getStringProp(request, 'memo') || '';
|
|
346
|
+
const operatorId = hederaKit.signer.getAccountId().toString();
|
|
347
|
+
const tx = buildHcs10SubmitConnectionRequestTx({ inboundTopicId, operatorId, memo });
|
|
348
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
349
|
+
}
|
|
350
|
+
);
|
|
351
|
+
|
|
352
|
+
ByteBuildRegistry.register('hcs20.deploy', async ({ hederaKit, request }) => {
|
|
353
|
+
if (!isRecord(request)) throw new Error('hcs20.deploy: invalid request payload');
|
|
354
|
+
const topicId = getStringProp(request, 'topicId') || '';
|
|
355
|
+
if (!topicId) throw new Error('hcs20.deploy: topicId is required');
|
|
356
|
+
const name = getStringProp(request, 'name') || '';
|
|
357
|
+
const tick = getStringProp(request, 'tick') || '';
|
|
358
|
+
const max = getStringProp(request, 'max') || '';
|
|
359
|
+
const lim = getStringProp(request, 'lim');
|
|
360
|
+
const metadata = getStringProp(request, 'metadata');
|
|
361
|
+
const memo = getStringProp(request, 'memo');
|
|
362
|
+
const tx = buildHcs20DeployTx({ topicId, name, tick, max, lim, metadata, memo });
|
|
363
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
ByteBuildRegistry.register('hcs20.mint', async ({ hederaKit, request }) => {
|
|
367
|
+
if (!isRecord(request)) throw new Error('hcs20.mint: invalid request payload');
|
|
368
|
+
const topicId = getStringProp(request, 'topicId') || '';
|
|
369
|
+
if (!topicId) throw new Error('hcs20.mint: topicId is required');
|
|
370
|
+
const tick = getStringProp(request, 'tick') || '';
|
|
371
|
+
const amt = getStringProp(request, 'amt') || '';
|
|
372
|
+
const to = getStringProp(request, 'to') || '';
|
|
373
|
+
const memo = getStringProp(request, 'memo');
|
|
374
|
+
const tx = buildHcs20MintTx({ topicId, tick, amt, to, memo });
|
|
375
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
ByteBuildRegistry.register('hcs20.transfer', async ({ hederaKit, request }) => {
|
|
379
|
+
if (!isRecord(request)) throw new Error('hcs20.transfer: invalid request payload');
|
|
380
|
+
const topicId = getStringProp(request, 'topicId') || '';
|
|
381
|
+
if (!topicId) throw new Error('hcs20.transfer: topicId is required');
|
|
382
|
+
const tick = getStringProp(request, 'tick') || '';
|
|
383
|
+
const amt = getStringProp(request, 'amt') || '';
|
|
384
|
+
const from = getStringProp(request, 'from') || '';
|
|
385
|
+
const to = getStringProp(request, 'to') || '';
|
|
386
|
+
const memo = getStringProp(request, 'memo');
|
|
387
|
+
const tx = buildHcs20TransferTx({ topicId, tick, amt, from, to, memo });
|
|
388
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
ByteBuildRegistry.register('hcs20.burn', async ({ hederaKit, request }) => {
|
|
392
|
+
if (!isRecord(request)) throw new Error('hcs20.burn: invalid request payload');
|
|
393
|
+
const topicId = getStringProp(request, 'topicId') || '';
|
|
394
|
+
if (!topicId) throw new Error('hcs20.burn: topicId is required');
|
|
395
|
+
const tick = getStringProp(request, 'tick') || '';
|
|
396
|
+
const amt = getStringProp(request, 'amt') || '';
|
|
397
|
+
const from = getStringProp(request, 'from') || '';
|
|
398
|
+
const memo = getStringProp(request, 'memo');
|
|
399
|
+
const tx = buildHcs20BurnTx({ topicId, tick, amt, from, memo });
|
|
400
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
ByteBuildRegistry.register('hcs20.register', async ({ hederaKit, request }) => {
|
|
404
|
+
if (!isRecord(request)) throw new Error('hcs20.register: invalid request payload');
|
|
405
|
+
const registryTopicId = getStringProp(request, 'registryTopicId') || '';
|
|
406
|
+
if (!registryTopicId) throw new Error('hcs20.register: registryTopicId is required');
|
|
407
|
+
const topicId = getStringProp(request, 'topicId') || '';
|
|
408
|
+
const name = getStringProp(request, 'name') || '';
|
|
409
|
+
const isPrivateVal = (request as any)['isPrivate'];
|
|
410
|
+
const isPrivate = typeof isPrivateVal === 'boolean' ? isPrivateVal : false;
|
|
411
|
+
const metadata = getStringProp(request, 'metadata');
|
|
412
|
+
const memo = getStringProp(request, 'memo');
|
|
413
|
+
const tx = buildHcs20RegisterTx({ registryTopicId, name, topicId, isPrivate, metadata, memo });
|
|
414
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
ByteBuildRegistry.register('hcs12.createRegistry', async ({ hederaKit, request }) => {
|
|
418
|
+
const opts = isRecord(request) ? getObjectProp(request, 'options') : undefined;
|
|
419
|
+
const ttlVal = opts ? getNumberProp(opts, 'ttl') : undefined;
|
|
420
|
+
const ttl = (ttlVal ?? 60) as number;
|
|
421
|
+
const registry = (opts && getStringProp(opts, 'registry')) || 'hashlinks';
|
|
422
|
+
let operatorPublicKey: any | undefined;
|
|
423
|
+
try {
|
|
424
|
+
const priv = (hederaKit as any)?.signer?.getOperatorPrivateKey?.();
|
|
425
|
+
operatorPublicKey = priv?.publicKey;
|
|
426
|
+
} catch {}
|
|
427
|
+
const tx = buildHcs12CreateRegistryTopicTx({ registry: registry as any, ttl, operatorPublicKey });
|
|
428
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
ByteBuildRegistry.register('hcs12.submitMessage', async ({ hederaKit, request }) => {
|
|
432
|
+
if (!isRecord(request)) throw new Error('hcs12.submitMessage: invalid request payload');
|
|
433
|
+
const topicId = getStringProp(request, 'topicId') || '';
|
|
434
|
+
if (!topicId) throw new Error('hcs12.submitMessage: topicId is required');
|
|
435
|
+
const payload = (request as any)['payload'];
|
|
436
|
+
const tx = buildHcs12SubmitMessageTx({ topicId, payload: payload as any });
|
|
437
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
ByteBuildRegistry.register('hcs12.registerAssembly', async ({ hederaKit, request }) => {
|
|
441
|
+
if (!isRecord(request)) throw new Error('hcs12.registerAssembly: invalid request payload');
|
|
442
|
+
const assemblyTopicId = getStringProp(request, 'assemblyTopicId') || '';
|
|
443
|
+
if (!assemblyTopicId) throw new Error('hcs12.registerAssembly: assemblyTopicId is required');
|
|
444
|
+
const registration = getObjectProp(request, 'registration') || {};
|
|
445
|
+
const tx = buildHcs12RegisterAssemblyTx({ assemblyTopicId, registration: registration as any });
|
|
446
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
ByteBuildRegistry.register('hcs12.addBlock', async ({ hederaKit, request }) => {
|
|
450
|
+
if (!isRecord(request)) throw new Error('hcs12.addBlock: invalid request payload');
|
|
451
|
+
const assemblyTopicId = getStringProp(request, 'assemblyTopicId') || '';
|
|
452
|
+
if (!assemblyTopicId) throw new Error('hcs12.addBlock: assemblyTopicId is required');
|
|
453
|
+
const operation = getObjectProp(request, 'operation') || {};
|
|
454
|
+
const tx = buildHcs12AddBlockToAssemblyTx({ assemblyTopicId, operation: operation as any });
|
|
455
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
ByteBuildRegistry.register('hcs12.addAction', async ({ hederaKit, request }) => {
|
|
459
|
+
if (!isRecord(request)) throw new Error('hcs12.addAction: invalid request payload');
|
|
460
|
+
const assemblyTopicId = getStringProp(request, 'assemblyTopicId') || '';
|
|
461
|
+
if (!assemblyTopicId) throw new Error('hcs12.addAction: assemblyTopicId is required');
|
|
462
|
+
const operation = getObjectProp(request, 'operation') || {};
|
|
463
|
+
const tx = buildHcs12AddActionToAssemblyTx({ assemblyTopicId, operation: operation as any });
|
|
464
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
ByteBuildRegistry.register('hcs12.updateAssembly', async ({ hederaKit, request }) => {
|
|
468
|
+
if (!isRecord(request)) throw new Error('hcs12.updateAssembly: invalid request payload');
|
|
469
|
+
const assemblyTopicId = getStringProp(request, 'assemblyTopicId') || '';
|
|
470
|
+
if (!assemblyTopicId) throw new Error('hcs12.updateAssembly: assemblyTopicId is required');
|
|
471
|
+
const operation = getObjectProp(request, 'operation') || {};
|
|
472
|
+
const tx = buildHcs12UpdateAssemblyTx({ assemblyTopicId, operation: operation as any });
|
|
473
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
ByteBuildRegistry.register('hcs7.submitMessage', async ({ hederaKit, request }) => {
|
|
477
|
+
if (!isRecord(request)) throw new Error('hcs7.submitMessage: invalid request payload');
|
|
478
|
+
const topicId = getStringProp(request, 'topicId') || '';
|
|
479
|
+
if (!topicId) throw new Error('hcs7.submitMessage: topicId is required');
|
|
480
|
+
const message = getObjectProp(request, 'message') || {};
|
|
481
|
+
const tx = buildHcs7SubmitMessageTx({ topicId, message: message as any });
|
|
482
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
ByteBuildRegistry.register('hcs7.evm', async ({ hederaKit, request }) => {
|
|
486
|
+
if (!isRecord(request)) throw new Error('hcs7.evm: invalid request payload');
|
|
487
|
+
const topicId = getStringProp(request, 'topicId') || '';
|
|
488
|
+
if (!topicId) throw new Error('hcs7.evm: topicId is required');
|
|
489
|
+
const config = getObjectProp(request, 'config') || {};
|
|
490
|
+
const tx = buildHcs7EvmMessageTx({ topicId, config: config as any });
|
|
491
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
ByteBuildRegistry.register('hcs7.wasm', async ({ hederaKit, request }) => {
|
|
495
|
+
if (!isRecord(request)) throw new Error('hcs7.wasm: invalid request payload');
|
|
496
|
+
const topicId = getStringProp(request, 'topicId') || '';
|
|
497
|
+
if (!topicId) throw new Error('hcs7.wasm: topicId is required');
|
|
498
|
+
const config = getObjectProp(request, 'config') || {};
|
|
499
|
+
const tx = buildHcs7WasmMessageTx({ topicId, config: config as any });
|
|
500
|
+
return await freezeTxToBytes(hederaKit, tx);
|
|
501
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
export type NetworkString = 'mainnet' | 'testnet'
|
|
2
|
+
|
|
3
|
+
export interface DAppSigner {
|
|
4
|
+
getAccountId(): { toString(): string }
|
|
5
|
+
[key: string]: unknown
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type WalletInfo = { accountId: string; network: NetworkString }
|
|
9
|
+
|
|
10
|
+
export type WalletInfoResolver = () => Promise<WalletInfo | null> | WalletInfo | null
|
|
11
|
+
|
|
12
|
+
export type WalletExecutor = (
|
|
13
|
+
base64: string,
|
|
14
|
+
network: NetworkString
|
|
15
|
+
) => Promise<{ transactionId: string }>
|
|
16
|
+
|
|
17
|
+
export type HCSOperation =
|
|
18
|
+
| 'submitConnectionRequest'
|
|
19
|
+
| 'handleConnectionRequest'
|
|
20
|
+
| 'sendMessage'
|
|
21
|
+
| 'hcs2.createRegistry'
|
|
22
|
+
| 'hcs2.migrateRegistry'
|
|
23
|
+
| 'hcs2.registerEntry'
|
|
24
|
+
| 'hcs2.updateEntry'
|
|
25
|
+
| 'hcs2.deleteEntry'
|
|
26
|
+
| 'hcs2.submitMessage'
|
|
27
|
+
| 'hcs6.createRegistry'
|
|
28
|
+
| 'hcs6.registerEntry'
|
|
29
|
+
| 'hcs6.submitMessage'
|
|
30
|
+
|
|
31
|
+
export type StartHCSDelegate = (
|
|
32
|
+
op: HCSOperation,
|
|
33
|
+
request: Record<string, unknown>,
|
|
34
|
+
network: NetworkString
|
|
35
|
+
) => Promise<{ transactionBytes: string }>
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Central registry for browser signer and wallet execution delegates
|
|
39
|
+
*/
|
|
40
|
+
export class SignerProviderRegistry {
|
|
41
|
+
private static _signerProvider: (() => Promise<DAppSigner | null>) | (() => DAppSigner | null) | DAppSigner | null
|
|
42
|
+
private static _walletInfoResolver: WalletInfoResolver | null
|
|
43
|
+
private static _walletExecutor: WalletExecutor | null
|
|
44
|
+
private static _startHCSDelegate: StartHCSDelegate | null
|
|
45
|
+
private static _browserHCSClientFactory: ((network: NetworkString) => unknown) | null
|
|
46
|
+
private static _preferWalletOnly = false
|
|
47
|
+
|
|
48
|
+
static setSignerProvider(provider: typeof SignerProviderRegistry._signerProvider): void {
|
|
49
|
+
this._signerProvider = provider
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static async getSigner(): Promise<DAppSigner | null> {
|
|
53
|
+
const p = this._signerProvider
|
|
54
|
+
if (!p) return null
|
|
55
|
+
try {
|
|
56
|
+
if (typeof p === 'function') {
|
|
57
|
+
const val = (p as () => Promise<DAppSigner | null> | DAppSigner | null)()
|
|
58
|
+
return (val && typeof (val as Promise<unknown>).then === 'function')
|
|
59
|
+
? await (val as Promise<DAppSigner | null>)
|
|
60
|
+
: (val as DAppSigner | null)
|
|
61
|
+
}
|
|
62
|
+
return p as DAppSigner
|
|
63
|
+
} catch {
|
|
64
|
+
return null
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static setWalletInfoResolver(resolver: WalletInfoResolver | null): void {
|
|
69
|
+
this._walletInfoResolver = resolver || null
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static async getWalletInfo(): Promise<WalletInfo | null> {
|
|
73
|
+
const r = this._walletInfoResolver
|
|
74
|
+
if (!r) return null
|
|
75
|
+
try {
|
|
76
|
+
const val = r()
|
|
77
|
+
return (val && typeof (val as Promise<unknown>).then === 'function')
|
|
78
|
+
? await (val as Promise<WalletInfo | null>)
|
|
79
|
+
: (val as WalletInfo | null)
|
|
80
|
+
} catch {
|
|
81
|
+
return null
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static setWalletExecutor(executor: WalletExecutor | null): void {
|
|
86
|
+
this._walletExecutor = executor || null
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static get walletExecutor(): WalletExecutor | null {
|
|
90
|
+
return this._walletExecutor || null
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
static setStartHCSDelegate(delegate: StartHCSDelegate | null): void {
|
|
94
|
+
this._startHCSDelegate = delegate || null
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static get startHCSDelegate(): StartHCSDelegate | null {
|
|
98
|
+
return this._startHCSDelegate || null
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
static setPreferWalletOnly(flag: boolean): void {
|
|
102
|
+
this._preferWalletOnly = !!flag
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Register a factory to construct a BrowserHCSClient-like instance for wallet-driven flows
|
|
107
|
+
*/
|
|
108
|
+
static setBrowserHCSClientFactory(factory: ((network: NetworkString) => unknown) | null): void {
|
|
109
|
+
this._browserHCSClientFactory = factory || null
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
static getBrowserHCSClient(network: NetworkString): unknown | null {
|
|
113
|
+
return this._browserHCSClientFactory ? this._browserHCSClientFactory(network) : null
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
static get preferWalletOnly(): boolean {
|
|
117
|
+
return this._preferWalletOnly
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
@@ -2,6 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
import { BaseHCS2QueryTool } from './base-hcs2-tools';
|
|
3
3
|
import { HCS2RegistryType } from '@hashgraphonline/standards-sdk';
|
|
4
4
|
import { CallbackManagerForToolRun } from '@langchain/core/callbacks/manager';
|
|
5
|
+
import { isWalletBytesResponse, type TopicRegistrationResult } from '../../types/tx-results';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Schema for creating an HCS-2 registry
|
|
@@ -32,7 +33,7 @@ const createRegistrySchema = z.object({
|
|
|
32
33
|
*/
|
|
33
34
|
export class CreateRegistryTool extends BaseHCS2QueryTool<typeof createRegistrySchema> {
|
|
34
35
|
name = 'createHCS2Registry';
|
|
35
|
-
description = 'Create
|
|
36
|
+
description = 'Create an HCS-2 registry (standard HCS-2). Use when the user asks to create an HCS-2 registry, not a generic HCS topic. Builds a standards-compliant registry topic and returns the result or transaction bytes.'
|
|
36
37
|
|
|
37
38
|
get specificInputSchema(): typeof createRegistrySchema {
|
|
38
39
|
return createRegistrySchema;
|
|
@@ -42,19 +43,43 @@ export class CreateRegistryTool extends BaseHCS2QueryTool<typeof createRegistryS
|
|
|
42
43
|
params: z.infer<typeof createRegistrySchema>,
|
|
43
44
|
_runManager?: CallbackManagerForToolRun
|
|
44
45
|
): Promise<unknown> {
|
|
46
|
+
const normalizeKey = (val?: string | boolean): string | boolean | undefined => {
|
|
47
|
+
if (typeof val === 'string') {
|
|
48
|
+
const lc = val.trim().toLowerCase();
|
|
49
|
+
if (lc === 'true') return true;
|
|
50
|
+
if (lc === 'false') return false;
|
|
51
|
+
return val; // assume public key string
|
|
52
|
+
}
|
|
53
|
+
return val;
|
|
54
|
+
};
|
|
55
|
+
|
|
45
56
|
try {
|
|
46
|
-
const result = await this.hcs2Builder.createRegistry({
|
|
57
|
+
const result: TopicRegistrationResult = await this.hcs2Builder.createRegistry({
|
|
47
58
|
registryType: params.registryType,
|
|
48
59
|
ttl: params.ttl,
|
|
49
|
-
adminKey: params.adminKey,
|
|
50
|
-
submitKey: params.submitKey,
|
|
60
|
+
adminKey: normalizeKey(params.adminKey),
|
|
61
|
+
submitKey: normalizeKey(params.submitKey),
|
|
51
62
|
});
|
|
52
63
|
|
|
53
64
|
if (!result.success) {
|
|
54
65
|
throw new Error(result.error || 'Failed to create registry');
|
|
55
66
|
}
|
|
56
67
|
|
|
57
|
-
|
|
68
|
+
if (isWalletBytesResponse(result)) {
|
|
69
|
+
const txBytes = result.transactionBytes;
|
|
70
|
+
return {
|
|
71
|
+
message: 'I prepared an unsigned transaction to create your HCS-2 registry. Please review and approve to submit.',
|
|
72
|
+
transactionBytes: txBytes,
|
|
73
|
+
metadata: {
|
|
74
|
+
transactionBytes: txBytes,
|
|
75
|
+
pendingApproval: true,
|
|
76
|
+
description: `Create HCS-2 registry (${params.registryType === 1 ? 'Non-Indexed' : 'Indexed'}; TTL: ${params.ttl || 86400}s)`,
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const topicId = (result as any)?.topicId || 'unknown';
|
|
82
|
+
return `Successfully created HCS-2 registry!\n\nTopic ID: ${topicId}\nRegistry Type: ${params.registryType === 1 ? 'Non-Indexed' : 'Indexed'}\nTTL: ${params.ttl || 86400} seconds\n\nYou can now register entries to this registry using the topic ID.`;
|
|
58
83
|
} catch (error) {
|
|
59
84
|
const errorMessage = error instanceof Error ? error.message : 'Failed to create HCS-2 registry';
|
|
60
85
|
throw new Error(`Registry creation failed: ${errorMessage}`);
|