@lukso/transaction-decoder 1.0.1-dev.0f1bea5

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 (110) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +486 -0
  3. package/dist/browser.cjs +6912 -0
  4. package/dist/browser.cjs.map +1 -0
  5. package/dist/browser.d.cts +6 -0
  6. package/dist/browser.d.ts +6 -0
  7. package/dist/browser.js +131 -0
  8. package/dist/browser.js.map +1 -0
  9. package/dist/cdn/transaction-decoder.global.js +296 -0
  10. package/dist/cdn/transaction-decoder.global.js.map +1 -0
  11. package/dist/chunk-GGBHTWJL.js +437 -0
  12. package/dist/chunk-GGBHTWJL.js.map +1 -0
  13. package/dist/chunk-GXZOF3QY.js +839 -0
  14. package/dist/chunk-GXZOF3QY.js.map +1 -0
  15. package/dist/chunk-LJ6ES5XF.js +776 -0
  16. package/dist/chunk-LJ6ES5XF.js.map +1 -0
  17. package/dist/chunk-XVHJWV5U.js +4925 -0
  18. package/dist/chunk-XVHJWV5U.js.map +1 -0
  19. package/dist/data.cjs +5518 -0
  20. package/dist/data.cjs.map +1 -0
  21. package/dist/data.d.cts +43 -0
  22. package/dist/data.d.ts +43 -0
  23. package/dist/data.js +55 -0
  24. package/dist/data.js.map +1 -0
  25. package/dist/index-BzXh7poJ.d.cts +524 -0
  26. package/dist/index-BzXh7poJ.d.ts +524 -0
  27. package/dist/index.cjs +6912 -0
  28. package/dist/index.cjs.map +1 -0
  29. package/dist/index.d.cts +756 -0
  30. package/dist/index.d.ts +756 -0
  31. package/dist/index.js +131 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/server.cjs +5644 -0
  34. package/dist/server.cjs.map +1 -0
  35. package/dist/server.d.cts +217 -0
  36. package/dist/server.d.ts +217 -0
  37. package/dist/server.js +644 -0
  38. package/dist/server.js.map +1 -0
  39. package/dist/utils-CBAkjQh3.d.cts +108 -0
  40. package/dist/utils-xT9-km0r.d.ts +108 -0
  41. package/package.json +101 -0
  42. package/src/browser.ts +13 -0
  43. package/src/client/resolveAddresses.ts +157 -0
  44. package/src/core/addressCollector.ts +153 -0
  45. package/src/core/addressResolver.ts +135 -0
  46. package/src/core/dataModel.ts +888 -0
  47. package/src/core/instance.ts +33 -0
  48. package/src/core/integrateDecoder.ts +325 -0
  49. package/src/data.ts +70 -0
  50. package/src/decoder/GENERATOR_PROPOSAL.md +182 -0
  51. package/src/decoder/THREE_PHASE_EXAMPLE.md +108 -0
  52. package/src/decoder/aggregation.ts +218 -0
  53. package/src/decoder/browserCache.ts +237 -0
  54. package/src/decoder/cache/README.md +126 -0
  55. package/src/decoder/cache/index.ts +44 -0
  56. package/src/decoder/cache.ts +139 -0
  57. package/src/decoder/constants.ts +125 -0
  58. package/src/decoder/decodeTransaction.ts +292 -0
  59. package/src/decoder/errors.ts +95 -0
  60. package/src/decoder/events.ts +192 -0
  61. package/src/decoder/functionSignature.ts +344 -0
  62. package/src/decoder/getDataFromExternalSources.ts +248 -0
  63. package/src/decoder/graphqlWS.ts +22 -0
  64. package/src/decoder/interfaces.ts +185 -0
  65. package/src/decoder/keyValue.ts +5 -0
  66. package/src/decoder/kvCache.ts +241 -0
  67. package/src/decoder/lruCache.ts +184 -0
  68. package/src/decoder/lsp7Mint.test.ts +179 -0
  69. package/src/decoder/lsp7TransferBatch.test.ts +105 -0
  70. package/src/decoder/plugins/RegistryAbi.ts +562 -0
  71. package/src/decoder/plugins/enhanceBurntPix.ts +132 -0
  72. package/src/decoder/plugins/enhanceGraffiti.ts +70 -0
  73. package/src/decoder/plugins/enhanceLSP0ERC725Account.ts +179 -0
  74. package/src/decoder/plugins/enhanceLSP26FollowerSystem.ts +88 -0
  75. package/src/decoder/plugins/enhanceLSP6KeyManager.ts +231 -0
  76. package/src/decoder/plugins/enhanceLSP7DigitalAsset.ts +165 -0
  77. package/src/decoder/plugins/enhanceLSP8IdentifiableDigitalAsset.ts +170 -0
  78. package/src/decoder/plugins/enhanceLSP9Vault.ts +57 -0
  79. package/src/decoder/plugins/enhanceRetrieveAbi.ts +85 -0
  80. package/src/decoder/plugins/enhanceSetData.ts +135 -0
  81. package/src/decoder/plugins/index.ts +99 -0
  82. package/src/decoder/plugins/schemaDefault.ts +318 -0
  83. package/src/decoder/plugins/standardPlugin.ts +202 -0
  84. package/src/decoder/registry.ts +322 -0
  85. package/src/decoder/singleGQL.ts +293 -0
  86. package/src/decoder/transaction.ts +198 -0
  87. package/src/decoder/types.ts +465 -0
  88. package/src/decoder/utils.ts +212 -0
  89. package/src/example/usage.ts +172 -0
  90. package/src/index.ts +174 -0
  91. package/src/server/addressResolver.ts +68 -0
  92. package/src/server/caches.ts +209 -0
  93. package/src/server/decodeTransactionSync.ts +156 -0
  94. package/src/server/decodeTransactionsBatch.ts +207 -0
  95. package/src/server/finishDecoding.ts +116 -0
  96. package/src/server/index.ts +81 -0
  97. package/src/server/lsp23Resolver.test.ts +46 -0
  98. package/src/server/lsp23Resolver.ts +419 -0
  99. package/src/server/types.ts +168 -0
  100. package/src/server.ts +22 -0
  101. package/src/shared/addressResolver.ts +651 -0
  102. package/src/shared/cache.ts +144 -0
  103. package/src/shared/constants.ts +21 -0
  104. package/src/stubs/tty.ts +13 -0
  105. package/src/stubs/util.ts +42 -0
  106. package/src/types/index.ts +154 -0
  107. package/src/types/provider.ts +46 -0
  108. package/src/umd.ts +13 -0
  109. package/src/utils/debug.ts +49 -0
  110. package/src/utils/json-bigint.ts +47 -0
