@hashgraphonline/standards-sdk 0.0.120 → 0.0.122

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.
Files changed (90) hide show
  1. package/dist/cjs/hcs-11/client.d.ts +18 -1
  2. package/dist/cjs/hcs-11/client.d.ts.map +1 -1
  3. package/dist/cjs/hcs-11/index.d.ts +1 -0
  4. package/dist/cjs/hcs-11/index.d.ts.map +1 -1
  5. package/dist/cjs/hcs-11/mcp-server-builder.d.ts +118 -0
  6. package/dist/cjs/hcs-11/mcp-server-builder.d.ts.map +1 -0
  7. package/dist/cjs/hcs-11/types.d.ts +77 -18
  8. package/dist/cjs/hcs-11/types.d.ts.map +1 -1
  9. package/dist/cjs/{index-CHar8dVv-B2IK-7-2.cjs → index-CHar8dVv-BkACF223.cjs} +2 -2
  10. package/dist/cjs/{index-CHar8dVv-B2IK-7-2.cjs.map → index-CHar8dVv-BkACF223.cjs.map} +1 -1
  11. package/dist/cjs/index-DjDDRcKz.cjs +11 -0
  12. package/dist/cjs/index-DjDDRcKz.cjs.map +1 -0
  13. package/dist/cjs/standards-sdk.cjs +1 -1
  14. package/dist/es/hcs-11/client.d.ts +18 -1
  15. package/dist/es/hcs-11/client.d.ts.map +1 -1
  16. package/dist/es/hcs-11/index.d.ts +1 -0
  17. package/dist/es/hcs-11/index.d.ts.map +1 -1
  18. package/dist/es/hcs-11/mcp-server-builder.d.ts +118 -0
  19. package/dist/es/hcs-11/mcp-server-builder.d.ts.map +1 -0
  20. package/dist/es/hcs-11/types.d.ts +77 -18
  21. package/dist/es/hcs-11/types.d.ts.map +1 -1
  22. package/dist/es/standards-sdk.es.js +17 -12
  23. package/dist/es/standards-sdk.es.js.map +1 -1
  24. package/dist/es/standards-sdk.es10.js +1 -1
  25. package/dist/es/standards-sdk.es11.js +2 -2
  26. package/dist/es/standards-sdk.es12.js +1 -1
  27. package/dist/es/standards-sdk.es13.js +226 -639
  28. package/dist/es/standards-sdk.es13.js.map +1 -1
  29. package/dist/es/standards-sdk.es14.js +770 -85
  30. package/dist/es/standards-sdk.es14.js.map +1 -1
  31. package/dist/es/standards-sdk.es15.js +132 -68
  32. package/dist/es/standards-sdk.es15.js.map +1 -1
  33. package/dist/es/standards-sdk.es16.js +66 -19
  34. package/dist/es/standards-sdk.es16.js.map +1 -1
  35. package/dist/es/standards-sdk.es17.js +18 -156
  36. package/dist/es/standards-sdk.es17.js.map +1 -1
  37. package/dist/es/standards-sdk.es18.js +150 -146
  38. package/dist/es/standards-sdk.es18.js.map +1 -1
  39. package/dist/es/standards-sdk.es19.js +134 -561
  40. package/dist/es/standards-sdk.es19.js.map +1 -1
  41. package/dist/es/standards-sdk.es2.js +1 -1
  42. package/dist/es/standards-sdk.es20.js +577 -24
  43. package/dist/es/standards-sdk.es20.js.map +1 -1
  44. package/dist/es/standards-sdk.es21.js +23 -400
  45. package/dist/es/standards-sdk.es21.js.map +1 -1
  46. package/dist/es/standards-sdk.es22.js +381 -1507
  47. package/dist/es/standards-sdk.es22.js.map +1 -1
  48. package/dist/es/standards-sdk.es23.js +1511 -133
  49. package/dist/es/standards-sdk.es23.js.map +1 -1
  50. package/dist/es/standards-sdk.es24.js +155 -7
  51. package/dist/es/standards-sdk.es24.js.map +1 -1
  52. package/dist/es/standards-sdk.es25.js +7 -7190
  53. package/dist/es/standards-sdk.es25.js.map +1 -1
  54. package/dist/es/standards-sdk.es26.js +7190 -2
  55. package/dist/es/standards-sdk.es26.js.map +1 -1
  56. package/dist/es/standards-sdk.es27.js +2 -501
  57. package/dist/es/standards-sdk.es27.js.map +1 -1
  58. package/dist/es/standards-sdk.es28.js +456 -64
  59. package/dist/es/standards-sdk.es28.js.map +1 -1
  60. package/dist/es/standards-sdk.es29.js +79 -36
  61. package/dist/es/standards-sdk.es29.js.map +1 -1
  62. package/dist/es/standards-sdk.es3.js +1 -1
  63. package/dist/es/standards-sdk.es30.js +32 -222
  64. package/dist/es/standards-sdk.es30.js.map +1 -1
  65. package/dist/es/standards-sdk.es31.js +183 -100
  66. package/dist/es/standards-sdk.es31.js.map +1 -1
  67. package/dist/es/standards-sdk.es32.js +167 -5
  68. package/dist/es/standards-sdk.es32.js.map +1 -1
  69. package/dist/es/standards-sdk.es33.js +8 -7132
  70. package/dist/es/standards-sdk.es33.js.map +1 -1
  71. package/dist/es/standards-sdk.es35.js +7138 -0
  72. package/dist/es/standards-sdk.es35.js.map +1 -0
  73. package/dist/es/standards-sdk.es4.js +1 -1
  74. package/dist/es/standards-sdk.es5.js +4 -4
  75. package/dist/es/standards-sdk.es7.js +7 -7
  76. package/dist/es/standards-sdk.es8.js +5 -5
  77. package/dist/es/standards-sdk.es9.js +2 -2
  78. package/dist/umd/hcs-11/client.d.ts +18 -1
  79. package/dist/umd/hcs-11/client.d.ts.map +1 -1
  80. package/dist/umd/hcs-11/index.d.ts +1 -0
  81. package/dist/umd/hcs-11/index.d.ts.map +1 -1
  82. package/dist/umd/hcs-11/mcp-server-builder.d.ts +118 -0
  83. package/dist/umd/hcs-11/mcp-server-builder.d.ts.map +1 -0
  84. package/dist/umd/hcs-11/types.d.ts +77 -18
  85. package/dist/umd/hcs-11/types.d.ts.map +1 -1
  86. package/dist/umd/standards-sdk.umd.js +12 -12
  87. package/dist/umd/standards-sdk.umd.js.map +1 -1
  88. package/package.json +2 -2
  89. package/dist/cjs/index-CHS2J8pS.cjs +0 -11
  90. package/dist/cjs/index-CHS2J8pS.cjs.map +0 -1
