@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
|
@@ -14,6 +14,9 @@ import {
|
|
|
14
14
|
HCS6CreateHashinalResponse,
|
|
15
15
|
NetworkType,
|
|
16
16
|
} from '@hashgraphonline/standards-sdk';
|
|
17
|
+
import { SignerProviderRegistry, type NetworkString } from '../../signing/signer-provider';
|
|
18
|
+
import type { HCS6TopicRegistrationResult, HCS6RegistryOperationResult, HCS6CreateHashinalResult } from '../../types/tx-results';
|
|
19
|
+
import { CodedError } from '../../utils/CodedError';
|
|
17
20
|
|
|
18
21
|
/**
|
|
19
22
|
* Builder for HCS-6 operations that delegates to HCS6Client
|
|
@@ -57,7 +60,31 @@ export class HCS6Builder extends BaseServiceBuilder {
|
|
|
57
60
|
*/
|
|
58
61
|
async createRegistry(
|
|
59
62
|
options: HCS6CreateRegistryOptions = {}
|
|
60
|
-
): Promise<
|
|
63
|
+
): Promise<HCS6TopicRegistrationResult> {
|
|
64
|
+
const exec = SignerProviderRegistry.walletExecutor;
|
|
65
|
+
const preferWallet = SignerProviderRegistry.preferWalletOnly;
|
|
66
|
+
const network = (this.hederaKit.client.network.toString().includes('mainnet') ? 'mainnet' : 'testnet') as NetworkString;
|
|
67
|
+
|
|
68
|
+
if (exec) {
|
|
69
|
+
const start = SignerProviderRegistry.startHCSDelegate;
|
|
70
|
+
if (start) {
|
|
71
|
+
try {
|
|
72
|
+
const request: Record<string, unknown> = { options };
|
|
73
|
+
const { transactionBytes } = await start('hcs6.createRegistry', request, network);
|
|
74
|
+
if (transactionBytes) {
|
|
75
|
+
return { success: true, transactionBytes };
|
|
76
|
+
}
|
|
77
|
+
} catch (err) {
|
|
78
|
+
if (preferWallet) {
|
|
79
|
+
throw new CodedError('wallet_submit_failed', `wallet_submit_failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (preferWallet) {
|
|
84
|
+
throw new CodedError('wallet_unavailable', 'WalletExecutor not configured for hcs6.createRegistry');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
61
88
|
const client = await this.getHCS6Client();
|
|
62
89
|
const sanitized = { ...options };
|
|
63
90
|
if ('adminKey' in sanitized) {
|
|
@@ -72,7 +99,31 @@ export class HCS6Builder extends BaseServiceBuilder {
|
|
|
72
99
|
async registerEntry(
|
|
73
100
|
registryTopicId: string,
|
|
74
101
|
options: HCS6RegisterEntryOptions
|
|
75
|
-
): Promise<
|
|
102
|
+
): Promise<HCS6RegistryOperationResult> {
|
|
103
|
+
const exec = SignerProviderRegistry.walletExecutor;
|
|
104
|
+
const preferWallet = SignerProviderRegistry.preferWalletOnly;
|
|
105
|
+
const network = (this.hederaKit.client.network.toString().includes('mainnet') ? 'mainnet' : 'testnet') as NetworkString;
|
|
106
|
+
|
|
107
|
+
if (exec) {
|
|
108
|
+
const start = SignerProviderRegistry.startHCSDelegate;
|
|
109
|
+
if (start) {
|
|
110
|
+
try {
|
|
111
|
+
const request: Record<string, unknown> = { registryTopicId, options };
|
|
112
|
+
const { transactionBytes } = await start('hcs6.registerEntry', request, network);
|
|
113
|
+
if (transactionBytes) {
|
|
114
|
+
return { success: true, transactionBytes };
|
|
115
|
+
}
|
|
116
|
+
} catch (err) {
|
|
117
|
+
if (preferWallet) {
|
|
118
|
+
throw new CodedError('wallet_submit_failed', `wallet_submit_failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (preferWallet) {
|
|
123
|
+
throw new CodedError('wallet_unavailable', 'WalletExecutor not configured for hcs6.registerEntry');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
76
127
|
const client = await this.getHCS6Client();
|
|
77
128
|
return await client.registerEntry(registryTopicId, options);
|
|
78
129
|
}
|
|
@@ -140,9 +191,33 @@ export class HCS6Builder extends BaseServiceBuilder {
|
|
|
140
191
|
async submitMessage(
|
|
141
192
|
topicId: string,
|
|
142
193
|
payload: any
|
|
143
|
-
): Promise<
|
|
194
|
+
): Promise<HCS6RegistryOperationResult> {
|
|
195
|
+
const exec = SignerProviderRegistry.walletExecutor;
|
|
196
|
+
const preferWallet = SignerProviderRegistry.preferWalletOnly;
|
|
197
|
+
const network = (this.hederaKit.client.network.toString().includes('mainnet') ? 'mainnet' : 'testnet') as NetworkString;
|
|
198
|
+
|
|
199
|
+
if (exec) {
|
|
200
|
+
const start = SignerProviderRegistry.startHCSDelegate;
|
|
201
|
+
if (start) {
|
|
202
|
+
try {
|
|
203
|
+
const request: Record<string, unknown> = { topicId, payload };
|
|
204
|
+
const { transactionBytes } = await start('hcs6.submitMessage', request, network);
|
|
205
|
+
if (transactionBytes) {
|
|
206
|
+
return { success: true, transactionBytes } as unknown as HCS6RegistryOperationResult;
|
|
207
|
+
}
|
|
208
|
+
} catch (err) {
|
|
209
|
+
if (preferWallet) {
|
|
210
|
+
throw new CodedError('wallet_submit_failed', `wallet_submit_failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (preferWallet) {
|
|
215
|
+
throw new CodedError('wallet_unavailable', 'WalletExecutor not configured for hcs6.submitMessage');
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
144
219
|
const client = await this.getHCS6Client();
|
|
145
|
-
return await client.submitMessage(topicId, payload);
|
|
220
|
+
return await client.submitMessage(topicId, payload) as unknown as HCS6RegistryOperationResult;
|
|
146
221
|
}
|
|
147
222
|
|
|
148
223
|
/**
|
|
@@ -10,8 +10,10 @@ import {
|
|
|
10
10
|
RetrievedInscriptionResult,
|
|
11
11
|
HederaClientConfig,
|
|
12
12
|
NetworkType,
|
|
13
|
+
getTopicId,
|
|
13
14
|
} from '@hashgraphonline/standards-sdk';
|
|
14
15
|
import { InscriptionSDK } from '@kiloscribe/inscription-sdk';
|
|
16
|
+
import type { AgentOperationalMode } from 'hedera-agent-kit';
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* Type definition for DAppSigner interface compatible with inscription SDK
|
|
@@ -26,11 +28,80 @@ interface DAppSigner {
|
|
|
26
28
|
*/
|
|
27
29
|
export class InscriberBuilder extends BaseServiceBuilder {
|
|
28
30
|
protected inscriptionSDK?: InscriptionSDK;
|
|
31
|
+
private static signerProvider?: () => Promise<DAppSigner | null> | DAppSigner | null;
|
|
32
|
+
private static walletInfoResolver?: () => Promise<{ accountId: string; network: 'mainnet' | 'testnet' } | null> | { accountId: string; network: 'mainnet' | 'testnet' } | null;
|
|
33
|
+
private static startInscriptionDelegate?: (
|
|
34
|
+
request: Record<string, unknown>,
|
|
35
|
+
network: 'mainnet' | 'testnet'
|
|
36
|
+
) => Promise<{
|
|
37
|
+
transactionBytes: string;
|
|
38
|
+
tx_id?: string;
|
|
39
|
+
topic_id?: string;
|
|
40
|
+
status?: string;
|
|
41
|
+
completed?: boolean;
|
|
42
|
+
}>;
|
|
43
|
+
private static walletExecutor?: (
|
|
44
|
+
base64: string,
|
|
45
|
+
network: 'mainnet' | 'testnet'
|
|
46
|
+
) => Promise<{ transactionId: string }>;
|
|
47
|
+
/** When true, do not allow server fallback; require a wallet path in Provide Bytes */
|
|
48
|
+
private static preferWalletOnly = false;
|
|
29
49
|
|
|
30
50
|
constructor(hederaKit: HederaAgentKit) {
|
|
31
51
|
super(hederaKit);
|
|
32
52
|
}
|
|
33
53
|
|
|
54
|
+
public getOperationalMode(): AgentOperationalMode {
|
|
55
|
+
return this.hederaKit.operationalMode as AgentOperationalMode;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static setSignerProvider(
|
|
59
|
+
provider: () => Promise<DAppSigner | null> | DAppSigner | null
|
|
60
|
+
): void {
|
|
61
|
+
InscriberBuilder.signerProvider = provider;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static setWalletInfoResolver(
|
|
65
|
+
resolver: () => Promise<{ accountId: string; network: 'mainnet' | 'testnet' } | null> | { accountId: string; network: 'mainnet' | 'testnet' } | null
|
|
66
|
+
): void {
|
|
67
|
+
InscriberBuilder.walletInfoResolver = resolver;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static setStartInscriptionDelegate(
|
|
71
|
+
delegate: (
|
|
72
|
+
request: Record<string, unknown>,
|
|
73
|
+
network: 'mainnet' | 'testnet'
|
|
74
|
+
) => Promise<{ transactionBytes: string; tx_id?: string; topic_id?: string; status?: string; completed?: boolean }>
|
|
75
|
+
): void {
|
|
76
|
+
InscriberBuilder.startInscriptionDelegate = delegate;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static setWalletExecutor(
|
|
80
|
+
executor: (base64: string, network: 'mainnet' | 'testnet') => Promise<{ transactionId: string }>
|
|
81
|
+
): void {
|
|
82
|
+
InscriberBuilder.walletExecutor = executor;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Control fallback behavior. When true, wallet must be available for execution paths.
|
|
87
|
+
*/
|
|
88
|
+
static setPreferWalletOnly(flag: boolean): void {
|
|
89
|
+
InscriberBuilder.preferWalletOnly = !!flag;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async getSigner(): Promise<DAppSigner | null> {
|
|
93
|
+
const provider = InscriberBuilder.signerProvider;
|
|
94
|
+
if (!provider) return null;
|
|
95
|
+
try {
|
|
96
|
+
const maybe = provider();
|
|
97
|
+
return (maybe && typeof (maybe as Promise<unknown>).then === 'function')
|
|
98
|
+
? await (maybe as Promise<DAppSigner | null>)
|
|
99
|
+
: (maybe as DAppSigner | null);
|
|
100
|
+
} catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
34
105
|
/**
|
|
35
106
|
* Get or create Inscription SDK - temporarily returns null since we don't have the actual SDK
|
|
36
107
|
*/
|
|
@@ -74,7 +145,169 @@ export class InscriberBuilder extends BaseServiceBuilder {
|
|
|
74
145
|
signer: DAppSigner,
|
|
75
146
|
options: InscriptionOptions
|
|
76
147
|
): Promise<InscriptionResponse> {
|
|
77
|
-
return await inscribeWithSigner(
|
|
148
|
+
return await inscribeWithSigner(
|
|
149
|
+
input,
|
|
150
|
+
signer as unknown as Parameters<typeof inscribeWithSigner>[1],
|
|
151
|
+
options
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async inscribeAuto(
|
|
156
|
+
input: InscriptionInput,
|
|
157
|
+
options: InscriptionOptions
|
|
158
|
+
): Promise<InscriptionResponse> {
|
|
159
|
+
const signer = await this.getSigner();
|
|
160
|
+
if (signer) {
|
|
161
|
+
return this.inscribeWithSigner(input, signer, options);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
type WalletInfo = { accountId: string; network: 'mainnet' | 'testnet' };
|
|
165
|
+
type WalletStartResponse = {
|
|
166
|
+
transactionBytes: string;
|
|
167
|
+
tx_id?: string;
|
|
168
|
+
topic_id?: string;
|
|
169
|
+
status?: string;
|
|
170
|
+
completed?: boolean;
|
|
171
|
+
};
|
|
172
|
+
type WalletExecutorResponse = { transactionId: string };
|
|
173
|
+
|
|
174
|
+
const infoMaybe: WalletInfo | null = InscriberBuilder.walletInfoResolver
|
|
175
|
+
? await InscriberBuilder.walletInfoResolver()
|
|
176
|
+
: null;
|
|
177
|
+
|
|
178
|
+
if (InscriberBuilder.preferWalletOnly && !infoMaybe) {
|
|
179
|
+
const err = new Error('Wallet unavailable: connect a wallet or switch to autonomous mode');
|
|
180
|
+
(err as unknown as { code: string }).code = 'wallet_unavailable';
|
|
181
|
+
throw err;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (
|
|
185
|
+
infoMaybe &&
|
|
186
|
+
InscriberBuilder.startInscriptionDelegate &&
|
|
187
|
+
InscriberBuilder.walletExecutor
|
|
188
|
+
) {
|
|
189
|
+
const holderId = infoMaybe.accountId;
|
|
190
|
+
const network: 'mainnet' | 'testnet' = infoMaybe.network;
|
|
191
|
+
|
|
192
|
+
type InscriptionOptionsExt = InscriptionOptions & {
|
|
193
|
+
fileStandard?: string;
|
|
194
|
+
chunkSize?: number;
|
|
195
|
+
jsonFileURL?: string;
|
|
196
|
+
metadata?: Record<string, unknown> & { creator?: string; description?: string };
|
|
197
|
+
};
|
|
198
|
+
const ext = options as InscriptionOptionsExt;
|
|
199
|
+
|
|
200
|
+
const baseRequest: Record<string, unknown> = {
|
|
201
|
+
holderId,
|
|
202
|
+
metadata: ext.metadata || {},
|
|
203
|
+
tags: options.tags || [],
|
|
204
|
+
mode: options.mode || 'file',
|
|
205
|
+
};
|
|
206
|
+
if (typeof ext.fileStandard !== 'undefined') {
|
|
207
|
+
(baseRequest as { fileStandard?: string }).fileStandard = ext.fileStandard;
|
|
208
|
+
}
|
|
209
|
+
if (typeof ext.chunkSize !== 'undefined') {
|
|
210
|
+
(baseRequest as { chunkSize?: number }).chunkSize = ext.chunkSize;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
let request: Record<string, unknown> = { ...baseRequest };
|
|
214
|
+
switch (input.type) {
|
|
215
|
+
case 'url':
|
|
216
|
+
request = { ...baseRequest, file: { type: 'url', url: input.url } };
|
|
217
|
+
break;
|
|
218
|
+
case 'file':
|
|
219
|
+
request = { ...baseRequest, file: { type: 'path', path: input.path } };
|
|
220
|
+
break;
|
|
221
|
+
case 'buffer':
|
|
222
|
+
request = {
|
|
223
|
+
...baseRequest,
|
|
224
|
+
file: {
|
|
225
|
+
type: 'base64',
|
|
226
|
+
base64: Buffer.from(input.buffer).toString('base64'),
|
|
227
|
+
fileName: input.fileName,
|
|
228
|
+
mimeType: input.mimeType,
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (options.mode === 'hashinal') {
|
|
235
|
+
(request as { metadataObject?: unknown }).metadataObject = ext.metadata;
|
|
236
|
+
(request as { creator?: string }).creator = ext.metadata?.creator || holderId;
|
|
237
|
+
(request as { description?: string }).description = ext.metadata?.description;
|
|
238
|
+
if (typeof ext.jsonFileURL === 'string' && ext.jsonFileURL.length > 0) {
|
|
239
|
+
(request as { jsonFileURL?: string }).jsonFileURL = ext.jsonFileURL;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const start: WalletStartResponse = await InscriberBuilder.startInscriptionDelegate(
|
|
244
|
+
request,
|
|
245
|
+
network
|
|
246
|
+
);
|
|
247
|
+
if (!start || !start.transactionBytes) {
|
|
248
|
+
throw new Error('Failed to start inscription (no transaction bytes)');
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const exec: WalletExecutorResponse = await InscriberBuilder.walletExecutor(
|
|
252
|
+
start.transactionBytes,
|
|
253
|
+
network
|
|
254
|
+
);
|
|
255
|
+
const transactionId = exec?.transactionId || '';
|
|
256
|
+
|
|
257
|
+
const shouldWait = options.quoteOnly ? false : options.waitForConfirmation ?? true;
|
|
258
|
+
if (shouldWait) {
|
|
259
|
+
const maxAttempts = (options as { waitMaxAttempts?: number }).waitMaxAttempts ?? 60;
|
|
260
|
+
const intervalMs = (options as { waitIntervalMs?: number }).waitIntervalMs ?? 5000;
|
|
261
|
+
|
|
262
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
263
|
+
try {
|
|
264
|
+
const retrieved: RetrievedInscriptionResult = await this.retrieveInscription(
|
|
265
|
+
transactionId,
|
|
266
|
+
options
|
|
267
|
+
);
|
|
268
|
+
const topicIdFromInscription: string | undefined = getTopicId(retrieved as unknown);
|
|
269
|
+
const topicId: string | undefined = topicIdFromInscription ?? start.topic_id;
|
|
270
|
+
const status: string | undefined = (retrieved as { status?: string }).status;
|
|
271
|
+
const isDone = status === 'completed' || !!topicId;
|
|
272
|
+
if (isDone) {
|
|
273
|
+
const resultConfirmed: InscriptionResponse = {
|
|
274
|
+
quote: false,
|
|
275
|
+
confirmed: true,
|
|
276
|
+
result: {
|
|
277
|
+
jobId: start.tx_id || '',
|
|
278
|
+
transactionId,
|
|
279
|
+
topicId,
|
|
280
|
+
},
|
|
281
|
+
inscription: retrieved,
|
|
282
|
+
} as unknown as InscriptionResponse;
|
|
283
|
+
return resultConfirmed;
|
|
284
|
+
}
|
|
285
|
+
} catch {
|
|
286
|
+
}
|
|
287
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const partial: InscriptionResponse = {
|
|
292
|
+
quote: false,
|
|
293
|
+
confirmed: false,
|
|
294
|
+
result: {
|
|
295
|
+
jobId: start.tx_id || '',
|
|
296
|
+
transactionId,
|
|
297
|
+
status: start.status,
|
|
298
|
+
completed: start.completed,
|
|
299
|
+
},
|
|
300
|
+
inscription: start.topic_id ? { topic_id: start.topic_id } : undefined,
|
|
301
|
+
} as unknown as InscriptionResponse;
|
|
302
|
+
return partial;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (InscriberBuilder.preferWalletOnly) {
|
|
306
|
+
const err = new Error('Wallet unavailable: connect a wallet or switch to autonomous mode');
|
|
307
|
+
(err as unknown as { code: string }).code = 'wallet_unavailable';
|
|
308
|
+
throw err;
|
|
309
|
+
}
|
|
310
|
+
return this.inscribe(input, options);
|
|
78
311
|
}
|
|
79
312
|
|
|
80
313
|
/**
|
|
@@ -102,4 +335,4 @@ export class InscriberBuilder extends BaseServiceBuilder {
|
|
|
102
335
|
async close(): Promise<void> {
|
|
103
336
|
this.inscriptionSDK = undefined;
|
|
104
337
|
}
|
|
105
|
-
}
|
|
338
|
+
}
|
package/src/hcs10/HCS10Client.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -8,4 +8,8 @@ export { HCS10Builder, HCS2Builder, HCS6Builder, InscriberBuilder } from './buil
|
|
|
8
8
|
export type { ExecuteResult } from './builders';
|
|
9
9
|
export { HCS10Client } from './hcs10';
|
|
10
10
|
export type { ContentReferenceConfig } from './config/ContentReferenceConfig';
|
|
11
|
-
export { loadConfig } from './config/ContentReferenceConfig';
|
|
11
|
+
export { loadConfig } from './config/ContentReferenceConfig';
|
|
12
|
+
export { SignerProviderRegistry } from './signing/signer-provider';
|
|
13
|
+
export type { DAppSigner, WalletInfo, WalletExecutor, StartHCSDelegate, NetworkString } from './signing/signer-provider';
|
|
14
|
+
export { ByteBuildRegistry } from './signing/bytes-registry';
|
|
15
|
+
export type { ByteBuildHandler } from './signing/bytes-registry';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ZodType } from 'zod';
|
|
2
2
|
import { RenderConfigSchema, EnhancedRenderConfig, ZodSchemaWithRender, FormFieldType, FieldMetadata, SelectOption } from './types';
|
|
3
3
|
|
|
4
|
-
// Type definitions for extended Zod schemas - using Record to extend existing properties
|
|
5
4
|
interface ExtendedZodSchema {
|
|
6
5
|
description?: string;
|
|
7
6
|
merge?: (other: ZodType<unknown>) => ZodType<unknown>;
|