@@ -0,0 +1,43 @@
1
+ import * as viem from 'viem';
2
+ import { Abi, Chain } from 'viem';
3
+ import * as _preact_signals_core from '@preact/signals-core';
4
+ import { D as DataModelOptions, I as IDataModel, a as DecodeEventResult, A as ArrayArgs, T as TransactionState, b as DecoderResult, E as EnhancedInfo, c as DataKey } from './index-BzXh7poJ.cjs';
5
+ export { d as AddressState, C as CustomDecodeFunctionDataReturn, e as Info, N as NamedArgs, R as ResultShared, f as ResultType } from './index-BzXh7poJ.cjs';
6
+ export { e as createNamedArgs, f as customDecodeFunctionData, d as dataModel, b as decodeKeyValue, c as decodeKeyValueRaw, a as decodeTransaction, g as extractAddress, h as getPublicClient, s as standardSchemaPlugin } from './utils-CBAkjQh3.cjs';
7
+ import { ERC725JSONSchema } from '@erc725/erc725.js';
8
+
9
+ /**
10
+ * Create a secure DataModel instance
11
+ * Freezes the prototype to prevent prototype pollution attacks
12
+ */
13
+ declare function createDataModel(options?: DataModelOptions): IDataModel;
14
+
15
+ declare const IPFS_GATEWAY = "https://api.universalprofile.cloud/ipfs/";
16
+ /**
17
+ * Concatenation of all the schemas
18
+ */
19
+ declare const defaultSchema: ERC725JSONSchema[];
20
+
21
+ /**
22
+ * Decode events
23
+ *
24
+ * @param log Transaction to decode (should have data/input)
25
+ * @returns Promise<ResultType>
26
+ */
27
+ declare function decodeEvent<abi extends Abi | readonly unknown[] = Abi>(chain: Chain, abi: abi, log: DecodeEventResult): ({
28
+ eventName: string;
29
+ args: ArrayArgs;
30
+ } & DecodeEventResult) | undefined;
31
+
32
+ declare const addTransactions: <T extends unknown | unknown[]>(jsonTransactions: T) => T extends unknown[] ? Array<_preact_signals_core.Signal<TransactionState>> : _preact_signals_core.Signal<TransactionState>;
33
+ declare const updateTransactionData: (hash: viem.Hex, newData: DecoderResult, decoderIndex?: number) => void;
34
+ declare const injectData: (dataList: EnhancedInfo[]) => void;
35
+ declare const updateData: (data: EnhancedInfo) => void;
36
+ declare const setLoading: (keys: DataKey[]) => void;
37
+ declare const setError: (key: DataKey, error: string) => void;
38
+ declare const getMissingKeys: () => DataKey[];
39
+ declare const getLoadingKeys: () => DataKey[];
40
+ declare const clear: () => void;
41
+ declare const remove: (keys: DataKey[]) => void;
42
+
43
+ export { ArrayArgs, DataKey, DataModelOptions, DecoderResult, EnhancedInfo, IDataModel, IPFS_GATEWAY, TransactionState, addTransactions, clear, createDataModel, decodeEvent, defaultSchema, getLoadingKeys, getMissingKeys, injectData, remove, setError, setLoading, updateData, updateTransactionData };
package/dist/data.d.ts ADDED
@@ -0,0 +1,43 @@
1
+ import * as viem from 'viem';
2
+ import { Abi, Chain } from 'viem';
3
+ import * as _preact_signals_core from '@preact/signals-core';
4
+ import { D as DataModelOptions, I as IDataModel, a as DecodeEventResult, A as ArrayArgs, T as TransactionState, b as DecoderResult, E as EnhancedInfo, c as DataKey } from './index-BzXh7poJ.js';
5
+ export { d as AddressState, C as CustomDecodeFunctionDataReturn, e as Info, N as NamedArgs, R as ResultShared, f as ResultType } from './index-BzXh7poJ.js';
6
+ export { e as createNamedArgs, f as customDecodeFunctionData, d as dataModel, b as decodeKeyValue, c as decodeKeyValueRaw, a as decodeTransaction, g as extractAddress, h as getPublicClient, s as standardSchemaPlugin } from './utils-xT9-km0r.js';
7
+ import { ERC725JSONSchema } from '@erc725/erc725.js';
8
+
9
+ /**
10
+ * Create a secure DataModel instance
11
+ * Freezes the prototype to prevent prototype pollution attacks
12
+ */
13
+ declare function createDataModel(options?: DataModelOptions): IDataModel;
14
+
15
+ declare const IPFS_GATEWAY = "https://api.universalprofile.cloud/ipfs/";
16
+ /**
17
+ * Concatenation of all the schemas
18
+ */
19
+ declare const defaultSchema: ERC725JSONSchema[];
20
+
21
+ /**
22
+ * Decode events
23
+ *
24
+ * @param log Transaction to decode (should have data/input)
25
+ * @returns Promise<ResultType>
26
+ */
27
+ declare function decodeEvent<abi extends Abi | readonly unknown[] = Abi>(chain: Chain, abi: abi, log: DecodeEventResult): ({
28
+ eventName: string;
29
+ args: ArrayArgs;
30
+ } & DecodeEventResult) | undefined;
31
+
32
+ declare const addTransactions: <T extends unknown | unknown[]>(jsonTransactions: T) => T extends unknown[] ? Array<_preact_signals_core.Signal<TransactionState>> : _preact_signals_core.Signal<TransactionState>;
33
+ declare const updateTransactionData: (hash: viem.Hex, newData: DecoderResult, decoderIndex?: number) => void;
34
+ declare const injectData: (dataList: EnhancedInfo[]) => void;
35
+ declare const updateData: (data: EnhancedInfo) => void;
36
+ declare const setLoading: (keys: DataKey[]) => void;
37
+ declare const setError: (key: DataKey, error: string) => void;
38
+ declare const getMissingKeys: () => DataKey[];
39
+ declare const getLoadingKeys: () => DataKey[];
40
+ declare const clear: () => void;
41
+ declare const remove: (keys: DataKey[]) => void;
42
+
43
+ export { ArrayArgs, DataKey, DataModelOptions, DecoderResult, EnhancedInfo, IDataModel, IPFS_GATEWAY, TransactionState, addTransactions, clear, createDataModel, decodeEvent, defaultSchema, getLoadingKeys, getMissingKeys, injectData, remove, setError, setLoading, updateData, updateTransactionData };
package/dist/data.js ADDED
@@ -0,0 +1,55 @@
1
+ import {
2
+ createDataModel,
3
+ dataModel,
4
+ decodeTransaction
5
+ } from "./chunk-GXZOF3QY.js";
6
+ import {
7
+ IPFS_GATEWAY,
8
+ createNamedArgs,
9
+ customDecodeFunctionData,
10
+ decodeEvent,
11
+ decodeKeyValue,
12
+ decodeKeyValueRaw,
13
+ defaultSchema,
14
+ extractAddress,
15
+ getPublicClient,
16
+ standardSchemaPlugin
17
+ } from "./chunk-XVHJWV5U.js";
18
+
19
+ // src/data.ts
20
+ var addTransactions = dataModel.addTransactions.bind(dataModel);
21
+ var updateTransactionData = dataModel.updateTransactionData.bind(dataModel);
22
+ var injectData = dataModel.injectData.bind(dataModel);
23
+ var updateData = dataModel.updateData.bind(dataModel);
24
+ var setLoading = dataModel.setLoading.bind(dataModel);
25
+ var setError = dataModel.setError.bind(dataModel);
26
+ var getMissingKeys = dataModel.getMissingKeys.bind(dataModel);
27
+ var getLoadingKeys = dataModel.getLoadingKeys.bind(dataModel);
28
+ var clear = dataModel.clear.bind(dataModel);
29
+ var remove = dataModel.remove.bind(dataModel);
30
+ export {
31
+ IPFS_GATEWAY,
32
+ addTransactions,
33
+ clear,
34
+ createDataModel,
35
+ createNamedArgs,
36
+ customDecodeFunctionData,
37
+ dataModel,
38
+ decodeEvent,
39
+ decodeKeyValue,
40
+ decodeKeyValueRaw,
41
+ decodeTransaction,
42
+ defaultSchema,
43
+ extractAddress,
44
+ getLoadingKeys,
45
+ getMissingKeys,
46
+ getPublicClient,
47
+ injectData,
48
+ remove,
49
+ setError,
50
+ setLoading,
51
+ standardSchemaPlugin,
52
+ updateData,
53
+ updateTransactionData
54
+ };
55
+ //# sourceMappingURL=data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/data.ts"],"sourcesContent":["/**\n * @lukso/transaction-decoder/data - Data Provider API\n *\n * This module exports functions for data providers to manage transaction and address data.\n * Consumers should use the main '@lukso/transaction-decoder' import instead.\n */\n\nimport { dataModel } from './core/instance'\n\n// Export provider-specific types\nexport type {\n AddressState,\n DataKey,\n DataModelOptions,\n DecoderResult,\n EnhancedInfo,\n IDataModel,\n TransactionState,\n} from './types'\n\n// Export data management methods\nexport const addTransactions = dataModel.addTransactions.bind(dataModel)\nexport const updateTransactionData =\n dataModel.updateTransactionData.bind(dataModel)\n\n// Address data management\nexport const injectData = dataModel.injectData.bind(dataModel)\nexport const updateData = dataModel.updateData.bind(dataModel)\nexport const setLoading = dataModel.setLoading.bind(dataModel)\nexport const setError = dataModel.setError.bind(dataModel)\n\n// Collection management\nexport const getMissingKeys = dataModel.getMissingKeys.bind(dataModel)\nexport const getLoadingKeys = dataModel.getLoadingKeys.bind(dataModel)\n\n// Maintenance methods\nexport const clear = dataModel.clear.bind(dataModel)\nexport const remove = dataModel.remove.bind(dataModel)\n\n// Also export the full data model for advanced usage\nexport { dataModel }\n\n// Export factory function for creating new instances\nexport { createDataModel } from './core/dataModel'\n// Export useful constants for plugin developers\nexport { defaultSchema, IPFS_GATEWAY } from './decoder/constants'\n\nexport { decodeTransaction } from './decoder/decodeTransaction'\nexport { decodeEvent } from './decoder/events'\nexport {\n decodeKeyValue,\n decodeKeyValueRaw,\n standardSchemaPlugin,\n} from './decoder/plugins'\n// Export additional types for plugin development\nexport type {\n ArrayArgs,\n CustomDecodeFunctionDataReturn,\n Info,\n NamedArgs,\n ResultShared,\n ResultType,\n} from './decoder/types'\n// Export plugin development utilities\nexport {\n createNamedArgs,\n customDecodeFunctionData,\n extractAddress,\n getPublicClient,\n} from './decoder/utils'\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAqBO,IAAM,kBAAkB,UAAU,gBAAgB,KAAK,SAAS;AAChE,IAAM,wBACX,UAAU,sBAAsB,KAAK,SAAS;AAGzC,IAAM,aAAa,UAAU,WAAW,KAAK,SAAS;AACtD,IAAM,aAAa,UAAU,WAAW,KAAK,SAAS;AACtD,IAAM,aAAa,UAAU,WAAW,KAAK,SAAS;AACtD,IAAM,WAAW,UAAU,SAAS,KAAK,SAAS;AAGlD,IAAM,iBAAiB,UAAU,eAAe,KAAK,SAAS;AAC9D,IAAM,iBAAiB,UAAU,eAAe,KAAK,SAAS;AAG9D,IAAM,QAAQ,UAAU,MAAM,KAAK,SAAS;AAC5C,IAAM,SAAS,UAAU,OAAO,KAAK,SAAS;","names":[]}
@@ -0,0 +1,524 @@
1
+ import { Signal } from '@preact/signals-core';
2
+ import { Transaction, Hex, AbiParameter, Log, Address, Chain, Abi, DecodeFunctionDataReturnType } from 'viem';
3
+ import { ERC725JSONSchema } from '@erc725/erc725.js';
4
+
5
+ /**
6
+ * Cache interface for decoder with support for different backends
7
+ * (LRU, Cloudflare KV, Redis, etc.)
8
+ */
9
+
10
+ /**
11
+ * Cache entry with metadata
12
+ */
13
+ interface CacheEntry<T> {
14
+ /** The cached value */
15
+ value: T;
16
+ /** Timestamp when the entry expires (ms since epoch) */
17
+ expires?: number;
18
+ /** Timestamp when the entry becomes stale (for stale-while-revalidate) */
19
+ stale?: number;
20
+ /** Whether this entry resulted from an error */
21
+ isError?: boolean;
22
+ }
23
+ /**
24
+ * Options for cache operations
25
+ */
26
+ interface CacheOptions {
27
+ /** Time to live in milliseconds */
28
+ ttl?: number;
29
+ /** TTL for error responses (typically shorter) */
30
+ errorTTL?: number;
31
+ /** Time in ms after which the value is stale but still usable */
32
+ staleWhileRevalidate?: number;
33
+ }
34
+ /**
35
+ * Generic cache interface that can be implemented by different backends
36
+ */
37
+ interface DecoderCache {
38
+ /**
39
+ * Get a value from the cache
40
+ */
41
+ get<T>(key: string): Promise<CacheEntry<T> | undefined>;
42
+ /**
43
+ * Set a value in the cache
44
+ */
45
+ set<T>(key: string, value: T, options?: CacheOptions): Promise<void>;
46
+ /**
47
+ * Delete a value from the cache
48
+ */
49
+ delete(key: string): Promise<void>;
50
+ /**
51
+ * Get multiple values at once (for batch operations)
52
+ */
53
+ getMany?<T>(keys: string[]): Promise<Map<string, CacheEntry<T>>>;
54
+ /**
55
+ * Set multiple values at once (for batch operations)
56
+ */
57
+ setMany?<T>(entries: Array<{
58
+ key: string;
59
+ value: T;
60
+ options?: CacheOptions;
61
+ }>): Promise<void>;
62
+ /**
63
+ * Clear all entries (optional)
64
+ */
65
+ clear?(): Promise<void>;
66
+ /**
67
+ * Get or set with automatic promise deduplication
68
+ * This is the main method for async operations
69
+ */
70
+ getOrSet<T>(key: string, factory: (signal?: AbortSignal) => Promise<T>, options?: CacheOptions & {
71
+ signal?: AbortSignal;
72
+ }): Promise<T>;
73
+ }
74
+
75
+ /**
76
+ * Array length item: Represents the length of an ERC725 Array schema item.
77
+ */
78
+ type ArrayLengthInfo = ERC725JSONSchema & {
79
+ type: 'ArrayLength';
80
+ value: number;
81
+ pretty?: string;
82
+ };
83
+ /**
84
+ * Array item: Represents the value of an ERC725 Array schema item.
85
+ */
86
+ type ArrayItemInfo = ERC725JSONSchema & {
87
+ type: 'ArrayItem';
88
+ dynamic: number;
89
+ value: unknown;
90
+ pretty?: string;
91
+ };
92
+ /**
93
+ * Value item: Represents the value of an ERC725 schema item.
94
+ */
95
+ type ValueInfo = ERC725JSONSchema & {
96
+ type: 'Value';
97
+ dynamic?: string | string[];
98
+ value: unknown;
99
+ data?: string;
100
+ method?: string;
101
+ url?: string;
102
+ src?: string;
103
+ pretty?: string;
104
+ };
105
+ /**
106
+ * Undecoded item: Represents an undecoded ERC725 schema item (unknown, raw data).
107
+ */
108
+ type UndecodedInfo = {
109
+ type: 'Undecoded';
110
+ key: string;
111
+ name: undefined;
112
+ value: string;
113
+ };
114
+ /**
115
+ * Error item: Error happened during decoding or retrieval (404 or exception due to invalid data)
116
+ */
117
+ type ErrorInfo = ERC725JSONSchema & {
118
+ type: 'Error';
119
+ key: string;
120
+ value: string | Error;
121
+ data?: string;
122
+ method?: string;
123
+ url?: string;
124
+ src?: string;
125
+ pretty?: string;
126
+ };
127
+ /**
128
+ * Info item: Results of the decoded schema.
129
+ */
130
+ type Info = ArrayLengthInfo | ArrayItemInfo | ValueInfo | UndecodedInfo | ErrorInfo;
131
+ /**
132
+ * Add address as a property to the record so that obj.address instead of obj['address'] can be used
133
+ */
134
+ type EnhancedInfo = {
135
+ address: `0x${string}`;
136
+ standard?: string;
137
+ tokenId?: `0x${string}`;
138
+ name?: string;
139
+ __gqltype?: 'Profile' | 'Asset' | 'Token';
140
+ [key: string]: unknown;
141
+ };
142
+ type NamedArgs = Record<string | number, AbiParameter & {
143
+ value?: unknown;
144
+ }>;
145
+ type ArrayArgs = Array<AbiParameter & {
146
+ value?: unknown;
147
+ }>;
148
+ type ResultShared = {
149
+ resultType?: string;
150
+ standard?: string;
151
+ type?: string;
152
+ sig?: `0x${string}` | null;
153
+ graphqlData?: Record<Hex, EnhancedInfo>;
154
+ /**
155
+ * Decoding phase - added by server-side decoder
156
+ */
157
+ phase?: 'immediate' | 'enhanced';
158
+ /**
159
+ * Whether this result was served from cache - added by server-side decoder
160
+ */
161
+ cached?: boolean;
162
+ /**
163
+ * Time taken to decode (milliseconds)
164
+ */
165
+ timeTaken?: number;
166
+ moduleHint?: string;
167
+ logs?: DecodeEventResult[];
168
+ isDecoded?: boolean;
169
+ error?: {
170
+ code: string;
171
+ message: string;
172
+ details: Error;
173
+ };
174
+ processingError?: {
175
+ message: string;
176
+ code: unknown;
177
+ };
178
+ blockTimestamp?: number;
179
+ /**
180
+ * List of addresses found in the transaction (to, from, args, namedArgs, wrappers)
181
+ */
182
+ addresses?: DataKey[];
183
+ transactionHash?: Hex;
184
+ /**
185
+ * Custom data for view matching and extensibility.
186
+ * Populated by enhancers to provide additional context for view selection.
187
+ *
188
+ * Common use cases:
189
+ * - tokenType: 0 (token) | 1 (NFT) | 2 (collection)
190
+ * - isToken, isNFT, isCollection: boolean flags
191
+ * - operationType: 'mint' | 'burn' | 'transfer'
192
+ * - hasMetadata: boolean
193
+ * - customFlags: any enhancer-specific data
194
+ *
195
+ * This field is NOT typed to allow for plugin extensibility.
196
+ */
197
+ custom?: Record<string, unknown>;
198
+ enhancementAttempted?: boolean;
199
+ };
200
+ type ResultError = {
201
+ resultType: 'error';
202
+ functionName?: string;
203
+ errorType: ErrorType;
204
+ sig: `0x${string}`;
205
+ input?: `0x${string}` | null;
206
+ args?: ArrayArgs;
207
+ summary?: string;
208
+ devdocs?: string;
209
+ };
210
+ type ResultAggregate = {
211
+ resultType: 'aggregate';
212
+ aggregate: {
213
+ count: number;
214
+ blockRange: {
215
+ from: number;
216
+ to: number;
217
+ };
218
+ [key: string]: unknown;
219
+ };
220
+ functionName?: string;
221
+ args?: ArrayArgs;
222
+ wrappers?: Array<ResultType>;
223
+ devdocs?: string;
224
+ };
225
+ type ResultExecute = {
226
+ resultType: 'execute';
227
+ functionName?: string;
228
+ args?: ArrayArgs;
229
+ wrappers?: Array<ResultType>;
230
+ devdocs?: string;
231
+ };
232
+ type ResultCreate = {
233
+ resultType: 'create';
234
+ wrappers?: Array<ResultType>;
235
+ args?: ArrayArgs;
236
+ };
237
+ type ResultWrapper = {
238
+ resultType: 'wrapper';
239
+ functionName?: string;
240
+ args?: ArrayArgs;
241
+ devdocs?: string;
242
+ };
243
+ type ResultFollowProfile = {
244
+ resultType: 'followProfile';
245
+ functionName?: string;
246
+ address: Address;
247
+ };
248
+ type ResultExecuteBatch = {
249
+ resultType: 'executeBatch';
250
+ functionName: string;
251
+ args?: ArrayArgs;
252
+ children: Array<ResultType & ResultShared>;
253
+ wrappers?: Array<ResultType & ResultShared>;
254
+ devdocs?: string;
255
+ };
256
+ type ResultSetDataBatch = {
257
+ resultType: 'setDataBatch';
258
+ functionName?: string;
259
+ standard?: string;
260
+ args?: ArrayArgs;
261
+ children: Array<ResultSetData & ResultShared>;
262
+ wrappers?: Array<ResultType & ResultShared>;
263
+ devdocs?: string;
264
+ };
265
+ type ResultGrafitti = {
266
+ resultType: 'grafitti';
267
+ standard?: string;
268
+ graffiti: string;
269
+ devdocs?: string;
270
+ functionName?: string;
271
+ };
272
+ type ResultSetData = {
273
+ resultType: 'setData';
274
+ functionName?: string;
275
+ tokenId?: `0x${string}`;
276
+ args?: ArrayArgs;
277
+ wrappers?: Array<ResultType & ResultShared>;
278
+ info?: Info;
279
+ devdocs?: string;
280
+ };
281
+ type ResultRaw = {
282
+ resultType: 'raw';
283
+ standard?: string;
284
+ input?: `0x${string}`;
285
+ };
286
+ /**
287
+ * DecodeFunctionDataReturn: Represents the return type of a decodeTransaction function.
288
+ * There are extra properties added to the return type to make it more useful.
289
+ * Internally some of the properties are used to decode the data so in some places
290
+ * we use "any" to avoid type errors during the decoding process.
291
+ * The main offenders here are isDecoded: boolean and __decoder: string and so on.
292
+ * Rather than mixing those into the type, then it would make the types unnecessarily complex.
293
+ */
294
+ type ResultComponent = ResultExecute | ResultCreate | ResultWrapper | ResultSetDataBatch | ResultExecuteBatch | ResultSetData | ResultGrafitti | ResultRaw | ResultError | ResultAggregate | ResultFollowProfile;
295
+ /**
296
+ * The main result type returned by decodeTransaction.
297
+ */
298
+ type ResultType = Partial<Omit<Transaction, 'type' | 'logs' | 'blobVersionedHashes'>> & ResultShared & ResultComponent & {
299
+ __decoder?: string;
300
+ __decoderVerifiedContract?: boolean;
301
+ type?: string;
302
+ logs?: DecodeEventResult[];
303
+ blobVersionedHashes?: readonly Hex[];
304
+ };
305
+ /**
306
+ * CustomDecodeFunctionDataReturn: Represents the return type of a customDecodeFunctionData function.
307
+ * Basically the normal decodeFunctionData doesn't return the abi entry, so that
308
+ * we can't decode argument names and types.
309
+ */
310
+ type CustomDecodeFunctionDataReturn<abi extends Abi | readonly unknown[]> = DecodeFunctionDataReturnType<abi> & {
311
+ args?: ArrayArgs;
312
+ };
313
+ declare enum ErrorType {
314
+ EMPTY_REVERT = "EMPTY_REVERT",
315
+ INVALID = "INVALID",
316
+ PANIC = "PANIC",
317
+ ERROR = "ERROR",
318
+ CUSTOM_ERROR = "CUSTOM_ERROR",
319
+ UNKNOWN = "UNKNOWN"
320
+ }
321
+ /**
322
+ * The output of the enhancer
323
+ */
324
+ type DecoderResult = ResultType & ResultShared & {
325
+ /** Which aggregations apply (just keys, no plugin prefix) */
326
+ aggregationKeys?: string[];
327
+ };
328
+ /**
329
+ * Aggregation configuration for map/reduce operations
330
+ */
331
+ interface Aggregation<T = any> {
332
+ /** Unique key for this aggregation within the plugin */
333
+ key: string;
334
+ /** Extract/transform data from a single transaction */
335
+ map: (tx: DecoderResult) => T | undefined;
336
+ /** Combine mapped data with existing state */
337
+ reduce: (state: T | undefined, mapped: T) => T;
338
+ /** Transform state for final output */
339
+ finalize: (state: T) => Omit<ResultAggregate, 'resultType'>;
340
+ }
341
+ /**
342
+ * Bitmap enum for controlling which async operations are enabled
343
+ */
344
+ declare enum AsyncOperations {
345
+ /** No async operations (default) */
346
+ DISABLED = 0,// 0b000
347
+ /** Enable async plugins (ABI fetching, function signatures) */
348
+ ENABLE_PLUGINS = 1,// 0b001
349
+ /** Enable address resolution (profile/address metadata) */
350
+ ENABLE_ADDRESS_RESOLVE = 2,// 0b010
351
+ /** Enable external data fetching (IPFS, external JSON) */
352
+ ENABLE_EXTERNAL_DATA = 4
353
+ }
354
+ /**
355
+ * Options to modify operations which now also have to be sent down to the enhancer and plugin
356
+ */
357
+ type DecoderOptions = {
358
+ plugins: ReadonlyArray<DecoderPlugin>;
359
+ schemaPlugins: ReadonlyArray<SchemaPlugin>;
360
+ preferError?: boolean;
361
+ wrappers: Array<ResultType & ResultShared>;
362
+ chain: Chain;
363
+ /**
364
+ * Controls which async operations are enabled.
365
+ * Can be a boolean for backward compatibility (true = all async, false = none)
366
+ * or AsyncOperations enum for fine-grained control
367
+ */
368
+ async?: boolean | AsyncOperations;
369
+ /** Cache implementation for async operations */
370
+ cache?: DecoderCache;
371
+ /** Timeout for async operations in milliseconds */
372
+ timeout?: number;
373
+ /** AbortSignal for cancelling async operations */
374
+ signal?: AbortSignal;
375
+ };
376
+ /**
377
+ * Generic plugin into decoder (most of the time this will be wrapped with the standard plugin to provide
378
+ * additional or existing abis)
379
+ */
380
+ type DecoderPlugin = {
381
+ enhance: (transaction: DecoderResult, options: DecoderOptions) => Promise<DecoderResult | undefined>;
382
+ decodeEvent: (log: DecodeEventResult, options: DecoderOptions) => Promise<DecodeEventResult>;
383
+ getAggregationKey?: EnhancerAggregationKeyCallback;
384
+ summarize?: EnhancerSummarizeCallback;
385
+ name?: string;
386
+ required?: boolean;
387
+ priority?: number;
388
+ usesAsync?: boolean;
389
+ /** Aggregations supported by this plugin */
390
+ aggregations?: Aggregation[];
391
+ };
392
+ type PluginOptions = {
393
+ abiName: string;
394
+ decoderName?: string;
395
+ moduleHint?: string;
396
+ name?: string;
397
+ required?: boolean;
398
+ priority?: number;
399
+ usesAsync?: boolean;
400
+ };
401
+ /**
402
+ * Type for the actual enhancement logic
403
+ */
404
+ type EnhancerCallback = (result: DecoderResult, pluginOptions: PluginOptions, options: DecoderOptions) => Promise<DecoderResult | undefined>;
405
+ type EnhancerAggregationKeyCallback = (result: DecoderResult, pluginOptions: PluginOptions, options: DecoderOptions) => Promise<string | undefined>;
406
+ type EnhancerSummarizeCallback = (aggregateKey: string, result: DecoderResult[], pluginOptions: PluginOptions, options: DecoderOptions) => Promise<DecoderResult | undefined>;
407
+ /**
408
+ * Plugins to execute decodeData with custom schema tables.
409
+ * The passed in data will contain the abi name, functionName and so on.
410
+ */
411
+ type SchemaPlugin = ((key: Hex, value: Hex) => Promise<Info | undefined>) & {
412
+ name?: string;
413
+ required?: boolean;
414
+ priority?: number;
415
+ };
416
+ /**
417
+ * Plugin callback function to decode events.
418
+ */
419
+ type DecodeEventCallback = (log: DecodeEventResult, options: DecoderOptions) => Promise<DecodeEventResult>;
420
+ type DecodeEventResult = ({
421
+ eventName: string;
422
+ args: ArrayArgs;
423
+ } & Log) | undefined;
424
+
425
+ /**
426
+ * Core types for @lukso/decoder
427
+ */
428
+
429
+ type DataKey = Hex;
430
+ type DeepReadonly<T> = T extends (infer R)[] ? DeepReadonlyArray<R> : T extends (...args: unknown[]) => unknown ? T : T extends object ? DeepReadonlyObject<T> : T;
431
+ interface DeepReadonlyArray<T> extends ReadonlyArray<DeepReadonly<T>> {
432
+ }
433
+ type DeepReadonlyObject<T> = {
434
+ readonly [P in keyof T]: DeepReadonly<T[P]>;
435
+ };
436
+ /**
437
+ * State wrapper for address/asset information
438
+ */
439
+ interface AddressState {
440
+ loading: boolean;
441
+ data?: DeepReadonly<EnhancedInfo>;
442
+ error?: string;
443
+ lastUpdated?: number;
444
+ }
445
+ /**
446
+ * Transaction decoding status
447
+ * - raw: No decoding attempted yet
448
+ * - decoded: Sync decoding complete (phase 1)
449
+ * - enhanced: ABI retrieval complete (phase 2)
450
+ * - complete: Address resolution complete (phase 3)
451
+ * - failed: Decoding failed
452
+ */
453
+ type DecodingStatus = 'raw' | 'decoded' | 'enhanced' | 'complete' | 'failed';
454
+ /**
455
+ * State wrapper for decoded transactions
456
+ */
457
+ interface TransactionState {
458
+ loading: boolean;
459
+ data: DeepReadonly<DecoderResult>;
460
+ addresses: ReadonlyArray<DataKey>;
461
+ error?: string;
462
+ lastUpdated?: number;
463
+ decodingStatus?: DecodingStatus;
464
+ addressesResolved?: boolean;
465
+ resolvedData?: DeepReadonly<DecoderResult>;
466
+ }
467
+ /**
468
+ * Options for creating a data model instance
469
+ */
470
+ interface DataModelOptions {
471
+ onMissingKeys?: (keys: DataKey[]) => void;
472
+ onNewTransaction?: (transaction: unknown) => void;
473
+ }
474
+ /**
475
+ * Read-only interface for consumers (views, components)
476
+ * This is the interface available on window.transactionDecoder
477
+ */
478
+ interface IDataModelConsumer {
479
+ getTransaction(jsonTransaction: unknown): Signal<TransactionState> | undefined;
480
+ getTransactionByKey(hash: Hex, decoderIndex?: number): Signal<TransactionState> | undefined;
481
+ getTransactionsByIndex(index: number): Map<number | null, Signal<TransactionState>> | undefined;
482
+ getTransactionHashByIndex(index: number): Hex | undefined;
483
+ getTransactionCount(): number;
484
+ getDecodedCount(hash: Hex): number;
485
+ getDecodedTransactions(hash: Hex): Array<Signal<TransactionState>>;
486
+ getTransactionsInOrder(): Array<{
487
+ hash: Hex;
488
+ transactions: Array<Signal<TransactionState>>;
489
+ }>;
490
+ getAddress(address: DataKey): Signal<AddressState>;
491
+ getSignal(key: DataKey): Signal<AddressState>;
492
+ subscribe(key: DataKey, callback: (state: AddressState) => void): () => void;
493
+ getState(key: DataKey): AddressState;
494
+ hasData(key: DataKey): boolean;
495
+ getData(key: DataKey): DeepReadonly<EnhancedInfo> | undefined;
496
+ isLoading(key: DataKey): boolean;
497
+ getError(key: DataKey): string | undefined;
498
+ getAllKeys(): ReadonlyArray<DataKey>;
499
+ getAllData(): Readonly<Record<string, AddressState>>;
500
+ getAllTransactions(): Readonly<Record<string, TransactionState>>;
501
+ }
502
+ /**
503
+ * Full interface for data management (used by data providers)
504
+ * Includes all consumer methods plus data modification methods
505
+ */
506
+ interface IDataModel extends IDataModelConsumer {
507
+ addTransactions<T extends unknown | unknown[]>(jsonTransactions: T): T extends unknown[] ? Array<Signal<TransactionState>> : Signal<TransactionState>;
508
+ updateTransactionData(hash: Hex, newData: DecoderResult, decoderIndex?: number): void;
509
+ injectData(dataList: EnhancedInfo[]): void;
510
+ updateData(data: EnhancedInfo): void;
511
+ setLoading(keys: DataKey[]): void;
512
+ setError(key: DataKey, error: string): void;
513
+ getMissingKeys(): DataKey[];
514
+ getLoadingKeys(): DataKey[];
515
+ clear(): void;
516
+ remove(keys: DataKey[]): void;
517
+ }
518
+ declare global {
519
+ interface Window {
520
+ TransactionDecoder?: IDataModelConsumer;
521
+ }
522
+ }
523
+
524
+ export type { ArrayArgs as A, CustomDecodeFunctionDataReturn as C, DataModelOptions as D, EnhancedInfo as E, IDataModel as I, NamedArgs as N, PluginOptions as P, ResultShared as R, SchemaPlugin as S, TransactionState as T, DecodeEventResult as a, DecoderResult as b, DataKey as c, AddressState as d, Info as e, ResultType as f, IDataModelConsumer as g, DecoderOptions as h, EnhancerCallback as i, DecodeEventCallback as j, EnhancerAggregationKeyCallback as k, EnhancerSummarizeCallback as l, Aggregation as m, DecoderPlugin as n, ResultSetData as o, ResultAggregate as p, ResultCreate as q, ResultError as r, ResultExecute as s, ResultExecuteBatch as t, ResultFollowProfile as u, ResultGrafitti as v, ResultRaw as w, ResultSetDataBatch as x, ResultWrapper as y };