@@ -1,33 +1,586 @@
1
- import { PrivateKey } from "@hashgraph/sdk";
2
- function detectKeyTypeFromString(privateKeyString) {
3
- let detectedType = "ed25519";
4
- if (privateKeyString.startsWith("0x")) {
5
- detectedType = "ecdsa";
6
- } else if (privateKeyString.startsWith("302e020100300506032b6570")) {
7
- detectedType = "ed25519";
8
- } else if (privateKeyString.startsWith("3030020100300706052b8104000a")) {
9
- detectedType = "ecdsa";
10
- } else if (privateKeyString.length === 96) {
11
- detectedType = "ed25519";
12
- } else if (privateKeyString.length === 88) {
13
- detectedType = "ecdsa";
14
- }
15
- try {
16
- const privateKey = detectedType === "ecdsa" ? PrivateKey.fromStringECDSA(privateKeyString) : PrivateKey.fromStringED25519(privateKeyString);
17
- return { detectedType, privateKey };
18
- } catch (parseError) {
19
- const alternateType = detectedType === "ecdsa" ? "ed25519" : "ecdsa";
1
+ import { proto } from "@hashgraph/proto";
2
+ import { Buffer } from "buffer";
3
+ import { Hbar, Long, HbarUnit } from "@hashgraph/sdk";
4
+ import { ethers } from "ethers";
5
+ import { HTSParser } from "./standards-sdk.es28.js";
6
+ import { HCSParser } from "./standards-sdk.es29.js";
7
+ import { FileParser } from "./standards-sdk.es30.js";
8
+ import { CryptoParser } from "./standards-sdk.es31.js";
9
+ import { SCSParser } from "./standards-sdk.es32.js";
10
+ import { UtilParser } from "./standards-sdk.es33.js";
11
+ class TransactionParser {
12
+ /**
13
+ * Parse a base64 encoded transaction body and return structured data
14
+ * @param transactionBodyBase64 - The base64 encoded transaction body
15
+ * @returns The parsed transaction
16
+ */
17
+ static parseTransactionBody(transactionBodyBase64) {
20
18
  try {
21
- const privateKey = alternateType === "ecdsa" ? PrivateKey.fromStringECDSA(privateKeyString) : PrivateKey.fromStringED25519(privateKeyString);
22
- return { detectedType: alternateType, privateKey };
23
- } catch (secondError) {
19
+ const buffer = ethers.decodeBase64(transactionBodyBase64);
20
+ const txBody = proto.SchedulableTransactionBody.decode(buffer);
21
+ const transactionType = this.getTransactionType(txBody);
22
+ const result = {
23
+ type: transactionType,
24
+ humanReadableType: this.getHumanReadableType(transactionType),
25
+ transfers: [],
26
+ tokenTransfers: [],
27
+ raw: txBody
28
+ };
29
+ if (txBody.memo) {
30
+ result.memo = txBody.memo;
31
+ }
32
+ if (txBody.transactionFee) {
33
+ const hbarAmount = Hbar.fromTinybars(
34
+ Long.fromValue(txBody.transactionFee)
35
+ );
36
+ result.transactionFee = hbarAmount.toString(HbarUnit.Hbar);
37
+ }
38
+ if (txBody.cryptoTransfer) {
39
+ CryptoParser.parseCryptoTransfers(txBody.cryptoTransfer, result);
40
+ }
41
+ if (txBody.cryptoDelete) {
42
+ result.cryptoDelete = CryptoParser.parseCryptoDelete(
43
+ txBody.cryptoDelete
44
+ );
45
+ }
46
+ if (txBody.cryptoCreateAccount) {
47
+ result.cryptoCreateAccount = CryptoParser.parseCryptoCreateAccount(
48
+ txBody.cryptoCreateAccount
49
+ );
50
+ }
51
+ if (txBody.cryptoUpdateAccount) {
52
+ result.cryptoUpdateAccount = CryptoParser.parseCryptoUpdateAccount(
53
+ txBody.cryptoUpdateAccount
54
+ );
55
+ }
56
+ if (txBody.cryptoApproveAllowance) {
57
+ result.cryptoApproveAllowance = CryptoParser.parseCryptoApproveAllowance(
58
+ txBody.cryptoApproveAllowance
59
+ );
60
+ }
61
+ if (txBody.cryptoDeleteAllowance) {
62
+ result.cryptoDeleteAllowance = CryptoParser.parseCryptoDeleteAllowance(
63
+ txBody.cryptoDeleteAllowance
64
+ );
65
+ }
66
+ if (txBody.contractCall) {
67
+ result.contractCall = SCSParser.parseContractCall(txBody.contractCall);
68
+ }
69
+ if (txBody.contractCreateInstance) {
70
+ result.contractCreate = SCSParser.parseContractCreate(
71
+ txBody.contractCreateInstance
72
+ );
73
+ }
74
+ if (txBody.contractUpdateInstance) {
75
+ result.contractUpdate = SCSParser.parseContractUpdate(
76
+ txBody.contractUpdateInstance
77
+ );
78
+ }
79
+ if (txBody.contractDeleteInstance) {
80
+ result.contractDelete = SCSParser.parseContractDelete(
81
+ txBody.contractDeleteInstance
82
+ );
83
+ }
84
+ if (txBody.tokenCreation) {
85
+ result.tokenCreation = HTSParser.parseTokenCreate(txBody.tokenCreation);
86
+ }
87
+ if (txBody.tokenMint) {
88
+ result.tokenMint = HTSParser.parseTokenMint(txBody.tokenMint);
89
+ }
90
+ if (txBody.tokenBurn) {
91
+ result.tokenBurn = HTSParser.parseTokenBurn(txBody.tokenBurn);
92
+ }
93
+ if (txBody.tokenUpdate) {
94
+ result.tokenUpdate = HTSParser.parseTokenUpdate(txBody.tokenUpdate);
95
+ }
96
+ if (txBody.tokenFeeScheduleUpdate) {
97
+ result.tokenFeeScheduleUpdate = HTSParser.parseTokenFeeScheduleUpdate(
98
+ txBody.tokenFeeScheduleUpdate
99
+ );
100
+ }
101
+ if (txBody.tokenFreeze) {
102
+ result.tokenFreeze = HTSParser.parseTokenFreeze(txBody.tokenFreeze);
103
+ }
104
+ if (txBody.tokenUnfreeze) {
105
+ result.tokenUnfreeze = HTSParser.parseTokenUnfreeze(
106
+ txBody.tokenUnfreeze
107
+ );
108
+ }
109
+ if (txBody.tokenGrantKyc) {
110
+ result.tokenGrantKyc = HTSParser.parseTokenGrantKyc(
111
+ txBody.tokenGrantKyc
112
+ );
113
+ }
114
+ if (txBody.tokenRevokeKyc) {
115
+ result.tokenRevokeKyc = HTSParser.parseTokenRevokeKyc(
116
+ txBody.tokenRevokeKyc
117
+ );
118
+ }
119
+ if (txBody.tokenPause) {
120
+ result.tokenPause = HTSParser.parseTokenPause(txBody.tokenPause);
121
+ }
122
+ if (txBody.tokenUnpause) {
123
+ result.tokenUnpause = HTSParser.parseTokenUnpause(txBody.tokenUnpause);
124
+ }
125
+ if (txBody.tokenWipe) {
126
+ result.tokenWipeAccount = HTSParser.parseTokenWipeAccount(
127
+ txBody.tokenWipe
128
+ );
129
+ }
130
+ if (txBody.tokenDeletion) {
131
+ result.tokenDelete = HTSParser.parseTokenDelete(txBody.tokenDeletion);
132
+ }
133
+ if (txBody.tokenAssociate) {
134
+ result.tokenAssociate = HTSParser.parseTokenAssociate(
135
+ txBody.tokenAssociate
136
+ );
137
+ }
138
+ if (txBody.tokenDissociate) {
139
+ result.tokenDissociate = HTSParser.parseTokenDissociate(
140
+ txBody.tokenDissociate
141
+ );
142
+ }
143
+ if (txBody.consensusCreateTopic) {
144
+ result.consensusCreateTopic = HCSParser.parseConsensusCreateTopic(
145
+ txBody.consensusCreateTopic
146
+ );
147
+ }
148
+ if (txBody.consensusSubmitMessage) {
149
+ result.consensusSubmitMessage = HCSParser.parseConsensusSubmitMessage(
150
+ txBody.consensusSubmitMessage
151
+ );
152
+ }
153
+ if (txBody.consensusUpdateTopic) {
154
+ result.consensusUpdateTopic = HCSParser.parseConsensusUpdateTopic(
155
+ txBody.consensusUpdateTopic
156
+ );
157
+ }
158
+ if (txBody.consensusDeleteTopic) {
159
+ result.consensusDeleteTopic = HCSParser.parseConsensusDeleteTopic(
160
+ txBody.consensusDeleteTopic
161
+ );
162
+ }
163
+ if (txBody.fileCreate) {
164
+ result.fileCreate = FileParser.parseFileCreate(txBody.fileCreate);
165
+ }
166
+ if (txBody.fileAppend) {
167
+ result.fileAppend = FileParser.parseFileAppend(txBody.fileAppend);
168
+ }
169
+ if (txBody.fileUpdate) {
170
+ result.fileUpdate = FileParser.parseFileUpdate(txBody.fileUpdate);
171
+ }
172
+ if (txBody.fileDelete) {
173
+ result.fileDelete = FileParser.parseFileDelete(txBody.fileDelete);
174
+ }
175
+ if (txBody.utilPrng) {
176
+ result.utilPrng = UtilParser.parseUtilPrng(txBody.utilPrng);
177
+ }
178
+ return result;
179
+ } catch (error) {
24
180
  throw new Error(
25
- `Failed to parse private key as either ED25519 or ECDSA: ${parseError}`
181
+ `Failed to parse transaction body: ${error instanceof Error ? error.message : String(error)}`
26
182
  );
27
183
  }
28
184
  }
185
+ /**
186
+ * Parse details from a complete schedule response
187
+ * @param scheduleResponse - The schedule response to parse
188
+ * @returns The parsed transaction
189
+ */
190
+ static parseScheduleResponse(scheduleResponse) {
191
+ if (!scheduleResponse.transaction_body) {
192
+ throw new Error("Schedule response missing transaction_body");
193
+ }
194
+ const parsed = this.parseTransactionBody(scheduleResponse.transaction_body);
195
+ if (scheduleResponse.memo) {
196
+ parsed.memo = scheduleResponse.memo;
197
+ }
198
+ return parsed;
199
+ }
200
+ /**
201
+ * Determine the transaction type
202
+ * @param txBody - The transaction body to determine the type of
203
+ * @returns The type of the transaction
204
+ */
205
+ static getTransactionType(txBody) {
206
+ let transactionType = "unknown";
207
+ if (txBody.cryptoTransfer) {
208
+ transactionType = "cryptoTransfer";
209
+ } else if (txBody.cryptoCreateAccount) {
210
+ transactionType = "cryptoCreateAccount";
211
+ } else if (txBody.cryptoUpdateAccount) {
212
+ transactionType = "cryptoUpdateAccount";
213
+ } else if (txBody.cryptoApproveAllowance) {
214
+ transactionType = "cryptoApproveAllowance";
215
+ } else if (txBody.cryptoDeleteAllowance) {
216
+ transactionType = "cryptoDeleteAllowance";
217
+ } else if (txBody.cryptoDelete) {
218
+ transactionType = "cryptoDelete";
219
+ } else if (txBody.consensusCreateTopic) {
220
+ transactionType = "consensusCreateTopic";
221
+ } else if (txBody.consensusUpdateTopic) {
222
+ transactionType = "consensusUpdateTopic";
223
+ } else if (txBody.consensusSubmitMessage) {
224
+ transactionType = "consensusSubmitMessage";
225
+ } else if (txBody.consensusDeleteTopic) {
226
+ transactionType = "consensusDeleteTopic";
227
+ } else if (txBody.fileCreate) {
228
+ transactionType = "fileCreate";
229
+ } else if (txBody.fileAppend) {
230
+ transactionType = "fileAppend";
231
+ } else if (txBody.fileUpdate) {
232
+ transactionType = "fileUpdate";
233
+ } else if (txBody.fileDelete) {
234
+ transactionType = "fileDelete";
235
+ } else if (txBody.contractCall) {
236
+ transactionType = "contractCall";
237
+ } else if (txBody.contractCreateInstance) {
238
+ transactionType = "contractCreate";
239
+ } else if (txBody.contractUpdateInstance) {
240
+ transactionType = "contractUpdate";
241
+ } else if (txBody.contractDeleteInstance) {
242
+ transactionType = "contractDelete";
243
+ } else if (txBody.tokenCreation) {
244
+ transactionType = "tokenCreate";
245
+ } else if (txBody.tokenUpdate) {
246
+ transactionType = "tokenUpdate";
247
+ } else if (txBody.tokenDeletion) {
248
+ transactionType = "tokenDelete";
249
+ } else if (txBody.tokenAssociate) {
250
+ transactionType = "tokenAssociate";
251
+ } else if (txBody.tokenDissociate) {
252
+ transactionType = "tokenDissociate";
253
+ } else if (txBody.tokenMint) {
254
+ transactionType = "tokenMint";
255
+ } else if (txBody.tokenBurn) {
256
+ transactionType = "tokenBurn";
257
+ } else if (txBody.tokenFeeScheduleUpdate) {
258
+ transactionType = "tokenFeeScheduleUpdate";
259
+ } else if (txBody.tokenFreeze) {
260
+ transactionType = "tokenFreeze";
261
+ } else if (txBody.tokenUnfreeze) {
262
+ transactionType = "tokenUnfreeze";
263
+ } else if (txBody.tokenGrantKyc) {
264
+ transactionType = "tokenGrantKyc";
265
+ } else if (txBody.tokenRevokeKyc) {
266
+ transactionType = "tokenRevokeKyc";
267
+ } else if (txBody.tokenPause) {
268
+ transactionType = "tokenPause";
269
+ } else if (txBody.tokenUnpause) {
270
+ transactionType = "tokenUnpause";
271
+ } else if (txBody.tokenWipe) {
272
+ transactionType = "tokenWipe";
273
+ } else if (txBody.utilPrng) {
274
+ transactionType = "utilPrng";
275
+ }
276
+ return transactionType;
277
+ }
278
+ /**
279
+ * Convert technical transaction type to human-readable format
280
+ * @param type - The technical transaction type
281
+ * @returns The human-readable transaction type
282
+ */
283
+ static getHumanReadableType(type) {
284
+ const typeMap = {
285
+ cryptoTransfer: "HBAR Transfer",
286
+ cryptoCreateAccount: "Create Account",
287
+ cryptoUpdateAccount: "Update Account",
288
+ cryptoDeleteAccount: "Delete Account",
289
+ cryptoApproveAllowance: "Approve Allowance",
290
+ cryptoDeleteAllowance: "Delete Allowance",
291
+ cryptoDelete: "Delete Account",
292
+ consensusCreateTopic: "Create Topic",
293
+ consensusUpdateTopic: "Update Topic",
294
+ consensusSubmitMessage: "Submit Message",
295
+ consensusDeleteTopic: "Delete Topic",
296
+ fileCreate: "Create File",
297
+ fileAppend: "Append File",
298
+ fileUpdate: "Update File",
299
+ fileDelete: "Delete File",
300
+ contractCall: "Contract Call",
301
+ contractCreate: "Create Contract",
302
+ contractUpdate: "Update Contract",
303
+ contractDelete: "Delete Contract",
304
+ ethereumTransaction: "Ethereum Transaction",
305
+ tokenCreate: "Create Token",
306
+ tokenUpdate: "Update Token",
307
+ tokenDelete: "Delete Token",
308
+ tokenAssociate: "Associate Token",
309
+ tokenDissociate: "Dissociate Token",
310
+ tokenMint: "Mint Token",
311
+ tokenBurn: "Burn Token",
312
+ tokenFeeScheduleUpdate: "Update Token Fee Schedule",
313
+ tokenFreeze: "Freeze Token",
314
+ tokenUnfreeze: "Unfreeze Token",
315
+ tokenGrantKyc: "Grant KYC",
316
+ tokenRevokeKyc: "Revoke KYC",
317
+ tokenPause: "Pause Token",
318
+ tokenUnpause: "Unpause Token",
319
+ tokenWipe: "Wipe Token",
320
+ scheduleCreate: "Create Schedule",
321
+ scheduleSign: "Sign Schedule",
322
+ utilPrng: "Generate Random Number",
323
+ unknown: "Unknown Transaction"
324
+ };
325
+ let result;
326
+ if (typeMap[type]) {
327
+ result = typeMap[type];
328
+ } else {
329
+ result = "Unknown Transaction";
330
+ }
331
+ return result;
332
+ }
333
+ /**
334
+ * Get a human-readable summary of the transaction
335
+ * @param parsedTx - The parsed transaction
336
+ * @returns The human-readable summary of the transaction
337
+ */
338
+ static getTransactionSummary(parsedTx) {
339
+ if (parsedTx.type === "cryptoTransfer") {
340
+ const senders = [];
341
+ const receivers = [];
342
+ for (const transfer of parsedTx.transfers) {
343
+ const originalAmountFloat = parseFloat(transfer.amount);
344
+ let displayStr = transfer.amount;
345
+ if (displayStr.startsWith("-")) {
346
+ displayStr = displayStr.substring(1);
347
+ }
348
+ displayStr = displayStr.replace(/\s*ℏ$/, "");
349
+ if (originalAmountFloat < 0) {
350
+ senders.push(`${transfer.accountId} (${displayStr} ℏ)`);
351
+ } else if (originalAmountFloat > 0) {
352
+ receivers.push(`${transfer.accountId} (${displayStr} ℏ)`);
353
+ }
354
+ }
355
+ if (senders.length > 0 && receivers.length > 0) {
356
+ return `Transfer of HBAR from ${senders.join(", ")} to ${receivers.join(
357
+ ", "
358
+ )}`;
359
+ } else {
360
+ return parsedTx.humanReadableType;
361
+ }
362
+ } else if (parsedTx.contractCall) {
363
+ let contractCallSummary = `Contract call to ${parsedTx.contractCall.contractId} with ${parsedTx.contractCall.gas} gas`;
364
+ if (parsedTx.contractCall.amount > 0) {
365
+ contractCallSummary += ` and ${parsedTx.contractCall.amount} HBAR`;
366
+ }
367
+ if (parsedTx.contractCall.functionName) {
368
+ contractCallSummary += ` calling function ${parsedTx.contractCall.functionName}`;
369
+ }
370
+ return contractCallSummary;
371
+ } else if (parsedTx.tokenMint) {
372
+ return `Mint ${parsedTx.tokenMint.amount} tokens for token ${parsedTx.tokenMint.tokenId}`;
373
+ } else if (parsedTx.tokenBurn) {
374
+ return `Burn ${parsedTx.tokenBurn.amount} tokens for token ${parsedTx.tokenBurn.tokenId}`;
375
+ } else if (parsedTx.tokenCreation) {
376
+ let summary = `Create token ${parsedTx.tokenCreation.tokenName || "(No Name)"} (${parsedTx.tokenCreation.tokenSymbol || "(No Symbol)"})`;
377
+ if (parsedTx.tokenCreation.initialSupply) {
378
+ summary += ` with initial supply ${parsedTx.tokenCreation.initialSupply}`;
379
+ }
380
+ if (parsedTx.tokenCreation.customFees?.length) {
381
+ summary += ` including ${parsedTx.tokenCreation.customFees.length} custom fee(s)`;
382
+ }
383
+ return summary;
384
+ } else if (parsedTx.tokenTransfers.length > 0) {
385
+ const tokenGroups = {};
386
+ for (const transfer of parsedTx.tokenTransfers) {
387
+ if (!tokenGroups[transfer.tokenId]) {
388
+ tokenGroups[transfer.tokenId] = [];
389
+ }
390
+ tokenGroups[transfer.tokenId].push(transfer);
391
+ }
392
+ const tokenSummaries = [];
393
+ for (const [tokenId, transfers] of Object.entries(tokenGroups)) {
394
+ const tokenSenders = [];
395
+ const tokenReceivers = [];
396
+ for (const transfer of transfers) {
397
+ const transferAmountValue = parseFloat(transfer.amount.toString());
398
+ if (transferAmountValue < 0) {
399
+ tokenSenders.push(
400
+ `${transfer.accountId} (${Math.abs(transferAmountValue)})`
401
+ );
402
+ } else if (transferAmountValue > 0) {
403
+ tokenReceivers.push(
404
+ `${transfer.accountId} (${transferAmountValue})`
405
+ );
406
+ }
407
+ }
408
+ if (tokenSenders.length > 0 && tokenReceivers.length > 0) {
409
+ tokenSummaries.push(
410
+ `Transfer of token ${tokenId} from ${tokenSenders.join(
411
+ ", "
412
+ )} to ${tokenReceivers.join(", ")}`
413
+ );
414
+ }
415
+ }
416
+ if (tokenSummaries.length > 0) {
417
+ return tokenSummaries.join("; ");
418
+ } else {
419
+ return parsedTx.humanReadableType;
420
+ }
421
+ } else if (parsedTx.consensusCreateTopic) {
422
+ let summary = `Create new topic`;
423
+ if (parsedTx.consensusCreateTopic.memo) {
424
+ summary += ` with memo "${parsedTx.consensusCreateTopic.memo}"`;
425
+ }
426
+ if (parsedTx.consensusCreateTopic.autoRenewAccountId) {
427
+ summary += `, auto-renew by ${parsedTx.consensusCreateTopic.autoRenewAccountId}`;
428
+ }
429
+ return summary;
430
+ } else if (parsedTx.consensusSubmitMessage) {
431
+ let summary = `Submit message`;
432
+ if (parsedTx.consensusSubmitMessage.topicId) {
433
+ summary += ` to topic ${parsedTx.consensusSubmitMessage.topicId}`;
434
+ }
435
+ if (parsedTx.consensusSubmitMessage.message) {
436
+ if (parsedTx.consensusSubmitMessage.messageEncoding === "utf8") {
437
+ const messagePreview = parsedTx.consensusSubmitMessage.message.substring(0, 70);
438
+ summary += `: "${messagePreview}${parsedTx.consensusSubmitMessage.message.length > 70 ? "..." : ""}"`;
439
+ } else {
440
+ summary += ` (binary message data, length: ${Buffer.from(parsedTx.consensusSubmitMessage.message, "base64").length} bytes)`;
441
+ }
442
+ }
443
+ if (parsedTx.consensusSubmitMessage.chunkInfoNumber && parsedTx.consensusSubmitMessage.chunkInfoTotal) {
444
+ summary += ` (chunk ${parsedTx.consensusSubmitMessage.chunkInfoNumber}/${parsedTx.consensusSubmitMessage.chunkInfoTotal})`;
445
+ }
446
+ return summary;
447
+ } else if (parsedTx.fileCreate) {
448
+ let summary = "Create File";
449
+ if (parsedTx.fileCreate.memo) {
450
+ summary += ` with memo "${parsedTx.fileCreate.memo}"`;
451
+ }
452
+ if (parsedTx.fileCreate.contents) {
453
+ summary += ` (includes content)`;
454
+ }
455
+ return summary;
456
+ } else if (parsedTx.fileAppend) {
457
+ return `Append to File ${parsedTx.fileAppend.fileId || "(Unknown ID)"}`;
458
+ } else if (parsedTx.fileUpdate) {
459
+ return `Update File ${parsedTx.fileUpdate.fileId || "(Unknown ID)"}`;
460
+ } else if (parsedTx.fileDelete) {
461
+ return `Delete File ${parsedTx.fileDelete.fileId || "(Unknown ID)"}`;
462
+ } else if (parsedTx.consensusUpdateTopic) {
463
+ return `Update Topic ${parsedTx.consensusUpdateTopic.topicId || "(Unknown ID)"}`;
464
+ } else if (parsedTx.consensusDeleteTopic) {
465
+ return `Delete Topic ${parsedTx.consensusDeleteTopic.topicId || "(Unknown ID)"}`;
466
+ } else if (parsedTx.tokenUpdate) {
467
+ return `Update Token ${parsedTx.tokenUpdate.tokenId || "(Unknown ID)"}`;
468
+ } else if (parsedTx.tokenFeeScheduleUpdate) {
469
+ return `Update Fee Schedule for Token ${parsedTx.tokenFeeScheduleUpdate.tokenId || "(Unknown ID)"}`;
470
+ } else if (parsedTx.utilPrng) {
471
+ let summary = "Generate Random Number";
472
+ if (parsedTx.utilPrng.range && parsedTx.utilPrng.range > 0) {
473
+ summary += ` (range up to ${parsedTx.utilPrng.range - 1})`;
474
+ }
475
+ return summary;
476
+ } else if (parsedTx.tokenFreeze) {
477
+ return `Freeze Token ${parsedTx.tokenFreeze.tokenId} for Account ${parsedTx.tokenFreeze.accountId}`;
478
+ } else if (parsedTx.tokenUnfreeze) {
479
+ return `Unfreeze Token ${parsedTx.tokenUnfreeze.tokenId} for Account ${parsedTx.tokenUnfreeze.accountId}`;
480
+ } else if (parsedTx.tokenGrantKyc) {
481
+ return `Grant KYC for Token ${parsedTx.tokenGrantKyc.tokenId} to Account ${parsedTx.tokenGrantKyc.accountId}`;
482
+ } else if (parsedTx.tokenRevokeKyc) {
483
+ return `Revoke KYC for Token ${parsedTx.tokenRevokeKyc.tokenId} from Account ${parsedTx.tokenRevokeKyc.accountId}`;
484
+ } else if (parsedTx.tokenPause) {
485
+ return `Pause Token ${parsedTx.tokenPause.tokenId}`;
486
+ } else if (parsedTx.tokenUnpause) {
487
+ return `Unpause Token ${parsedTx.tokenUnpause.tokenId}`;
488
+ } else if (parsedTx.tokenWipeAccount) {
489
+ let summary = `Wipe Token ${parsedTx.tokenWipeAccount.tokenId} from Account ${parsedTx.tokenWipeAccount.accountId}`;
490
+ if (parsedTx.tokenWipeAccount.serialNumbers?.length) {
491
+ summary += ` (Serials: ${parsedTx.tokenWipeAccount.serialNumbers.join(
492
+ ", "
493
+ )})`;
494
+ }
495
+ if (parsedTx.tokenWipeAccount.amount) {
496
+ summary += ` (Amount: ${parsedTx.tokenWipeAccount.amount})`;
497
+ }
498
+ return summary;
499
+ } else if (parsedTx.tokenDelete) {
500
+ return `Delete Token ${parsedTx.tokenDelete.tokenId}`;
501
+ } else if (parsedTx.tokenAssociate) {
502
+ return `Associate Account ${parsedTx.tokenAssociate.accountId} with Tokens: ${parsedTx.tokenAssociate.tokenIds?.join(", ")}`;
503
+ } else if (parsedTx.tokenDissociate) {
504
+ return `Dissociate Account ${parsedTx.tokenDissociate.accountId} from Tokens: ${parsedTx.tokenDissociate.tokenIds?.join(", ")}`;
505
+ } else if (parsedTx.cryptoDelete) {
506
+ return `Delete Account ${parsedTx.cryptoDelete.deleteAccountId}`;
507
+ }
508
+ if (parsedTx.cryptoCreateAccount) {
509
+ let summary = "Create Account";
510
+ if (parsedTx.cryptoCreateAccount.initialBalance && parsedTx.cryptoCreateAccount.initialBalance !== "0") {
511
+ summary += ` with balance ${parsedTx.cryptoCreateAccount.initialBalance}`;
512
+ }
513
+ if (parsedTx.cryptoCreateAccount.alias) {
514
+ summary += ` (Alias: ${parsedTx.cryptoCreateAccount.alias})`;
515
+ }
516
+ return summary;
517
+ }
518
+ if (parsedTx.cryptoUpdateAccount) {
519
+ return `Update Account ${parsedTx.cryptoUpdateAccount.accountIdToUpdate || "(Unknown ID)"}`;
520
+ }
521
+ if (parsedTx.cryptoApproveAllowance) {
522
+ let count = (parsedTx.cryptoApproveAllowance.hbarAllowances?.length || 0) + (parsedTx.cryptoApproveAllowance.tokenAllowances?.length || 0) + (parsedTx.cryptoApproveAllowance.nftAllowances?.length || 0);
523
+ return `Approve ${count} Crypto Allowance(s)`;
524
+ }
525
+ if (parsedTx.cryptoDeleteAllowance) {
526
+ return `Delete ${parsedTx.cryptoDeleteAllowance.nftAllowancesToRemove?.length || 0} NFT Crypto Allowance(s)`;
527
+ }
528
+ if (parsedTx.contractCreate) {
529
+ let summary = "Create Contract";
530
+ if (parsedTx.contractCreate.memo) {
531
+ summary += ` (Memo: ${parsedTx.contractCreate.memo})`;
532
+ }
533
+ return summary;
534
+ }
535
+ if (parsedTx.contractUpdate) {
536
+ return `Update Contract ${parsedTx.contractUpdate.contractIdToUpdate || "(Unknown ID)"}`;
537
+ }
538
+ if (parsedTx.contractDelete) {
539
+ let summary = `Delete Contract ${parsedTx.contractDelete.contractIdToDelete || "(Unknown ID)"}`;
540
+ if (parsedTx.contractDelete.transferAccountId) {
541
+ summary += ` (Transfer to Account: ${parsedTx.contractDelete.transferAccountId})`;
542
+ } else if (parsedTx.contractDelete.transferContractId) {
543
+ summary += ` (Transfer to Contract: ${parsedTx.contractDelete.transferContractId})`;
544
+ }
545
+ return summary;
546
+ }
547
+ if (parsedTx.humanReadableType && parsedTx.humanReadableType !== "Unknown Transaction") {
548
+ return parsedTx.humanReadableType;
549
+ }
550
+ if (parsedTx.tokenTransfers.length > 0) {
551
+ const tokenGroups = {};
552
+ for (const transfer of parsedTx.tokenTransfers) {
553
+ if (!tokenGroups[transfer.tokenId]) {
554
+ tokenGroups[transfer.tokenId] = [];
555
+ }
556
+ tokenGroups[transfer.tokenId].push(transfer);
557
+ }
558
+ const tokenSummaries = [];
559
+ for (const [tokenId, transfers] of Object.entries(tokenGroups)) {
560
+ const tokenSenders = transfers.filter((t) => t.amount < 0).map((t) => `${t.accountId} (${Math.abs(t.amount)})`);
561
+ const tokenReceivers = transfers.filter((t) => t.amount > 0).map((t) => `${t.accountId} (${t.amount})`);
562
+ if (tokenSenders.length > 0 && tokenReceivers.length > 0) {
563
+ tokenSummaries.push(
564
+ `Transfer of token ${tokenId} from ${tokenSenders.join(
565
+ ", "
566
+ )} to ${tokenReceivers.join(", ")}`
567
+ );
568
+ } else if (tokenReceivers.length > 0) {
569
+ tokenSummaries.push(
570
+ `Token ${tokenId} received by ${tokenReceivers.join(", ")}`
571
+ );
572
+ } else if (tokenSenders.length > 0) {
573
+ tokenSummaries.push(
574
+ `Token ${tokenId} sent from ${tokenSenders.join(", ")}`
575
+ );
576
+ }
577
+ }
578
+ if (tokenSummaries.length > 0) return tokenSummaries.join("; ");
579
+ }
580
+ return "Unknown Transaction";
581
+ }
29
582
  }
30
583
  export {
31
- detectKeyTypeFromString
584
+ TransactionParser
32
585
  };
33
586
  //# sourceMappingURL=standards-sdk.es20.js.map