@hashgraphonline/standards-sdk 0.0.67 → 0.0.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/hcs-10/base-client.d.ts +20 -5
- package/dist/es/hcs-10/base-client.d.ts.map +1 -1
- package/dist/es/hcs-10/browser.d.ts.map +1 -1
- package/dist/es/hcs-10/sdk.d.ts +12 -2
- package/dist/es/hcs-10/sdk.d.ts.map +1 -1
- package/dist/es/standards-sdk.es102.js +1 -1
- package/dist/es/standards-sdk.es104.js +1 -1
- package/dist/es/standards-sdk.es105.js +6 -6
- package/dist/es/standards-sdk.es106.js +3 -3
- package/dist/es/standards-sdk.es113.js +1 -1
- package/dist/es/standards-sdk.es114.js +2 -2
- package/dist/es/standards-sdk.es12.js +2 -2
- package/dist/es/standards-sdk.es14.js +1 -1
- package/dist/es/standards-sdk.es17.js +1 -1
- package/dist/es/standards-sdk.es18.js +2 -2
- package/dist/es/standards-sdk.es20.js +10 -10
- package/dist/es/standards-sdk.es22.js +36 -3
- package/dist/es/standards-sdk.es22.js.map +1 -1
- package/dist/es/standards-sdk.es23.js +48 -4167
- package/dist/es/standards-sdk.es23.js.map +1 -1
- package/dist/es/standards-sdk.es24.js +6627 -36
- package/dist/es/standards-sdk.es24.js.map +1 -1
- package/dist/es/standards-sdk.es25.js +3 -48
- package/dist/es/standards-sdk.es25.js.map +1 -1
- package/dist/es/standards-sdk.es26.js +2 -6627
- package/dist/es/standards-sdk.es26.js.map +1 -1
- package/dist/es/standards-sdk.es27.js +5 -2
- package/dist/es/standards-sdk.es27.js.map +1 -1
- package/dist/es/standards-sdk.es28.js +4167 -5
- package/dist/es/standards-sdk.es28.js.map +1 -1
- package/dist/es/standards-sdk.es29.js +419 -3
- package/dist/es/standards-sdk.es29.js.map +1 -1
- package/dist/es/standards-sdk.es30.js +1 -163
- package/dist/es/standards-sdk.es30.js.map +1 -1
- package/dist/es/standards-sdk.es31.js +112 -93
- package/dist/es/standards-sdk.es31.js.map +1 -1
- package/dist/es/standards-sdk.es32.js +3 -2
- package/dist/es/standards-sdk.es32.js.map +1 -1
- package/dist/es/standards-sdk.es33.js +163 -15
- package/dist/es/standards-sdk.es33.js.map +1 -1
- package/dist/es/standards-sdk.es34.js +2 -409
- package/dist/es/standards-sdk.es34.js.map +1 -1
- package/dist/es/standards-sdk.es35.js +189 -413
- package/dist/es/standards-sdk.es35.js.map +1 -1
- package/dist/es/standards-sdk.es36.js +438 -2
- package/dist/es/standards-sdk.es36.js.map +1 -1
- package/dist/es/standards-sdk.es37.js +20 -115
- package/dist/es/standards-sdk.es37.js.map +1 -1
- package/dist/es/standards-sdk.es38.js +139 -2282
- package/dist/es/standards-sdk.es38.js.map +1 -1
- package/dist/es/standards-sdk.es39.js +17 -3
- package/dist/es/standards-sdk.es39.js.map +1 -1
- package/dist/es/standards-sdk.es40.js +29 -2
- package/dist/es/standards-sdk.es40.js.map +1 -1
- package/dist/es/standards-sdk.es41.js +25 -80
- package/dist/es/standards-sdk.es41.js.map +1 -1
- package/dist/es/standards-sdk.es42.js +20 -22
- package/dist/es/standards-sdk.es42.js.map +1 -1
- package/dist/es/standards-sdk.es43.js +38 -142
- package/dist/es/standards-sdk.es43.js.map +1 -1
- package/dist/es/standards-sdk.es44.js +13 -86
- package/dist/es/standards-sdk.es44.js.map +1 -1
- package/dist/es/standards-sdk.es45.js +55 -168
- package/dist/es/standards-sdk.es45.js.map +1 -1
- package/dist/es/standards-sdk.es46.js +1288 -5
- package/dist/es/standards-sdk.es46.js.map +1 -1
- package/dist/es/standards-sdk.es47.js +132 -127
- package/dist/es/standards-sdk.es47.js.map +1 -1
- package/dist/es/standards-sdk.es48.js +81 -185
- package/dist/es/standards-sdk.es48.js.map +1 -1
- package/dist/es/standards-sdk.es49.js +75 -429
- package/dist/es/standards-sdk.es49.js.map +1 -1
- package/dist/es/standards-sdk.es5.js +67 -18
- package/dist/es/standards-sdk.es5.js.map +1 -1
- package/dist/es/standards-sdk.es50.js +28 -21
- package/dist/es/standards-sdk.es50.js.map +1 -1
- package/dist/es/standards-sdk.es51.js +5 -138
- package/dist/es/standards-sdk.es51.js.map +1 -1
- package/dist/es/standards-sdk.es52.js +154 -13
- package/dist/es/standards-sdk.es52.js.map +1 -1
- package/dist/es/standards-sdk.es53.js +21 -27
- package/dist/es/standards-sdk.es53.js.map +1 -1
- package/dist/es/standards-sdk.es54.js +784 -20
- package/dist/es/standards-sdk.es54.js.map +1 -1
- package/dist/es/standards-sdk.es55.js +170 -17
- package/dist/es/standards-sdk.es55.js.map +1 -1
- package/dist/es/standards-sdk.es56.js +134 -35
- package/dist/es/standards-sdk.es56.js.map +1 -1
- package/dist/es/standards-sdk.es57.js +3 -17
- package/dist/es/standards-sdk.es57.js.map +1 -1
- package/dist/es/standards-sdk.es58.js +11 -51
- package/dist/es/standards-sdk.es58.js.map +1 -1
- package/dist/es/standards-sdk.es59.js +22 -1284
- package/dist/es/standards-sdk.es59.js.map +1 -1
- package/dist/es/standards-sdk.es60.js +23 -29
- package/dist/es/standards-sdk.es60.js.map +1 -1
- package/dist/es/standards-sdk.es61.js +37 -158
- package/dist/es/standards-sdk.es61.js.map +1 -1
- package/dist/es/standards-sdk.es62.js +346 -775
- package/dist/es/standards-sdk.es62.js.map +1 -1
- package/dist/es/standards-sdk.es63.js +5 -26
- package/dist/es/standards-sdk.es63.js.map +1 -1
- package/dist/es/standards-sdk.es64.js +177 -24
- package/dist/es/standards-sdk.es64.js.map +1 -1
- package/dist/es/standards-sdk.es65.js +79 -36
- package/dist/es/standards-sdk.es65.js.map +1 -1
- package/dist/es/standards-sdk.es66.js +112 -19
- package/dist/es/standards-sdk.es66.js.map +1 -1
- package/dist/es/standards-sdk.es67.js +42 -354
- package/dist/es/standards-sdk.es67.js.map +1 -1
- package/dist/es/standards-sdk.es68.js +9 -5
- package/dist/es/standards-sdk.es68.js.map +1 -1
- package/dist/es/standards-sdk.es69.js +82 -164
- package/dist/es/standards-sdk.es69.js.map +1 -1
- package/dist/es/standards-sdk.es7.js +52 -7
- package/dist/es/standards-sdk.es7.js.map +1 -1
- package/dist/es/standards-sdk.es70.js +3 -80
- package/dist/es/standards-sdk.es70.js.map +1 -1
- package/dist/es/standards-sdk.es71.js +2 -114
- package/dist/es/standards-sdk.es71.js.map +1 -1
- package/dist/es/standards-sdk.es72.js +104 -43
- package/dist/es/standards-sdk.es72.js.map +1 -1
- package/dist/es/standards-sdk.es73.js +72 -8
- package/dist/es/standards-sdk.es73.js.map +1 -1
- package/dist/es/standards-sdk.es74.js +5 -96
- package/dist/es/standards-sdk.es74.js.map +1 -1
- package/dist/es/standards-sdk.es75.js +4 -3
- package/dist/es/standards-sdk.es75.js.map +1 -1
- package/dist/es/standards-sdk.es76.js +221 -2
- package/dist/es/standards-sdk.es76.js.map +1 -1
- package/dist/es/standards-sdk.es77.js +53 -108
- package/dist/es/standards-sdk.es77.js.map +1 -1
- package/dist/es/standards-sdk.es78.js +68 -73
- package/dist/es/standards-sdk.es78.js.map +1 -1
- package/dist/es/standards-sdk.es79.js +100 -5
- package/dist/es/standards-sdk.es79.js.map +1 -1
- package/dist/es/standards-sdk.es8.js +17 -3
- package/dist/es/standards-sdk.es8.js.map +1 -1
- package/dist/es/standards-sdk.es80.js +2 -5
- package/dist/es/standards-sdk.es80.js.map +1 -1
- package/dist/es/standards-sdk.es81.js +15 -220
- package/dist/es/standards-sdk.es81.js.map +1 -1
- package/dist/es/standards-sdk.es82.js +403 -52
- package/dist/es/standards-sdk.es82.js.map +1 -1
- package/dist/es/standards-sdk.es83.js +32 -69
- package/dist/es/standards-sdk.es83.js.map +1 -1
- package/dist/es/standards-sdk.es84.js +57 -26
- package/dist/es/standards-sdk.es84.js.map +1 -1
- package/dist/es/standards-sdk.es85.js +45 -58
- package/dist/es/standards-sdk.es85.js.map +1 -1
- package/dist/es/standards-sdk.es86.js +8 -48
- package/dist/es/standards-sdk.es86.js.map +1 -1
- package/dist/es/standards-sdk.es87.js +63 -8
- package/dist/es/standards-sdk.es87.js.map +1 -1
- package/dist/es/standards-sdk.es88.js +5 -64
- package/dist/es/standards-sdk.es88.js.map +1 -1
- package/dist/es/standards-sdk.es89.js +15 -6
- package/dist/es/standards-sdk.es89.js.map +1 -1
- package/dist/es/standards-sdk.es9.js +1 -1
- package/dist/es/standards-sdk.es90.js +7 -15
- package/dist/es/standards-sdk.es90.js.map +1 -1
- package/dist/es/standards-sdk.es91.js +44 -6
- package/dist/es/standards-sdk.es91.js.map +1 -1
- package/dist/es/standards-sdk.es92.js +2 -45
- package/dist/es/standards-sdk.es92.js.map +1 -1
- package/dist/es/standards-sdk.es93.js +136 -2
- package/dist/es/standards-sdk.es93.js.map +1 -1
- package/dist/es/standards-sdk.es94.js +162 -126
- package/dist/es/standards-sdk.es94.js.map +1 -1
- package/dist/es/standards-sdk.es95.js +2281 -171
- package/dist/es/standards-sdk.es95.js.map +1 -1
- package/dist/es/standards-sdk.es98.js +1 -1
- package/dist/es/standards-sdk.es99.js +3 -3
- package/dist/umd/hcs-10/base-client.d.ts +20 -5
- package/dist/umd/hcs-10/base-client.d.ts.map +1 -1
- package/dist/umd/hcs-10/browser.d.ts.map +1 -1
- package/dist/umd/hcs-10/sdk.d.ts +12 -2
- package/dist/umd/hcs-10/sdk.d.ts.map +1 -1
- package/dist/umd/standards-sdk.umd.js +1 -1
- package/dist/umd/standards-sdk.umd.js.map +1 -1
- package/package.json +1 -1
|
@@ -3,9 +3,9 @@ import { Logger } from "./standards-sdk.es14.js";
|
|
|
3
3
|
import { Registration } from "./standards-sdk.es9.js";
|
|
4
4
|
import { HCS11Client } from "./standards-sdk.es12.js";
|
|
5
5
|
import { PublicKey } from "@hashgraph/sdk";
|
|
6
|
-
import "./standards-sdk.
|
|
6
|
+
import "./standards-sdk.es22.js";
|
|
7
7
|
import { HederaMirrorNode } from "./standards-sdk.es18.js";
|
|
8
|
-
import axios from "./standards-sdk.
|
|
8
|
+
import axios from "./standards-sdk.es23.js";
|
|
9
9
|
var Hcs10MemoType = /* @__PURE__ */ ((Hcs10MemoType2) => {
|
|
10
10
|
Hcs10MemoType2["INBOUND"] = "inbound";
|
|
11
11
|
Hcs10MemoType2["OUTBOUND"] = "outbound";
|
|
@@ -27,6 +27,26 @@ class HCS10BaseClient extends Registration {
|
|
|
27
27
|
);
|
|
28
28
|
this.feeAmount = config.feeAmount || 1e-3;
|
|
29
29
|
}
|
|
30
|
+
extractTopicFromOperatorId(operatorId) {
|
|
31
|
+
if (!operatorId) {
|
|
32
|
+
return "";
|
|
33
|
+
}
|
|
34
|
+
const parts = operatorId.split("@");
|
|
35
|
+
if (parts.length > 0) {
|
|
36
|
+
return parts[0];
|
|
37
|
+
}
|
|
38
|
+
return "";
|
|
39
|
+
}
|
|
40
|
+
extractAccountFromOperatorId(operatorId) {
|
|
41
|
+
if (!operatorId) {
|
|
42
|
+
return "";
|
|
43
|
+
}
|
|
44
|
+
const parts = operatorId.split("@");
|
|
45
|
+
if (parts.length > 1) {
|
|
46
|
+
return parts[1];
|
|
47
|
+
}
|
|
48
|
+
return "";
|
|
49
|
+
}
|
|
30
50
|
/**
|
|
31
51
|
* Get a stream of messages from a connection topic
|
|
32
52
|
* @param topicId The connection topic ID to get messages from
|
|
@@ -179,8 +199,19 @@ class HCS10BaseClient extends Registration {
|
|
|
179
199
|
async getAccountMemo(accountId) {
|
|
180
200
|
return await this.mirrorNode.getAccountMemo(accountId);
|
|
181
201
|
}
|
|
182
|
-
async retrieveProfile(accountId) {
|
|
202
|
+
async retrieveProfile(accountId, disableCache) {
|
|
183
203
|
this.logger.info(`Retrieving profile for account: ${accountId}`);
|
|
204
|
+
const cacheKey = `${accountId}-${this.network}`;
|
|
205
|
+
if (!disableCache) {
|
|
206
|
+
const cachedProfileResponse = HCS10Cache.getInstance().get(cacheKey);
|
|
207
|
+
if (cachedProfileResponse) {
|
|
208
|
+
this.logger.info(`Cache hit for profile: ${accountId}`);
|
|
209
|
+
return cachedProfileResponse;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
this.logger.info(
|
|
213
|
+
`Cache miss for profile: ${accountId}, fetching from network`
|
|
214
|
+
);
|
|
184
215
|
try {
|
|
185
216
|
const hcs11Client = new HCS11Client({
|
|
186
217
|
network: this.network,
|
|
@@ -213,14 +244,14 @@ class HCS10BaseClient extends Registration {
|
|
|
213
244
|
outboundTopic: profileResult.topicInfo.outboundTopic,
|
|
214
245
|
profileTopicId: profileResult.topicInfo.profileTopicId
|
|
215
246
|
};
|
|
216
|
-
const cacheKey = `${accountId}-${this.network}`;
|
|
217
|
-
HCS10Cache.getInstance().set(cacheKey, topicInfo);
|
|
218
247
|
}
|
|
219
|
-
|
|
248
|
+
const responseToCache = {
|
|
220
249
|
profile,
|
|
221
250
|
topicInfo,
|
|
222
251
|
success: true
|
|
223
252
|
};
|
|
253
|
+
HCS10Cache.getInstance().set(cacheKey, responseToCache);
|
|
254
|
+
return responseToCache;
|
|
224
255
|
} catch (error) {
|
|
225
256
|
this.logger.error("Failed to retrieve profile:", error);
|
|
226
257
|
return {
|
|
@@ -230,10 +261,28 @@ class HCS10BaseClient extends Registration {
|
|
|
230
261
|
};
|
|
231
262
|
}
|
|
232
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* @deprecated Use retrieveCommunicationTopics instead
|
|
266
|
+
* @param accountId The account ID to retrieve the outbound connect topic for
|
|
267
|
+
* @returns {TopicInfo} Topic Info from target profile.
|
|
268
|
+
*/
|
|
233
269
|
async retrieveOutboundConnectTopic(accountId) {
|
|
270
|
+
return await this.retrieveCommunicationTopics(accountId, true);
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Retrieves the communication topics for an account
|
|
274
|
+
* @param accountId The account ID to retrieve the communication topics for
|
|
275
|
+
* @param disableCache Whether to disable caching of the result
|
|
276
|
+
* @returns {TopicInfo} Topic Info from target profile.
|
|
277
|
+
*/
|
|
278
|
+
async retrieveCommunicationTopics(accountId, disableCache) {
|
|
234
279
|
this.logger.info(`Retrieving topics for account: ${accountId}`);
|
|
280
|
+
`${accountId}-${this.network}`;
|
|
235
281
|
try {
|
|
236
|
-
const profileResponse = await this.retrieveProfile(
|
|
282
|
+
const profileResponse = await this.retrieveProfile(
|
|
283
|
+
accountId,
|
|
284
|
+
disableCache
|
|
285
|
+
);
|
|
237
286
|
if (!profileResponse?.success) {
|
|
238
287
|
throw new Error(profileResponse.error || "Failed to retrieve profile");
|
|
239
288
|
}
|
|
@@ -243,14 +292,12 @@ class HCS10BaseClient extends Registration {
|
|
|
243
292
|
`Invalid HCS-11 profile for HCS-10 agent: missing inboundTopicId or outboundTopicId`
|
|
244
293
|
);
|
|
245
294
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
HCS10Cache.getInstance().set(cacheKey, topicInfo);
|
|
253
|
-
return topicInfo;
|
|
295
|
+
if (!profileResponse.topicInfo) {
|
|
296
|
+
throw new Error(
|
|
297
|
+
`TopicInfo is missing in the profile for account ${accountId}`
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
return profileResponse.topicInfo;
|
|
254
301
|
} catch (error) {
|
|
255
302
|
this.logger.error("Failed to retrieve topic info:", error);
|
|
256
303
|
throw error;
|
|
@@ -258,7 +305,7 @@ class HCS10BaseClient extends Registration {
|
|
|
258
305
|
}
|
|
259
306
|
async retrieveOutboundMessages(agentAccountId) {
|
|
260
307
|
try {
|
|
261
|
-
const topicInfo = await this.
|
|
308
|
+
const topicInfo = await this.retrieveCommunicationTopics(agentAccountId);
|
|
262
309
|
if (!topicInfo) {
|
|
263
310
|
this.logger.warn(
|
|
264
311
|
`No outbound connect topic found for agentAccountId: ${agentAccountId}`
|
|
@@ -276,7 +323,7 @@ class HCS10BaseClient extends Registration {
|
|
|
276
323
|
}
|
|
277
324
|
async hasConnectionCreated(agentAccountId, connectionId) {
|
|
278
325
|
try {
|
|
279
|
-
const outBoundTopic = await this.
|
|
326
|
+
const outBoundTopic = await this.retrieveCommunicationTopics(
|
|
280
327
|
agentAccountId
|
|
281
328
|
);
|
|
282
329
|
const messages = await this.retrieveOutboundMessages(
|
|
@@ -327,11 +374,12 @@ class HCS10BaseClient extends Registration {
|
|
|
327
374
|
* @param connectionRequestId The ID of the connection request
|
|
328
375
|
* @param confirmedRequestId The ID of the confirmed request
|
|
329
376
|
* @param connectionTopicId The ID of the connection topic
|
|
330
|
-
* @param operatorId The operator ID of the message sender
|
|
377
|
+
* @param operatorId The operator ID of the original message sender.
|
|
331
378
|
* @param memo An optional memo for the message
|
|
332
379
|
*/
|
|
333
380
|
async recordOutboundConnectionConfirmation({
|
|
334
381
|
outboundTopicId,
|
|
382
|
+
requestorOutboundTopicId,
|
|
335
383
|
connectionRequestId,
|
|
336
384
|
confirmedRequestId,
|
|
337
385
|
connectionTopicId,
|
|
@@ -343,6 +391,7 @@ class HCS10BaseClient extends Registration {
|
|
|
343
391
|
op: "connection_created",
|
|
344
392
|
connection_topic_id: connectionTopicId,
|
|
345
393
|
outbound_topic_id: outboundTopicId,
|
|
394
|
+
requestor_outbound_topic_id: requestorOutboundTopicId,
|
|
346
395
|
confirmed_request_id: confirmedRequestId,
|
|
347
396
|
connection_request_id: connectionRequestId,
|
|
348
397
|
operator_id: operatorId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es5.js","sources":["../../src/hcs-10/base-client.ts"],"sourcesContent":["\nimport { Logger, LogLevel } from '../utils/logger';\nimport { Registration } from './registrations';\nimport { HCS11Client } from '../hcs-11/client';\nimport { AccountResponse } from '../services/types';\nimport { TopicInfo } from '../services/types';\nimport { TransactionReceipt, PrivateKey, PublicKey } from '@hashgraph/sdk';\nimport axios from 'axios';\nimport { NetworkType } from '../utils/types';\nimport { HederaMirrorNode } from '../services';\n\nexport enum Hcs10MemoType {\n INBOUND = 'inbound',\n OUTBOUND = 'outbound',\n CONNECTION = 'connection',\n}\n\nexport interface HCS10Config {\n network: 'mainnet' | 'testnet';\n logLevel?: LogLevel;\n prettyPrint?: boolean;\n feeAmount?: number;\n}\n\nexport interface HCSMessage {\n p: 'hcs-10';\n op:\n | 'connection_request'\n | 'connection_created'\n | 'message'\n | 'close_connection';\n data: string;\n created?: Date;\n consensus_timestamp?: string;\n m?: string;\n payer: string;\n outbound_topic_id?: string;\n connection_request_id?: number;\n confirmed_request_id?: number;\n connection_topic_id?: string;\n connected_account_id?: string;\n requesting_account_id?: string;\n connection_id?: number;\n sequence_number: number;\n operator_id?: string;\n reason?: string;\n close_method?: string;\n}\n\nexport interface ProfileResponse {\n profile: any;\n topicInfo?: TopicInfo;\n success: boolean;\n error?: string;\n}\n\nexport abstract class HCS10BaseClient extends Registration {\n protected network: string;\n protected logger: Logger;\n protected mirrorNode: HederaMirrorNode;\n protected feeAmount: number;\n\n protected operatorId: string;\n\n constructor(config: HCS10Config) {\n super();\n this.network = config.network;\n this.logger = Logger.getInstance({\n level: config.logLevel || 'info',\n module: 'HCS10-BaseClient',\n prettyPrint: config.prettyPrint,\n });\n this.mirrorNode = new HederaMirrorNode(\n config.network as NetworkType,\n this.logger\n );\n this.feeAmount = config.feeAmount || 0.001;\n }\n\n abstract submitPayload(\n topicId: string,\n payload: object | string,\n submitKey?: PrivateKey,\n requiresFee?: boolean\n ): Promise<TransactionReceipt>;\n\n abstract getAccountAndSigner(): { accountId: string; signer: any };\n\n /**\n * Get a stream of messages from a connection topic\n * @param topicId The connection topic ID to get messages from\n * @returns A stream of filtered messages valid for connection topics\n */\n public async getMessageStream(\n topicId: string\n ): Promise<{ messages: HCSMessage[] }> {\n try {\n const messages = await this.mirrorNode.getTopicMessages(topicId);\n const validOps = ['message', 'close_connection'];\n\n const filteredMessages = messages.filter((msg) => {\n if (msg.p !== 'hcs-10' || !validOps.includes(msg.op)) {\n return false;\n }\n\n if (msg.op === 'message') {\n if (!msg.data) {\n return false;\n }\n\n if (!msg.operator_id) {\n return false;\n }\n\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n }\n\n if (msg.op === 'close_connection') {\n if (!msg.operator_id) {\n return false;\n }\n\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n }\n\n return true;\n });\n\n return {\n messages: filteredMessages,\n };\n } catch (error: any) {\n if (this.logger) {\n this.logger.error(`Error fetching messages: ${error.message}`);\n }\n return { messages: [] };\n }\n }\n\n /**\n * Checks if a user can submit to a topic and determines if a fee is required\n * @param topicId The topic ID to check\n * @param userAccountId The account ID of the user attempting to submit\n * @returns Object with canSubmit, requiresFee, and optional reason\n */\n public async canSubmitToTopic(\n topicId: string,\n userAccountId: string\n ): Promise<{ canSubmit: boolean; requiresFee: boolean; reason?: string }> {\n try {\n const topicInfo = await this.mirrorNode.getTopicInfo(topicId);\n\n if (!topicInfo) {\n return {\n canSubmit: false,\n requiresFee: false,\n reason: 'Topic does not exist',\n };\n }\n\n if (!topicInfo.submit_key?.key) {\n return { canSubmit: true, requiresFee: false };\n }\n\n try {\n const userPublicKey = await this.mirrorNode.getPublicKey(userAccountId);\n\n if (topicInfo.submit_key._type === 'ProtobufEncoded') {\n const keyBytes = Buffer.from(topicInfo.submit_key.key, 'hex');\n const hasAccess = await this.mirrorNode.checkKeyListAccess(\n keyBytes,\n userPublicKey\n );\n\n if (hasAccess) {\n return { canSubmit: true, requiresFee: false };\n }\n } else {\n const topicSubmitKey = PublicKey.fromString(topicInfo.submit_key.key);\n if (userPublicKey.toString() === topicSubmitKey.toString()) {\n return { canSubmit: true, requiresFee: false };\n }\n }\n } catch (error) {\n this.logger.error(\n `Key validation error: ${\n error instanceof Error ? error.message : String(error)\n }`\n );\n }\n\n if (\n topicInfo.fee_schedule_key?.key &&\n topicInfo.custom_fees?.fixed_fees?.length > 0\n ) {\n return {\n canSubmit: true,\n requiresFee: true,\n reason: 'Requires fee payment via HIP-991',\n };\n }\n\n return {\n canSubmit: false,\n requiresFee: false,\n reason: 'User does not have submit permission for this topic',\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n this.logger.error(`Topic submission validation error: ${errorMessage}`);\n return {\n canSubmit: false,\n requiresFee: false,\n reason: `Error: ${errorMessage}`,\n };\n }\n }\n\n /**\n * Get all messages from a topic\n * @param topicId The topic ID to get messages from\n * @returns All messages from the topic\n */\n public async getMessages(\n topicId: string\n ): Promise<{ messages: HCSMessage[] }> {\n try {\n const messages = await this.mirrorNode.getTopicMessages(topicId);\n\n const validatedMessages = messages.filter((msg) => {\n if (msg.p !== 'hcs-10') {\n return false;\n }\n\n if (msg.op === 'message') {\n if (!msg.data) {\n return false;\n }\n\n if (msg.operator_id) {\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n }\n }\n\n return true;\n });\n\n return {\n messages: validatedMessages,\n };\n } catch (error: any) {\n if (this.logger) {\n this.logger.error(`Error fetching messages: ${error.message}`);\n }\n return { messages: [] };\n }\n }\n\n public async requestAccount(account: string): Promise<AccountResponse> {\n try {\n return await this.mirrorNode.requestAccount(account);\n } catch (e) {\n this.logger.error('Failed to fetch account', e);\n throw e;\n }\n }\n\n public async getAccountMemo(accountId: string): Promise<string | null> {\n return await this.mirrorNode.getAccountMemo(accountId);\n }\n\n public async retrieveProfile(accountId: string): Promise<ProfileResponse> {\n this.logger.info(`Retrieving profile for account: ${accountId}`);\n\n try {\n const hcs11Client = new HCS11Client({\n network: this.network as 'mainnet' | 'testnet',\n auth: {\n operatorId: '0.0.0', // Read-only operations only\n },\n logLevel: 'info',\n });\n\n const profileResult = await hcs11Client.fetchProfileByAccountId(\n accountId,\n this.network\n );\n\n if (!profileResult?.success) {\n this.logger.error(\n `Failed to retrieve profile for account ID: ${accountId}`,\n profileResult?.error\n );\n return {\n profile: null,\n success: false,\n error:\n profileResult?.error ||\n `Failed to retrieve profile for account ID: ${accountId}`,\n };\n }\n\n const profile = profileResult.profile;\n let topicInfo = null;\n\n if (\n profileResult.topicInfo?.inboundTopic &&\n profileResult.topicInfo?.outboundTopic &&\n profileResult.topicInfo?.profileTopicId\n ) {\n topicInfo = {\n inboundTopic: profileResult.topicInfo.inboundTopic,\n outboundTopic: profileResult.topicInfo.outboundTopic,\n profileTopicId: profileResult.topicInfo.profileTopicId,\n };\n\n const cacheKey = `${accountId}-${this.network}`;\n HCS10Cache.getInstance().set(cacheKey, topicInfo);\n }\n\n return {\n profile,\n topicInfo,\n success: true,\n };\n } catch (error) {\n this.logger.error('Failed to retrieve profile:', error);\n return {\n profile: null,\n success: false,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n }\n\n public async retrieveOutboundConnectTopic(\n accountId: string\n ): Promise<TopicInfo> {\n this.logger.info(`Retrieving topics for account: ${accountId}`);\n\n try {\n const profileResponse = await this.retrieveProfile(accountId);\n\n if (!profileResponse?.success) {\n throw new Error(profileResponse.error || 'Failed to retrieve profile');\n }\n\n const profile = profileResponse.profile;\n\n if (!profile.inboundTopicId || !profile.outboundTopicId) {\n throw new Error(\n `Invalid HCS-11 profile for HCS-10 agent: missing inboundTopicId or outboundTopicId`\n );\n }\n\n const topicInfo = {\n inboundTopic: profile.inboundTopicId,\n outboundTopic: profile.outboundTopicId,\n profileTopicId: profile.profileTopicId,\n };\n\n const cacheKey = `${accountId}-${this.network}`;\n HCS10Cache.getInstance().set(cacheKey, topicInfo);\n return topicInfo;\n } catch (error) {\n this.logger.error('Failed to retrieve topic info:', error);\n throw error;\n }\n }\n\n public async retrieveOutboundMessages(\n agentAccountId: string\n ): Promise<HCSMessage[]> {\n try {\n const topicInfo = await this.retrieveOutboundConnectTopic(agentAccountId);\n if (!topicInfo) {\n this.logger.warn(\n `No outbound connect topic found for agentAccountId: ${agentAccountId}`\n );\n return [];\n }\n const response = await this.getMessages(topicInfo.outboundTopic);\n return response.messages.filter(\n (msg) =>\n msg.p === 'hcs-10' &&\n (msg.op === 'connection_request' ||\n msg.op === 'connection_created' ||\n msg.op === 'message')\n );\n } catch (error) {\n this.logger.error('Failed to retrieve outbound messages:', error);\n return [];\n }\n }\n\n public async hasConnectionCreated(\n agentAccountId: string,\n connectionId: number\n ): Promise<boolean> {\n try {\n const outBoundTopic = await this.retrieveOutboundConnectTopic(\n agentAccountId\n );\n const messages = await this.retrieveOutboundMessages(\n outBoundTopic.outboundTopic\n );\n return messages.some(\n (msg) =>\n msg.op === 'connection_created' && msg.connection_id === connectionId\n );\n } catch (error) {\n this.logger.error('Failed to check connection created:', error);\n return false;\n }\n }\n\n /**\n * Gets message content, resolving any HRL references if needed\n * @param data The message data which might be an HRL reference\n * @returns The resolved content\n */\n async getMessageContent(data: string): Promise<string> {\n const hrlPattern = /^hcs:\\/\\/(\\d+)\\/([0-9.]+)$/;\n const match = data.match(hrlPattern);\n\n if (!match) {\n return data;\n }\n\n const [_, standard, topicId] = match;\n\n this.logger.info(\n `Resolving HRL reference: standard=${standard}, topicId=${topicId}`\n );\n\n try {\n const cdnUrl = `https://kiloscribe.com/api/inscription-cdn/${topicId}?network=${this.network}`;\n const response = await axios.get(cdnUrl);\n\n if (!response.data) {\n throw new Error(`Failed to fetch content from topic: ${topicId}`);\n }\n\n return (\n response.data.content ||\n response.data.text ||\n JSON.stringify(response.data)\n );\n } catch (error) {\n this.logger.error(\n `Error resolving HRL reference: ${\n error instanceof Error ? error.message : 'Unknown error'\n }`\n );\n throw new Error(\n `Failed to resolve HRL reference: ${\n error instanceof Error ? error.message : 'Unknown error'\n }`\n );\n }\n }\n\n /**\n * Records an outbound connection confirmation\n * @param outboundTopicId The ID of the outbound topic\n * @param connectionRequestId The ID of the connection request\n * @param confirmedRequestId The ID of the confirmed request\n * @param connectionTopicId The ID of the connection topic\n * @param operatorId The operator ID of the message sender\n * @param memo An optional memo for the message\n */\n public async recordOutboundConnectionConfirmation({\n outboundTopicId,\n connectionRequestId,\n confirmedRequestId,\n connectionTopicId,\n operatorId,\n memo,\n }: {\n outboundTopicId: string;\n connectionRequestId: number;\n confirmedRequestId: number;\n connectionTopicId: string;\n operatorId: string;\n memo: string;\n }): Promise<TransactionReceipt> {\n const payload = {\n p: 'hcs-10',\n op: 'connection_created',\n connection_topic_id: connectionTopicId,\n outbound_topic_id: outboundTopicId,\n confirmed_request_id: confirmedRequestId,\n connection_request_id: connectionRequestId,\n operator_id: operatorId,\n m: memo,\n };\n return await this.submitPayload(outboundTopicId, payload);\n }\n\n public async getOperatorId(disableCache?: boolean): Promise<string> {\n if (this.operatorId && !disableCache) {\n return this.operatorId;\n }\n\n const accountResponse = this.getAccountAndSigner();\n\n if (!accountResponse.accountId) {\n throw new Error('Operator ID not found');\n }\n\n const profile = await this.retrieveProfile(accountResponse.accountId);\n\n if (!profile.success) {\n throw new Error('Failed to retrieve profile');\n }\n\n const operatorId = `${profile.topicInfo?.inboundTopic}@${accountResponse.accountId}`;\n this.operatorId = operatorId;\n return operatorId;\n }\n\n clearCache(): void {\n HCS10Cache.getInstance().clear();\n }\n\n /**\n * Generates a standard HCS-10 memo string.\n * @param type The type of topic memo ('inbound', 'outbound', 'connection').\n * @param options Configuration options for the memo.\n * @returns The formatted memo string.\n * @protected\n */\n protected _generateHcs10Memo(\n type: Hcs10MemoType,\n options: {\n ttl?: number;\n accountId?: string;\n inboundTopicId?: string;\n connectionId?: number;\n }\n ): string {\n const ttl = options.ttl ?? 60; // Default TTL to 60 if not provided\n\n switch (type) {\n case Hcs10MemoType.INBOUND:\n if (!options.accountId) {\n throw new Error('accountId is required for inbound memo');\n }\n return `hcs-10:0:${ttl}:0:${options.accountId}`;\n case Hcs10MemoType.OUTBOUND:\n return `hcs-10:0:${ttl}:1`;\n case Hcs10MemoType.CONNECTION:\n if (!options.inboundTopicId || options.connectionId === undefined) {\n throw new Error(\n 'inboundTopicId and connectionId are required for connection memo'\n );\n }\n return `hcs-10:1:${ttl}:2:${options.inboundTopicId}:${options.connectionId}`;\n default:\n throw new Error(`Invalid HCS-10 memo type: ${type}`);\n }\n }\n\n protected async checkRegistrationStatus(\n transactionId: string,\n network: string,\n baseUrl: string\n ): Promise<{ status: 'pending' | 'success' | 'failed' }> {\n try {\n const response = await fetch(`${baseUrl}/api/request-confirm`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Network': network,\n },\n body: JSON.stringify({ transaction_id: transactionId }),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to confirm registration: ${response.statusText}`\n );\n }\n\n return await response.json();\n } catch (error) {\n this.logger.error(`Error checking registration status: ${error}`);\n throw error;\n }\n }\n\n /**\n * Validates if an operator_id follows the correct format (agentTopicId@accountId)\n * @param operatorId The operator ID to validate\n * @returns True if the format is valid, false otherwise\n */\n protected isValidOperatorId(operatorId: string): boolean {\n if (!operatorId) {\n return false;\n }\n\n const parts = operatorId.split('@');\n\n if (parts.length !== 2) {\n return false;\n }\n\n const agentTopicId = parts[0];\n const accountId = parts[1];\n\n if (!agentTopicId) {\n return false;\n }\n\n if (!accountId) {\n return false;\n }\n\n const hederaIdPattern = /^[0-9]+\\.[0-9]+\\.[0-9]+$/;\n\n if (!hederaIdPattern.test(accountId)) {\n return false;\n }\n\n if (!hederaIdPattern.test(agentTopicId)) {\n return false;\n }\n\n return true;\n }\n}\n\nexport class HCS10Cache {\n private static instance: HCS10Cache;\n private cache: Map<string, TopicInfo>;\n private cacheExpiry: Map<string, number>;\n private readonly CACHE_TTL = 3600000;\n\n private constructor() {\n this.cache = new Map();\n this.cacheExpiry = new Map();\n }\n\n static getInstance(): HCS10Cache {\n if (!HCS10Cache.instance) {\n HCS10Cache.instance = new HCS10Cache();\n }\n return HCS10Cache.instance;\n }\n\n set(key: string, value: TopicInfo): void {\n this.cache.set(key, value);\n this.cacheExpiry.set(key, Date.now() + this.CACHE_TTL);\n }\n\n get(key: string): TopicInfo | undefined {\n const expiry = this.cacheExpiry.get(key);\n if (expiry && expiry > Date.now()) {\n return this.cache.get(key);\n }\n if (expiry) {\n this.cache.delete(key);\n this.cacheExpiry.delete(key);\n }\n return undefined;\n }\n\n clear(): void {\n this.cache.clear();\n this.cacheExpiry.clear();\n }\n}\n"],"names":["Hcs10MemoType"],"mappings":";;;;;;;;AAWY,IAAA,kCAAAA,mBAAL;AACLA,i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AAI,IAAI,KAAK,SAAS;AAAA,EAAA;AAAA,EAGvD,IAAI,KAAoC;AACtC,UAAM,SAAS,KAAK,YAAY,IAAI,GAAG;AACvC,QAAI,UAAU,SAAS,KAAK,IAAA,GAAO;AAC1B,aAAA,KAAK,MAAM,IAAI,GAAG;AAAA,IAAA;AAE3B,QAAI,QAAQ;AACL,WAAA,MAAM,OAAO,GAAG;AAChB,WAAA,YAAY,OAAO,GAAG;AAAA,IAAA;AAEtB,WAAA;AAAA,EAAA;AAAA,EAGT,QAAc;AACZ,SAAK,MAAM,MAAM;AACjB,SAAK,YAAY,MAAM;AAAA,EAAA;AAE3B;"}
|
|
1
|
+
{"version":3,"file":"standards-sdk.es5.js","sources":["../../src/hcs-10/base-client.ts"],"sourcesContent":["import { Logger, LogLevel } from '../utils/logger';\nimport { Registration } from './registrations';\nimport { HCS11Client } from '../hcs-11/client';\nimport { AccountResponse } from '../services/types';\nimport { TopicInfo } from '../services/types';\nimport { TransactionReceipt, PrivateKey, PublicKey } from '@hashgraph/sdk';\nimport axios from 'axios';\nimport { NetworkType } from '../utils/types';\nimport { HederaMirrorNode } from '../services';\n\nexport enum Hcs10MemoType {\n INBOUND = 'inbound',\n OUTBOUND = 'outbound',\n CONNECTION = 'connection',\n}\n\nexport interface HCS10Config {\n network: 'mainnet' | 'testnet';\n logLevel?: LogLevel;\n prettyPrint?: boolean;\n feeAmount?: number;\n}\n\nexport interface HCSMessage {\n p: 'hcs-10';\n op:\n | 'connection_request'\n | 'connection_created'\n | 'message'\n | 'close_connection';\n data: string;\n created?: Date;\n consensus_timestamp?: string;\n m?: string;\n payer: string;\n outbound_topic_id?: string;\n connection_request_id?: number;\n confirmed_request_id?: number;\n connection_topic_id?: string;\n connected_account_id?: string;\n requesting_account_id?: string;\n connection_id?: number;\n sequence_number: number;\n operator_id?: string;\n reason?: string;\n close_method?: string;\n}\n\nexport interface ProfileResponse {\n profile: any;\n topicInfo?: TopicInfo;\n success: boolean;\n error?: string;\n}\n\nexport abstract class HCS10BaseClient extends Registration {\n protected network: string;\n protected logger: Logger;\n protected mirrorNode: HederaMirrorNode;\n protected feeAmount: number;\n\n protected operatorId: string;\n\n constructor(config: HCS10Config) {\n super();\n this.network = config.network;\n this.logger = Logger.getInstance({\n level: config.logLevel || 'info',\n module: 'HCS10-BaseClient',\n prettyPrint: config.prettyPrint,\n });\n this.mirrorNode = new HederaMirrorNode(\n config.network as NetworkType,\n this.logger\n );\n this.feeAmount = config.feeAmount || 0.001;\n }\n\n abstract submitPayload(\n topicId: string,\n payload: object | string,\n submitKey?: PrivateKey,\n requiresFee?: boolean\n ): Promise<TransactionReceipt>;\n\n abstract getAccountAndSigner(): { accountId: string; signer: any };\n\n public extractTopicFromOperatorId(operatorId: string): string {\n if (!operatorId) {\n return '';\n }\n const parts = operatorId.split('@');\n if (parts.length > 0) {\n return parts[0];\n }\n return '';\n }\n\n public extractAccountFromOperatorId(operatorId: string): string {\n if (!operatorId) {\n return '';\n }\n const parts = operatorId.split('@');\n if (parts.length > 1) {\n return parts[1];\n }\n return '';\n }\n\n /**\n * Get a stream of messages from a connection topic\n * @param topicId The connection topic ID to get messages from\n * @returns A stream of filtered messages valid for connection topics\n */\n public async getMessageStream(\n topicId: string\n ): Promise<{ messages: HCSMessage[] }> {\n try {\n const messages = await this.mirrorNode.getTopicMessages(topicId);\n const validOps = ['message', 'close_connection'];\n\n const filteredMessages = messages.filter((msg) => {\n if (msg.p !== 'hcs-10' || !validOps.includes(msg.op)) {\n return false;\n }\n\n if (msg.op === 'message') {\n if (!msg.data) {\n return false;\n }\n\n if (!msg.operator_id) {\n return false;\n }\n\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n }\n\n if (msg.op === 'close_connection') {\n if (!msg.operator_id) {\n return false;\n }\n\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n }\n\n return true;\n });\n\n return {\n messages: filteredMessages,\n };\n } catch (error: any) {\n if (this.logger) {\n this.logger.error(`Error fetching messages: ${error.message}`);\n }\n return { messages: [] };\n }\n }\n\n /**\n * Checks if a user can submit to a topic and determines if a fee is required\n * @param topicId The topic ID to check\n * @param userAccountId The account ID of the user attempting to submit\n * @returns Object with canSubmit, requiresFee, and optional reason\n */\n public async canSubmitToTopic(\n topicId: string,\n userAccountId: string\n ): Promise<{ canSubmit: boolean; requiresFee: boolean; reason?: string }> {\n try {\n const topicInfo = await this.mirrorNode.getTopicInfo(topicId);\n\n if (!topicInfo) {\n return {\n canSubmit: false,\n requiresFee: false,\n reason: 'Topic does not exist',\n };\n }\n\n if (!topicInfo.submit_key?.key) {\n return { canSubmit: true, requiresFee: false };\n }\n\n try {\n const userPublicKey = await this.mirrorNode.getPublicKey(userAccountId);\n\n if (topicInfo.submit_key._type === 'ProtobufEncoded') {\n const keyBytes = Buffer.from(topicInfo.submit_key.key, 'hex');\n const hasAccess = await this.mirrorNode.checkKeyListAccess(\n keyBytes,\n userPublicKey\n );\n\n if (hasAccess) {\n return { canSubmit: true, requiresFee: false };\n }\n } else {\n const topicSubmitKey = PublicKey.fromString(topicInfo.submit_key.key);\n if (userPublicKey.toString() === topicSubmitKey.toString()) {\n return { canSubmit: true, requiresFee: false };\n }\n }\n } catch (error) {\n this.logger.error(\n `Key validation error: ${\n error instanceof Error ? error.message : String(error)\n }`\n );\n }\n\n if (\n topicInfo.fee_schedule_key?.key &&\n topicInfo.custom_fees?.fixed_fees?.length > 0\n ) {\n return {\n canSubmit: true,\n requiresFee: true,\n reason: 'Requires fee payment via HIP-991',\n };\n }\n\n return {\n canSubmit: false,\n requiresFee: false,\n reason: 'User does not have submit permission for this topic',\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n this.logger.error(`Topic submission validation error: ${errorMessage}`);\n return {\n canSubmit: false,\n requiresFee: false,\n reason: `Error: ${errorMessage}`,\n };\n }\n }\n\n /**\n * Get all messages from a topic\n * @param topicId The topic ID to get messages from\n * @returns All messages from the topic\n */\n public async getMessages(\n topicId: string\n ): Promise<{ messages: HCSMessage[] }> {\n try {\n const messages = await this.mirrorNode.getTopicMessages(topicId);\n\n const validatedMessages = messages.filter((msg) => {\n if (msg.p !== 'hcs-10') {\n return false;\n }\n\n if (msg.op === 'message') {\n if (!msg.data) {\n return false;\n }\n\n if (msg.operator_id) {\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n }\n }\n\n return true;\n });\n\n return {\n messages: validatedMessages,\n };\n } catch (error: any) {\n if (this.logger) {\n this.logger.error(`Error fetching messages: ${error.message}`);\n }\n return { messages: [] };\n }\n }\n\n public async requestAccount(account: string): Promise<AccountResponse> {\n try {\n return await this.mirrorNode.requestAccount(account);\n } catch (e) {\n this.logger.error('Failed to fetch account', e);\n throw e;\n }\n }\n\n public async getAccountMemo(accountId: string): Promise<string | null> {\n return await this.mirrorNode.getAccountMemo(accountId);\n }\n\n public async retrieveProfile(\n accountId: string,\n disableCache?: boolean\n ): Promise<ProfileResponse> {\n this.logger.info(`Retrieving profile for account: ${accountId}`);\n\n const cacheKey = `${accountId}-${this.network}`;\n\n if (!disableCache) {\n const cachedProfileResponse = HCS10Cache.getInstance().get(cacheKey);\n if (cachedProfileResponse) {\n this.logger.info(`Cache hit for profile: ${accountId}`);\n return cachedProfileResponse;\n }\n }\n\n this.logger.info(\n `Cache miss for profile: ${accountId}, fetching from network`\n );\n\n try {\n const hcs11Client = new HCS11Client({\n network: this.network as 'mainnet' | 'testnet',\n auth: {\n operatorId: '0.0.0', // Read-only operations only\n },\n logLevel: 'info',\n });\n\n const profileResult = await hcs11Client.fetchProfileByAccountId(\n accountId,\n this.network\n );\n\n if (!profileResult?.success) {\n this.logger.error(\n `Failed to retrieve profile for account ID: ${accountId}`,\n profileResult?.error\n );\n return {\n profile: null,\n success: false,\n error:\n profileResult?.error ||\n `Failed to retrieve profile for account ID: ${accountId}`,\n };\n }\n\n const profile = profileResult.profile;\n let topicInfo: TopicInfo | null = null;\n\n if (\n profileResult.topicInfo?.inboundTopic &&\n profileResult.topicInfo?.outboundTopic &&\n profileResult.topicInfo?.profileTopicId\n ) {\n topicInfo = {\n inboundTopic: profileResult.topicInfo.inboundTopic,\n outboundTopic: profileResult.topicInfo.outboundTopic,\n profileTopicId: profileResult.topicInfo.profileTopicId,\n };\n }\n\n const responseToCache: ProfileResponse = {\n profile,\n topicInfo,\n success: true,\n };\n HCS10Cache.getInstance().set(cacheKey, responseToCache);\n return responseToCache;\n } catch (error) {\n this.logger.error('Failed to retrieve profile:', error);\n return {\n profile: null,\n success: false,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n }\n\n /**\n * @deprecated Use retrieveCommunicationTopics instead\n * @param accountId The account ID to retrieve the outbound connect topic for\n * @returns {TopicInfo} Topic Info from target profile.\n */\n public async retrieveOutboundConnectTopic(\n accountId: string\n ): Promise<TopicInfo> {\n return await this.retrieveCommunicationTopics(accountId, true);\n }\n\n /**\n * Retrieves the communication topics for an account\n * @param accountId The account ID to retrieve the communication topics for\n * @param disableCache Whether to disable caching of the result\n * @returns {TopicInfo} Topic Info from target profile.\n */\n public async retrieveCommunicationTopics(\n accountId: string,\n disableCache?: boolean\n ): Promise<TopicInfo> {\n this.logger.info(`Retrieving topics for account: ${accountId}`);\n const cacheKey = `${accountId}-${this.network}`;\n\n try {\n const profileResponse = await this.retrieveProfile(\n accountId,\n disableCache\n );\n\n if (!profileResponse?.success) {\n throw new Error(profileResponse.error || 'Failed to retrieve profile');\n }\n\n const profile = profileResponse.profile;\n\n if (!profile.inboundTopicId || !profile.outboundTopicId) {\n throw new Error(\n `Invalid HCS-11 profile for HCS-10 agent: missing inboundTopicId or outboundTopicId`\n );\n }\n\n if (!profileResponse.topicInfo) {\n throw new Error(\n `TopicInfo is missing in the profile for account ${accountId}`\n );\n }\n\n return profileResponse.topicInfo;\n } catch (error) {\n this.logger.error('Failed to retrieve topic info:', error);\n throw error;\n }\n }\n\n public async retrieveOutboundMessages(\n agentAccountId: string\n ): Promise<HCSMessage[]> {\n try {\n const topicInfo = await this.retrieveCommunicationTopics(agentAccountId);\n if (!topicInfo) {\n this.logger.warn(\n `No outbound connect topic found for agentAccountId: ${agentAccountId}`\n );\n return [];\n }\n const response = await this.getMessages(topicInfo.outboundTopic);\n return response.messages.filter(\n (msg) =>\n msg.p === 'hcs-10' &&\n (msg.op === 'connection_request' ||\n msg.op === 'connection_created' ||\n msg.op === 'message')\n );\n } catch (error) {\n this.logger.error('Failed to retrieve outbound messages:', error);\n return [];\n }\n }\n\n public async hasConnectionCreated(\n agentAccountId: string,\n connectionId: number\n ): Promise<boolean> {\n try {\n const outBoundTopic = await this.retrieveCommunicationTopics(\n agentAccountId\n );\n const messages = await this.retrieveOutboundMessages(\n outBoundTopic.outboundTopic\n );\n return messages.some(\n (msg) =>\n msg.op === 'connection_created' && msg.connection_id === connectionId\n );\n } catch (error) {\n this.logger.error('Failed to check connection created:', error);\n return false;\n }\n }\n\n /**\n * Gets message content, resolving any HRL references if needed\n * @param data The message data which might be an HRL reference\n * @returns The resolved content\n */\n async getMessageContent(data: string): Promise<string> {\n const hrlPattern = /^hcs:\\/\\/(\\d+)\\/([0-9.]+)$/;\n const match = data.match(hrlPattern);\n\n if (!match) {\n return data;\n }\n\n const [_, standard, topicId] = match;\n\n this.logger.info(\n `Resolving HRL reference: standard=${standard}, topicId=${topicId}`\n );\n\n try {\n const cdnUrl = `https://kiloscribe.com/api/inscription-cdn/${topicId}?network=${this.network}`;\n const response = await axios.get(cdnUrl);\n\n if (!response.data) {\n throw new Error(`Failed to fetch content from topic: ${topicId}`);\n }\n\n return (\n response.data.content ||\n response.data.text ||\n JSON.stringify(response.data)\n );\n } catch (error) {\n this.logger.error(\n `Error resolving HRL reference: ${\n error instanceof Error ? error.message : 'Unknown error'\n }`\n );\n throw new Error(\n `Failed to resolve HRL reference: ${\n error instanceof Error ? error.message : 'Unknown error'\n }`\n );\n }\n }\n\n /**\n * Records an outbound connection confirmation\n * @param outboundTopicId The ID of the outbound topic\n * @param connectionRequestId The ID of the connection request\n * @param confirmedRequestId The ID of the confirmed request\n * @param connectionTopicId The ID of the connection topic\n * @param operatorId The operator ID of the original message sender.\n * @param memo An optional memo for the message\n */\n public async recordOutboundConnectionConfirmation({\n outboundTopicId,\n requestorOutboundTopicId,\n connectionRequestId,\n confirmedRequestId,\n connectionTopicId,\n operatorId,\n memo,\n }: {\n outboundTopicId: string;\n requestorOutboundTopicId: string;\n connectionRequestId: number;\n confirmedRequestId: number;\n connectionTopicId: string;\n operatorId: string;\n memo: string;\n }): Promise<TransactionReceipt> {\n const payload = {\n p: 'hcs-10',\n op: 'connection_created',\n connection_topic_id: connectionTopicId,\n outbound_topic_id: outboundTopicId,\n requestor_outbound_topic_id: requestorOutboundTopicId,\n confirmed_request_id: confirmedRequestId,\n connection_request_id: connectionRequestId,\n operator_id: operatorId,\n m: memo,\n };\n return await this.submitPayload(outboundTopicId, payload);\n }\n\n public async getOperatorId(disableCache?: boolean): Promise<string> {\n if (this.operatorId && !disableCache) {\n return this.operatorId;\n }\n\n const accountResponse = this.getAccountAndSigner();\n\n if (!accountResponse.accountId) {\n throw new Error('Operator ID not found');\n }\n\n const profile = await this.retrieveProfile(accountResponse.accountId);\n\n if (!profile.success) {\n throw new Error('Failed to retrieve profile');\n }\n\n const operatorId = `${profile.topicInfo?.inboundTopic}@${accountResponse.accountId}`;\n this.operatorId = operatorId;\n return operatorId;\n }\n\n clearCache(): void {\n HCS10Cache.getInstance().clear();\n }\n\n /**\n * Generates a standard HCS-10 memo string.\n * @param type The type of topic memo ('inbound', 'outbound', 'connection').\n * @param options Configuration options for the memo.\n * @returns The formatted memo string.\n * @protected\n */\n protected _generateHcs10Memo(\n type: Hcs10MemoType,\n options: {\n ttl?: number;\n accountId?: string;\n inboundTopicId?: string;\n connectionId?: number;\n }\n ): string {\n const ttl = options.ttl ?? 60; // Default TTL to 60 if not provided\n\n switch (type) {\n case Hcs10MemoType.INBOUND:\n if (!options.accountId) {\n throw new Error('accountId is required for inbound memo');\n }\n return `hcs-10:0:${ttl}:0:${options.accountId}`;\n case Hcs10MemoType.OUTBOUND:\n return `hcs-10:0:${ttl}:1`;\n case Hcs10MemoType.CONNECTION:\n if (!options.inboundTopicId || options.connectionId === undefined) {\n throw new Error(\n 'inboundTopicId and connectionId are required for connection memo'\n );\n }\n return `hcs-10:1:${ttl}:2:${options.inboundTopicId}:${options.connectionId}`;\n default:\n throw new Error(`Invalid HCS-10 memo type: ${type}`);\n }\n }\n\n protected async checkRegistrationStatus(\n transactionId: string,\n network: string,\n baseUrl: string\n ): Promise<{ status: 'pending' | 'success' | 'failed' }> {\n try {\n const response = await fetch(`${baseUrl}/api/request-confirm`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Network': network,\n },\n body: JSON.stringify({ transaction_id: transactionId }),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to confirm registration: ${response.statusText}`\n );\n }\n\n return await response.json();\n } catch (error) {\n this.logger.error(`Error checking registration status: ${error}`);\n throw error;\n }\n }\n\n /**\n * Validates if an operator_id follows the correct format (agentTopicId@accountId)\n * @param operatorId The operator ID to validate\n * @returns True if the format is valid, false otherwise\n */\n protected isValidOperatorId(operatorId: string): boolean {\n if (!operatorId) {\n return false;\n }\n\n const parts = operatorId.split('@');\n\n if (parts.length !== 2) {\n return false;\n }\n\n const agentTopicId = parts[0];\n const accountId = parts[1];\n\n if (!agentTopicId) {\n return false;\n }\n\n if (!accountId) {\n return false;\n }\n\n const hederaIdPattern = /^[0-9]+\\.[0-9]+\\.[0-9]+$/;\n\n if (!hederaIdPattern.test(accountId)) {\n return false;\n }\n\n if (!hederaIdPattern.test(agentTopicId)) {\n return false;\n }\n\n return true;\n }\n}\n\nexport class HCS10Cache {\n private static instance: HCS10Cache;\n private cache: Map<string, ProfileResponse>;\n private cacheExpiry: Map<string, number>;\n private readonly CACHE_TTL = 3600000;\n\n private constructor() {\n this.cache = new Map();\n this.cacheExpiry = new Map();\n }\n\n static getInstance(): HCS10Cache {\n if (!HCS10Cache.instance) {\n HCS10Cache.instance = new HCS10Cache();\n }\n return HCS10Cache.instance;\n }\n\n set(key: string, value: ProfileResponse): void {\n this.cache.set(key, value);\n this.cacheExpiry.set(key, Date.now() + this.CACHE_TTL);\n }\n\n get(key: string): ProfileResponse | undefined {\n const expiry = this.cacheExpiry.get(key);\n if (expiry && expiry > Date.now()) {\n return this.cache.get(key);\n }\n if (expiry) {\n this.cache.delete(key);\n this.cacheExpiry.delete(key);\n }\n return undefined;\n }\n\n clear(): void {\n this.cache.clear();\n this.cacheExpiry.clear();\n }\n}\n"],"names":["Hcs10MemoType"],"mappings":";;;;;;;;AAUY,IAAA,kCAAAA,mBAAL;AACLA,iBAAA,SAAU,IAAA;AACVA,iBAAA,UAAW,IAAA;AACXA,iBAAA,YAAa,IAAA;AAHHA,SAAAA;AAAA,GAAA,iBAAA,CAAA,CAAA;AA6CL,MAAe,wBAAwB,aAAa;AAAA,EAQzD,YAAY,QAAqB;AACzB,UAAA;AACN,SAAK,UAAU,OAAO;AACjB,SAAA,SAAS,OAAO,YAAY;AAAA,MAC/B,OAAO,OAAO,YAAY;AAAA,MAC1B,QAAQ;AAAA,MACR,aAAa,OAAO;AAAA,IAAA,CACrB;AACD,SAAK,aAAa,IAAI;AAAA,MACpB,OAAO;AAAA,MACP,KAAK;AAAA,IACP;AACK,SAAA,YAAY,OAAO,aAAa;AAAA,EAAA;AAAA,EAYhC,2BAA2B,YAA4B;AAC5D,QAAI,CAAC,YAAY;AACR,aAAA;AAAA,IAAA;AAEH,UAAA,QAAQ,WAAW,MAAM,GAAG;AAC9B,QAAA,MAAM,SAAS,GAAG;AACpB,aAAO,MAAM,CAAC;AAAA,IAAA;AAET,WAAA;AAAA,EAAA;AAAA,EAGF,6BAA6B,YAA4B;AAC9D,QAAI,CAAC,YAAY;AACR,aAAA;AAAA,IAAA;AAEH,UAAA,QAAQ,WAAW,MAAM,GAAG;AAC9B,QAAA,MAAM,SAAS,GAAG;AACpB,aAAO,MAAM,CAAC;AAAA,IAAA;AAET,WAAA;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KAAK,SAAS;AAAA,EAAA;AAAA,EAGvD,IAAI,KAA0C;AAC5C,UAAM,SAAS,KAAK,YAAY,IAAI,GAAG;AACvC,QAAI,UAAU,SAAS,KAAK,IAAA,GAAO;AAC1B,aAAA,KAAK,MAAM,IAAI,GAAG;AAAA,IAAA;AAE3B,QAAI,QAAQ;AACL,WAAA,MAAM,OAAO,GAAG;AAChB,WAAA,YAAY,OAAO,GAAG;AAAA,IAAA;AAEtB,WAAA;AAAA,EAAA;AAAA,EAGT,QAAc;AACZ,SAAK,MAAM,MAAM;AACjB,SAAK,YAAY,MAAM;AAAA,EAAA;AAE3B;"}
|
|
@@ -1,28 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
value = getAddress(value);
|
|
16
|
-
} catch (error) {
|
|
17
|
-
return this._throwError(error.message, _value);
|
|
1
|
+
function checkType(value, type, name) {
|
|
2
|
+
const types = type.split("|").map((t) => t.trim());
|
|
3
|
+
for (let i = 0; i < types.length; i++) {
|
|
4
|
+
switch (type) {
|
|
5
|
+
case "any":
|
|
6
|
+
return;
|
|
7
|
+
case "bigint":
|
|
8
|
+
case "boolean":
|
|
9
|
+
case "number":
|
|
10
|
+
case "string":
|
|
11
|
+
if (typeof value === type) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
18
14
|
}
|
|
19
|
-
return writer.writeValue(value);
|
|
20
15
|
}
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
const error = new Error(`invalid value for type ${type}`);
|
|
17
|
+
error.code = "INVALID_ARGUMENT";
|
|
18
|
+
error.argument = `value.${name}`;
|
|
19
|
+
error.value = value;
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
function defineProperties(target, values, types) {
|
|
23
|
+
for (let key in values) {
|
|
24
|
+
let value = values[key];
|
|
25
|
+
const type = types ? types[key] : null;
|
|
26
|
+
if (type) {
|
|
27
|
+
checkType(value, type, key);
|
|
28
|
+
}
|
|
29
|
+
Object.defineProperty(target, key, { enumerable: true, value, writable: false });
|
|
23
30
|
}
|
|
24
31
|
}
|
|
25
32
|
export {
|
|
26
|
-
|
|
33
|
+
defineProperties
|
|
27
34
|
};
|
|
28
35
|
//# sourceMappingURL=standards-sdk.es50.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es50.js","sources":["../../node_modules/ethers/lib.esm/
|
|
1
|
+
{"version":3,"file":"standards-sdk.es50.js","sources":["../../node_modules/ethers/lib.esm/utils/properties.js"],"sourcesContent":["/**\n * Property helper functions.\n *\n * @_subsection api/utils:Properties [about-properties]\n */\nfunction checkType(value, type, name) {\n const types = type.split(\"|\").map(t => t.trim());\n for (let i = 0; i < types.length; i++) {\n switch (type) {\n case \"any\":\n return;\n case \"bigint\":\n case \"boolean\":\n case \"number\":\n case \"string\":\n if (typeof (value) === type) {\n return;\n }\n }\n }\n const error = new Error(`invalid value for type ${type}`);\n error.code = \"INVALID_ARGUMENT\";\n error.argument = `value.${name}`;\n error.value = value;\n throw error;\n}\n/**\n * Resolves to a new object that is a copy of %%value%%, but with all\n * values resolved.\n */\nexport async function resolveProperties(value) {\n const keys = Object.keys(value);\n const results = await Promise.all(keys.map((k) => Promise.resolve(value[k])));\n return results.reduce((accum, v, index) => {\n accum[keys[index]] = v;\n return accum;\n }, {});\n}\n/**\n * Assigns the %%values%% to %%target%% as read-only values.\n *\n * It %%types%% is specified, the values are checked.\n */\nexport function defineProperties(target, values, types) {\n for (let key in values) {\n let value = values[key];\n const type = (types ? types[key] : null);\n if (type) {\n checkType(value, type, key);\n }\n Object.defineProperty(target, key, { enumerable: true, value, writable: false });\n }\n}\n//# sourceMappingURL=properties.js.map"],"names":[],"mappings":"AAKA,SAAS,UAAU,OAAO,MAAM,MAAM;AAClC,QAAM,QAAQ,KAAK,MAAM,GAAG,EAAE,IAAI,OAAK,EAAE,MAAM;AAC/C,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACnC,YAAQ,MAAI;AAAA,MACR,KAAK;AACD;AAAA,MACJ,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AACD,YAAI,OAAQ,UAAW,MAAM;AACzB;AAAA,QACpB;AAAA,IACA;AAAA,EACA;AACI,QAAM,QAAQ,IAAI,MAAM,0BAA0B,IAAI,EAAE;AACxD,QAAM,OAAO;AACb,QAAM,WAAW,SAAS,IAAI;AAC9B,QAAM,QAAQ;AACd,QAAM;AACV;AAkBO,SAAS,iBAAiB,QAAQ,QAAQ,OAAO;AACpD,WAAS,OAAO,QAAQ;AACpB,QAAI,QAAQ,OAAO,GAAG;AACtB,UAAM,OAAQ,QAAQ,MAAM,GAAG,IAAI;AACnC,QAAI,MAAM;AACN,gBAAU,OAAO,MAAM,GAAG;AAAA,IACtC;AACQ,WAAO,eAAe,QAAQ,KAAK,EAAE,YAAY,MAAM,OAAO,UAAU,OAAO;AAAA,EACvF;AACA;","x_google_ignoreList":[0]}
|
|
@@ -1,142 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { Coder, WordSize, Writer, Result } from "./standards-sdk.es49.js";
|
|
6
|
-
import { AnonymousCoder } from "./standards-sdk.es66.js";
|
|
7
|
-
import { defineProperties } from "./standards-sdk.es60.js";
|
|
8
|
-
import { assertArgumentCount, assert, assertArgument, isError } from "./standards-sdk.es43.js";
|
|
9
|
-
function pack(writer, coders, values) {
|
|
10
|
-
let arrayValues = [];
|
|
11
|
-
if (Array.isArray(values)) {
|
|
12
|
-
arrayValues = values;
|
|
13
|
-
} else if (values && typeof values === "object") {
|
|
14
|
-
let unique = {};
|
|
15
|
-
arrayValues = coders.map((coder) => {
|
|
16
|
-
const name = coder.localName;
|
|
17
|
-
assert(name, "cannot encode object for signature with missing names", "INVALID_ARGUMENT", { argument: "values", info: { coder }, value: values });
|
|
18
|
-
assert(!unique[name], "cannot encode object for signature with duplicate names", "INVALID_ARGUMENT", { argument: "values", info: { coder }, value: values });
|
|
19
|
-
unique[name] = true;
|
|
20
|
-
return values[name];
|
|
21
|
-
});
|
|
22
|
-
} else {
|
|
23
|
-
assertArgument(false, "invalid tuple value", "tuple", values);
|
|
24
|
-
}
|
|
25
|
-
assertArgument(coders.length === arrayValues.length, "types/value length mismatch", "tuple", values);
|
|
26
|
-
let staticWriter = new Writer();
|
|
27
|
-
let dynamicWriter = new Writer();
|
|
28
|
-
let updateFuncs = [];
|
|
29
|
-
coders.forEach((coder, index) => {
|
|
30
|
-
let value = arrayValues[index];
|
|
31
|
-
if (coder.dynamic) {
|
|
32
|
-
let dynamicOffset = dynamicWriter.length;
|
|
33
|
-
coder.encode(dynamicWriter, value);
|
|
34
|
-
let updateFunc = staticWriter.writeUpdatableValue();
|
|
35
|
-
updateFuncs.push((baseOffset) => {
|
|
36
|
-
updateFunc(baseOffset + dynamicOffset);
|
|
37
|
-
});
|
|
38
|
-
} else {
|
|
39
|
-
coder.encode(staticWriter, value);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
updateFuncs.forEach((func) => {
|
|
43
|
-
func(staticWriter.length);
|
|
44
|
-
});
|
|
45
|
-
let length = writer.appendWriter(staticWriter);
|
|
46
|
-
length += writer.appendWriter(dynamicWriter);
|
|
47
|
-
return length;
|
|
48
|
-
}
|
|
49
|
-
function unpack(reader, coders) {
|
|
50
|
-
let values = [];
|
|
51
|
-
let keys = [];
|
|
52
|
-
let baseReader = reader.subReader(0);
|
|
53
|
-
coders.forEach((coder) => {
|
|
54
|
-
let value = null;
|
|
55
|
-
if (coder.dynamic) {
|
|
56
|
-
let offset = reader.readIndex();
|
|
57
|
-
let offsetReader = baseReader.subReader(offset);
|
|
58
|
-
try {
|
|
59
|
-
value = coder.decode(offsetReader);
|
|
60
|
-
} catch (error) {
|
|
61
|
-
if (isError(error, "BUFFER_OVERRUN")) {
|
|
62
|
-
throw error;
|
|
63
|
-
}
|
|
64
|
-
value = error;
|
|
65
|
-
value.baseType = coder.name;
|
|
66
|
-
value.name = coder.localName;
|
|
67
|
-
value.type = coder.type;
|
|
68
|
-
}
|
|
69
|
-
} else {
|
|
70
|
-
try {
|
|
71
|
-
value = coder.decode(reader);
|
|
72
|
-
} catch (error) {
|
|
73
|
-
if (isError(error, "BUFFER_OVERRUN")) {
|
|
74
|
-
throw error;
|
|
75
|
-
}
|
|
76
|
-
value = error;
|
|
77
|
-
value.baseType = coder.name;
|
|
78
|
-
value.name = coder.localName;
|
|
79
|
-
value.type = coder.type;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
if (value == void 0) {
|
|
83
|
-
throw new Error("investigate");
|
|
84
|
-
}
|
|
85
|
-
values.push(value);
|
|
86
|
-
keys.push(coder.localName || null);
|
|
87
|
-
});
|
|
88
|
-
return Result.fromItems(values, keys);
|
|
89
|
-
}
|
|
90
|
-
class ArrayCoder extends Coder {
|
|
91
|
-
constructor(coder, length, localName) {
|
|
92
|
-
const type = coder.type + "[" + (length >= 0 ? length : "") + "]";
|
|
93
|
-
const dynamic = length === -1 || coder.dynamic;
|
|
94
|
-
super("array", type, localName, dynamic);
|
|
95
|
-
__publicField(this, "coder");
|
|
96
|
-
__publicField(this, "length");
|
|
97
|
-
defineProperties(this, { coder, length });
|
|
98
|
-
}
|
|
99
|
-
defaultValue() {
|
|
100
|
-
const defaultChild = this.coder.defaultValue();
|
|
101
|
-
const result = [];
|
|
102
|
-
for (let i = 0; i < this.length; i++) {
|
|
103
|
-
result.push(defaultChild);
|
|
104
|
-
}
|
|
105
|
-
return result;
|
|
106
|
-
}
|
|
107
|
-
encode(writer, _value) {
|
|
108
|
-
const value = Typed.dereference(_value, "array");
|
|
109
|
-
if (!Array.isArray(value)) {
|
|
110
|
-
this._throwError("expected array value", value);
|
|
111
|
-
}
|
|
112
|
-
let count = this.length;
|
|
113
|
-
if (count === -1) {
|
|
114
|
-
count = value.length;
|
|
115
|
-
writer.writeValue(value.length);
|
|
116
|
-
}
|
|
117
|
-
assertArgumentCount(value.length, count, "coder array" + (this.localName ? " " + this.localName : ""));
|
|
118
|
-
let coders = [];
|
|
119
|
-
for (let i = 0; i < value.length; i++) {
|
|
120
|
-
coders.push(this.coder);
|
|
121
|
-
}
|
|
122
|
-
return pack(writer, coders, value);
|
|
123
|
-
}
|
|
124
|
-
decode(reader) {
|
|
125
|
-
let count = this.length;
|
|
126
|
-
if (count === -1) {
|
|
127
|
-
count = reader.readIndex();
|
|
128
|
-
assert(count * WordSize <= reader.dataLength, "insufficient data length", "BUFFER_OVERRUN", { buffer: reader.bytes, offset: count * WordSize, length: reader.dataLength });
|
|
129
|
-
}
|
|
130
|
-
let coders = [];
|
|
131
|
-
for (let i = 0; i < count; i++) {
|
|
132
|
-
coders.push(new AnonymousCoder(this.coder));
|
|
133
|
-
}
|
|
134
|
-
return unpack(reader, coders);
|
|
135
|
-
}
|
|
1
|
+
import { keccak256 } from "./standards-sdk.es53.js";
|
|
2
|
+
import { toUtf8Bytes } from "./standards-sdk.es56.js";
|
|
3
|
+
function id(value) {
|
|
4
|
+
return keccak256(toUtf8Bytes(value));
|
|
136
5
|
}
|
|
137
6
|
export {
|
|
138
|
-
|
|
139
|
-
pack,
|
|
140
|
-
unpack
|
|
7
|
+
id
|
|
141
8
|
};
|
|
142
9
|
//# sourceMappingURL=standards-sdk.es51.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es51.js","sources":["../../node_modules/ethers/lib.esm/
|
|
1
|
+
{"version":3,"file":"standards-sdk.es51.js","sources":["../../node_modules/ethers/lib.esm/hash/id.js"],"sourcesContent":["import { keccak256 } from \"../crypto/index.js\";\nimport { toUtf8Bytes } from \"../utils/index.js\";\n/**\n * A simple hashing function which operates on UTF-8 strings to\n * compute an 32-byte identifier.\n *\n * This simply computes the [UTF-8 bytes](toUtf8Bytes) and computes\n * the [[keccak256]].\n *\n * @example:\n * id(\"hello world\")\n * //_result:\n */\nexport function id(value) {\n return keccak256(toUtf8Bytes(value));\n}\n//# sourceMappingURL=id.js.map"],"names":[],"mappings":";;AAaO,SAAS,GAAG,OAAO;AACtB,SAAO,UAAU,YAAY,KAAK,CAAC;AACvC;","x_google_ignoreList":[0]}
|