@hyperbridge/sdk 1.0.0 → 1.1.12

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 (78) hide show
  1. package/README.md +45 -3
  2. package/dist/browser/index.d.ts +1952 -0
  3. package/dist/browser/index.js +6827 -0
  4. package/dist/browser/index.js.map +1 -0
  5. package/dist/browser/web_bg.wasm +0 -0
  6. package/dist/node/index.d.ts +1952 -0
  7. package/dist/node/index.js +6778 -0
  8. package/dist/node/index.js.map +1 -0
  9. package/dist/node/node_bg.wasm +0 -0
  10. package/package.json +43 -15
  11. package/plugins/vite.d.ts +11 -0
  12. package/plugins/vite.js +55 -0
  13. package/dist/abis/erc6160.d.ts +0 -370
  14. package/dist/abis/erc6160.js +0 -238
  15. package/dist/abis/erc6160.js.map +0 -1
  16. package/dist/abis/evmHost.d.ts +0 -1752
  17. package/dist/abis/evmHost.js +0 -2250
  18. package/dist/abis/evmHost.js.map +0 -1
  19. package/dist/abis/handler.d.ts +0 -580
  20. package/dist/abis/handler.js +0 -750
  21. package/dist/abis/handler.js.map +0 -1
  22. package/dist/abis/pingModule.d.ts +0 -594
  23. package/dist/abis/pingModule.js +0 -765
  24. package/dist/abis/pingModule.js.map +0 -1
  25. package/dist/abis/tokenGateway.d.ts +0 -839
  26. package/dist/abis/tokenGateway.js +0 -471
  27. package/dist/abis/tokenGateway.js.map +0 -1
  28. package/dist/chain.d.ts +0 -83
  29. package/dist/chain.js +0 -34
  30. package/dist/chain.js.map +0 -1
  31. package/dist/chains/evm.d.ts +0 -86
  32. package/dist/chains/evm.js +0 -249
  33. package/dist/chains/evm.js.map +0 -1
  34. package/dist/chains/substrate.d.ts +0 -88
  35. package/dist/chains/substrate.js +0 -287
  36. package/dist/chains/substrate.js.map +0 -1
  37. package/dist/client.d.ts +0 -216
  38. package/dist/client.js +0 -774
  39. package/dist/client.js.map +0 -1
  40. package/dist/index.d.ts +0 -6
  41. package/dist/index.js +0 -7
  42. package/dist/index.js.map +0 -1
  43. package/dist/queries.d.ts +0 -3
  44. package/dist/queries.js +0 -78
  45. package/dist/queries.js.map +0 -1
  46. package/dist/tests/hyperbridgeRequests.test.d.ts +0 -1
  47. package/dist/tests/hyperbridgeRequests.test.js +0 -415
  48. package/dist/tests/hyperbridgeRequests.test.js.map +0 -1
  49. package/dist/tests/postRequest.test.d.ts +0 -1
  50. package/dist/tests/postRequest.test.js +0 -293
  51. package/dist/tests/postRequest.test.js.map +0 -1
  52. package/dist/tests/setup.d.ts +0 -1
  53. package/dist/tests/setup.js +0 -6
  54. package/dist/tests/setup.js.map +0 -1
  55. package/dist/tests/tokenGateway.test.d.ts +0 -1
  56. package/dist/tests/tokenGateway.test.js +0 -85
  57. package/dist/tests/tokenGateway.test.js.map +0 -1
  58. package/dist/tests/xcmGateway.test.d.ts +0 -1
  59. package/dist/tests/xcmGateway.test.js +0 -71
  60. package/dist/tests/xcmGateway.test.js.map +0 -1
  61. package/dist/types/index.d.ts +0 -238
  62. package/dist/types/index.js +0 -30
  63. package/dist/types/index.js.map +0 -1
  64. package/dist/utils/mmr.d.ts +0 -13
  65. package/dist/utils/mmr.js +0 -153
  66. package/dist/utils/mmr.js.map +0 -1
  67. package/dist/utils/substrate.d.ts +0 -1913
  68. package/dist/utils/substrate.js +0 -361
  69. package/dist/utils/substrate.js.map +0 -1
  70. package/dist/utils/tokenGateway.d.ts +0 -68
  71. package/dist/utils/tokenGateway.js +0 -151
  72. package/dist/utils/tokenGateway.js.map +0 -1
  73. package/dist/utils/xcmGateway.d.ts +0 -81
  74. package/dist/utils/xcmGateway.js +0 -218
  75. package/dist/utils/xcmGateway.js.map +0 -1
  76. package/dist/utils.d.ts +0 -57
  77. package/dist/utils.js +0 -96
  78. package/dist/utils.js.map +0 -1
@@ -1,287 +0,0 @@
1
- import { ApiPromise, WsProvider } from "@polkadot/api";
2
- import { RpcWebSocketClient } from "rpc-websocket-client";
3
- import { toHex, hexToBytes, toBytes, bytesToHex } from "viem";
4
- import { match } from "ts-pattern";
5
- import capitalize from "lodash/capitalize";
6
- import { u8, Vector } from "scale-ts";
7
- import { BasicProof, isEvmChain, isSubstrateChain, Message, SubstrateStateProof } from "../utils.js";
8
- export class SubstrateChain {
9
- constructor(params) {
10
- this.params = params;
11
- }
12
- /*
13
- * connect: Connects to the Substrate chain using the provided WebSocket URL.
14
- */
15
- async connect() {
16
- const wsProvider = new WsProvider(this.params.ws);
17
- this.api = await ApiPromise.create({
18
- provider: wsProvider,
19
- });
20
- }
21
- /**
22
- * Returns the storage key for a request receipt in the child trie
23
- * The request commitment is the key
24
- * @param key - The H256 hash key (as a 0x-prefixed hex string)
25
- * @returns The storage key as a hex string
26
- */
27
- requestReceiptKey(key) {
28
- const prefix = new TextEncoder().encode("RequestReceipts");
29
- const keyBytes = hexToBytes(key);
30
- // Concatenate the prefix and key bytes
31
- return bytesToHex(new Uint8Array([...prefix, ...keyBytes]));
32
- }
33
- /**
34
- * Returns the storage key for a request commitment in the child trie
35
- * The request commitment is the key
36
- * @param key - The H256 hash key (as a 0x-prefixed hex string)
37
- * @returns The storage key as a hex string
38
- */
39
- requestCommitmentKey(key) {
40
- const prefix = new TextEncoder().encode("RequestCommitments");
41
- const keyBytes = hexToBytes(key);
42
- // Concatenate the prefix and key bytes
43
- return bytesToHex(new Uint8Array([...prefix, ...keyBytes]));
44
- }
45
- /**
46
- * Queries a request commitment from the ISMP child trie storage.
47
- * @param {HexString} commitment - The commitment hash to look up.
48
- * @returns {Promise<HexString | undefined>} The commitment data if found, undefined otherwise.
49
- */
50
- async queryRequestCommitment(commitment) {
51
- const prefix = toHex(":child_storage:default:ISMP");
52
- const key = this.requestCommitmentKey(commitment);
53
- const rpc = new RpcWebSocketClient();
54
- await rpc.connect(this.params.ws);
55
- const item = await rpc.call("childstate_getStorage", [prefix, key]);
56
- return item;
57
- }
58
- /**
59
- * Queries the request receipt.
60
- * @param {HexString} commitment - The commitment to query.
61
- * @returns {Promise<HexString | undefined>} The relayer address responsible for delivering the request.
62
- */
63
- async queryRequestReceipt(commitment) {
64
- const prefix = toHex(":child_storage:default:ISMP");
65
- const key = this.requestReceiptKey(commitment);
66
- const rpc = new RpcWebSocketClient();
67
- await rpc.connect(this.params.ws);
68
- const item = await rpc.call("childstate_getStorage", [prefix, key]);
69
- return item;
70
- }
71
- /**
72
- * Returns the current timestamp of the chain.
73
- * @returns {Promise<bigint>} The current timestamp.
74
- */
75
- async timestamp() {
76
- if (!this.api)
77
- throw new Error("API not initialized");
78
- const now = await this.api.query.timestamp.now();
79
- return BigInt(now.toJSON());
80
- }
81
- /**
82
- * Queries the proof of the requests.
83
- * @param {HexString[]} requests - The requests to query.
84
- * @param {string} counterparty - The counterparty address.
85
- * @param {bigint} [at] - The block number to query at.
86
- * @returns {Promise<HexString>} The proof.
87
- */
88
- async queryRequestsProof(requests, counterparty, at) {
89
- const rpc = new RpcWebSocketClient();
90
- await rpc.connect(this.params.ws);
91
- if (isEvmChain(counterparty)) {
92
- // for evm chains, query the mmr proof
93
- const proof = await rpc.call("mmr_queryProof", [Number(at), { Requests: requests }]);
94
- return toHex(proof.proof);
95
- }
96
- else if (isSubstrateChain(counterparty)) {
97
- // for substrate chains, we use the child trie proof
98
- const childTrieKeys = requests.map(requestCommitmentStorageKey);
99
- const proof = await rpc.call("ismp_queryChildTrieProof", [Number(at), childTrieKeys]);
100
- const basicProof = BasicProof.dec(toHex(proof.proof));
101
- const encoded = SubstrateStateProof.enc({
102
- tag: "OverlayProof",
103
- value: {
104
- hasher: {
105
- tag: this.params.hasher,
106
- value: undefined,
107
- },
108
- storageProof: basicProof,
109
- },
110
- });
111
- return toHex(encoded);
112
- }
113
- else {
114
- throw new Error(`Unsupported chain type for counterparty: ${counterparty}`);
115
- }
116
- }
117
- /**
118
- * Submit an unsigned ISMP transaction to the chain. Resolves when the transaction is finalized.
119
- * @param message - The message to be submitted.
120
- * @returns A promise that resolves to an object containing the transaction hash, block hash, and block number.
121
- */
122
- async submitUnsigned(message) {
123
- const self = this;
124
- if (!self.api)
125
- throw new Error("API not initialized");
126
- // remove the call and method selectors
127
- const args = hexToBytes(self.encode(message)).slice(2);
128
- const tx = self.api.tx.ismp.handleUnsigned(args);
129
- return new Promise(async (resolve, reject) => {
130
- const unsub = await tx.send(async ({ isFinalized, isError, dispatchError, txHash, status }) => {
131
- if (isFinalized) {
132
- unsub();
133
- const blockHash = status.asFinalized.toHex();
134
- const header = await self.api.rpc.chain.getHeader(blockHash);
135
- resolve({
136
- transactionHash: txHash.toHex(),
137
- blockHash: blockHash,
138
- blockNumber: header.number.toNumber(),
139
- });
140
- }
141
- else if (isError) {
142
- unsub();
143
- console.error("Unsigned transaction failed: ", dispatchError);
144
- reject(dispatchError);
145
- }
146
- });
147
- });
148
- }
149
- /**
150
- * Query the state proof for a given set of keys at a specific block height.
151
- * @param at The block height to query the state proof at.
152
- * @param keys The keys to query the state proof for.
153
- * @returns The state proof as a hexadecimal string.
154
- */
155
- async queryStateProof(at, keys) {
156
- const rpc = new RpcWebSocketClient();
157
- await rpc.connect(this.params.ws);
158
- const encodedKeys = keys.map((key) => Array.from(hexToBytes(key)));
159
- const proof = await rpc.call("ismp_queryChildTrieProof", [Number(at), encodedKeys]);
160
- const basicProof = BasicProof.dec(toHex(proof.proof));
161
- const encoded = SubstrateStateProof.enc({
162
- tag: "OverlayProof",
163
- value: {
164
- hasher: {
165
- tag: this.params.hasher,
166
- value: undefined,
167
- },
168
- storageProof: basicProof,
169
- },
170
- });
171
- return toHex(encoded);
172
- }
173
- /**
174
- * Encode an ISMP calldata for a substrate chain.
175
- * @param message The ISMP message to encode.
176
- * @returns The encoded message as a hexadecimal string.
177
- */
178
- encode(message) {
179
- const palletIndex = this.getPalletIndex("Ismp");
180
- const args = match(message)
181
- .with({ kind: "PostRequest" }, (message) => Vector(Message).enc([
182
- {
183
- tag: "RequestMessage",
184
- value: {
185
- requests: message.requests.map((r) => convertIPostRequestToCodec(r)),
186
- proof: {
187
- height: {
188
- height: message.proof.height,
189
- id: {
190
- consensusStateId: Array.from(toBytes(message.proof.consensusStateId)),
191
- id: convertStateMachineIdToEnum(message.proof.stateMachine),
192
- },
193
- },
194
- proof: Array.from(hexToBytes(message.proof.proof)),
195
- },
196
- signer: Array.from(hexToBytes(message.signer)),
197
- },
198
- },
199
- ]))
200
- .with({ kind: "TimeoutPostRequest" }, (message) => Vector(Message).enc([
201
- {
202
- tag: "TimeoutMessage",
203
- value: {
204
- tag: "Post",
205
- value: {
206
- requests: message.requests.map((r) => convertIPostRequestToCodec(r)),
207
- proof: {
208
- height: {
209
- height: message.proof.height,
210
- id: {
211
- consensusStateId: Array.from(toBytes(message.proof.consensusStateId)),
212
- id: convertStateMachineIdToEnum(message.proof.stateMachine),
213
- },
214
- },
215
- proof: Array.from(hexToBytes(message.proof.proof)),
216
- },
217
- },
218
- },
219
- },
220
- ]))
221
- .exhaustive();
222
- // Encoding the call enum and call index
223
- const call = Vector(u8, 2).enc([palletIndex, 0]);
224
- return toHex(new Uint8Array([...call, ...args]));
225
- }
226
- /**
227
- * Returns the index of a pallet by its name, by looking up the pallets in the runtime metadata.
228
- * @param {string} name - The name of the pallet.
229
- * @returns {number} The index of the pallet.
230
- */
231
- getPalletIndex(name) {
232
- if (!this.api)
233
- throw new Error("API not initialized");
234
- const pallets = this.api.runtimeMetadata.asLatest.pallets.entries();
235
- for (const p of pallets) {
236
- if (p[1].name.toString() === name) {
237
- const index = p[1].index.toNumber();
238
- return index;
239
- }
240
- }
241
- throw new Error(`${name} not found in runtime`);
242
- }
243
- }
244
- function requestCommitmentStorageKey(key) {
245
- // Convert "RequestCommitments" to bytes
246
- const prefix = new TextEncoder().encode("RequestCommitments");
247
- // Convert hex key to bytes
248
- const keyBytes = hexToBytes(key);
249
- // Combine prefix and key bytes
250
- return Array.from(new Uint8Array([...prefix, ...keyBytes]));
251
- }
252
- /**
253
- * Converts a state machine ID string to an enum value.
254
- * @param {string} id - The state machine ID string.
255
- * @returns {IStateMachine} The corresponding enum value.
256
- */
257
- export function convertStateMachineIdToEnum(id) {
258
- let [tag, value] = id.split("-");
259
- tag = capitalize(tag);
260
- if (["Evm", "Polkadot", "Kusama"].includes(tag)) {
261
- value = parseInt(value);
262
- }
263
- else {
264
- value = Array.from(toBytes(value));
265
- }
266
- return { tag, value };
267
- }
268
- /**
269
- * Converts an array of IPostRequest objects to a codec representation.
270
- * @param {IPostRequest} request - The array of IPostRequest objects.
271
- * @returns {any} The codec representation of the requests.
272
- */
273
- function convertIPostRequestToCodec(request) {
274
- return {
275
- tag: "Post",
276
- value: {
277
- source: convertStateMachineIdToEnum(request.source),
278
- dest: convertStateMachineIdToEnum(request.dest),
279
- from: Array.from(hexToBytes(request.from)),
280
- to: Array.from(hexToBytes(request.to)),
281
- nonce: request.nonce,
282
- body: Array.from(hexToBytes(request.body)),
283
- timeoutTimestamp: request.timeoutTimestamp,
284
- },
285
- };
286
- }
287
- //# sourceMappingURL=substrate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"substrate.js","sourceRoot":"","sources":["../../src/chains/substrate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,UAAU,MAAM,mBAAmB,CAAA;AAC1C,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAErC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,gBAAgB,EAAiB,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAgB/G,MAAM,OAAO,cAAc;IAK1B,YAA6B,MAA4B;QAA5B,WAAM,GAAN,MAAM,CAAsB;IAAG,CAAC;IAE7D;;OAEG;IACI,KAAK,CAAC,OA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,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IACxB,CAAC;SAAM,CAAC;QACP,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;IACnC,CAAC;IAED,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAA;AACtB,CAAC;AAED;;;;GAIG;AACH,SAAS,0BAA0B,CAAC,OAAqB;IACxD,OAAO;QACN,GAAG,EAAE,MAAM;QACX,KAAK,EAAE;YACN,MAAM,EAAE,2BAA2B,CAAC,OAAO,CAAC,MAAM,CAAC;YACnD,IAAI,EAAE,2BAA2B,CAAC,OAAO,CAAC,IAAI,CAAC;YAC/C,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC1C,EAAE,EAAE,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACtC,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC1C,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;SAC1C;KACD,CAAA;AACF,CAAC"}
package/dist/client.d.ts DELETED
@@ -1,216 +0,0 @@
1
- import { StateMachineUpdate, ClientConfig, RequestWithStatus, HexString, PostRequestTimeoutStatus, RequestStatusWithMetadata } from "./types";
2
- import { IChain } from "./chain";
3
- /**
4
- * IndexerClient provides methods for interacting with the Hyperbridge indexer.
5
- *
6
- * This client facilitates querying and tracking cross-chain requests and their status
7
- * through the Hyperbridge protocol. It supports:
8
- *
9
- * - Querying state machine updates by block height or timestamp
10
- * - Retrieving request status information by transaction hash
11
- * - Monitoring request status changes through streaming interfaces
12
- * - Handling request timeout flows and related proof generation
13
- * - Tracking request finalization across source and destination chains
14
- *
15
- * The client implements automatic retries with exponential backoff for network
16
- * resilience and provides both simple query methods and advanced streaming
17
- * interfaces for real-time status tracking.
18
- *
19
- * The URLs provided in the configuration must point to archive nodes to allow the client to query for storage proofs
20
- * of potentially much older blocks. Regular nodes only store the state for recent blocks and will not be able
21
- * to provide the necessary proofs for cross-chain verification, especially in timeout scenarios.
22
- *
23
- * @example
24
- * ```typescript
25
- * const client = new IndexerClient({
26
- * url: "https://indexer.hyperbridge.xyz/graphql",
27
- * pollInterval: 2000,
28
- * source: {
29
- * stateMachineId: "EVM-1",
30
- * consensusStateId: "ETH0"
31
- * rpcUrl: "",
32
- * host: "0x87ea45..",
33
- * },
34
- * dest: {
35
- * stateMachineId: "EVM-42161",
36
- * consensusStateId: "ETH0"
37
- * rpcUrl: "",
38
- * host: "0x87ea42345..",
39
- * },
40
- * hyperbridge: {
41
- * stateMachineId: "POLKADOT-3367",
42
- * consensusStateId: "DOT0"
43
- * wsUrl: "ws://localhost:9944"
44
- * }
45
- * });
46
- *
47
- * // Query a request status
48
- * const status = await client.queryRequestWithStatus("0x1234...");
49
- *
50
- * // Stream status updates
51
- * for await (const update of client.postRequestStatusStream("0x1234...")) {
52
- * console.log(`Request status: ${update.status}`);
53
- * }
54
- * ```
55
- */
56
- export declare class IndexerClient {
57
- /**
58
- * GraphQL client used for making requests to the indexer
59
- */
60
- private client;
61
- /**
62
- * Configuration for the IndexerClient including URLs, poll intervals, and chain-specific settings
63
- */
64
- private config;
65
- /**
66
- * Default configuration for retry behavior when network requests fail
67
- * - maxRetries: Maximum number of retry attempts before failing
68
- * - backoffMs: Initial backoff time in milliseconds (doubles with each retry)
69
- */
70
- private defaultRetryConfig;
71
- /**
72
- * Creates a new IndexerClient instance
73
- */
74
- constructor(config: ClientConfig);
75
- /**
76
- * Query for a single state machine update event greater than or equal to the given height.
77
- * @params statemachineId - ID of the state machine
78
- * @params height - Starting block height
79
- * @params chain - The identifier for the chain where the state machine update should be queried (corresponds to a stateMachineId)
80
- * @returns Closest state machine update
81
- */
82
- queryStateMachineUpdateByHeight({ statemachineId, height, chain, }: {
83
- statemachineId: string;
84
- chain: string;
85
- height: number;
86
- }): Promise<StateMachineUpdate | undefined>;
87
- /**
88
- * Query for a single state machine update event greater than or equal to the given timestamp.
89
- * @params statemachineId - ID of the state machine
90
- * @params timestamp - Starting block timestamp
91
- * @params chain - The identifier for the chain where the state machine update should be queried (corresponds to a stateMachineId)
92
- * @returns Closest state machine update
93
- */
94
- queryStateMachineUpdateByTimestamp({ statemachineId, commitmentTimestamp, chain, }: {
95
- statemachineId: string;
96
- commitmentTimestamp: bigint;
97
- chain: string;
98
- }): Promise<StateMachineUpdate | undefined>;
99
- /**
100
- * Queries a request by any of its associated hashes and returns it alongside its statuses
101
- * Statuses will be one of SOURCE, HYPERBRIDGE_DELIVERED and DESTINATION
102
- * @param hash - Can be commitment, hyperbridge tx hash, source tx hash, destination tx hash, or timeout tx hash
103
- * @returns Latest status and block metadata of the request
104
- */
105
- queryRequest(hash: string): Promise<RequestWithStatus | undefined>;
106
- /**
107
- * Enhances a request with finality events by querying state machine updates.
108
- *
109
- * This method augments a request object with additional inferred status events
110
- * that represent chain finality confirmations. It adds:
111
- * - SOURCE_FINALIZED: When the source chain has finalized the request
112
- * - HYPERBRIDGE_FINALIZED: When Hyperbridge has finalized the delivery confirmation
113
- *
114
- * The method also generates appropriate calldata for submitting cross-chain proofs
115
- * when applicable.
116
- *
117
- * @param request - The request to enhance with finality events
118
- * @returns The request with finality events added
119
- * @private
120
- */
121
- private addRequestFinalityEvents;
122
- /**
123
- * Adds timeout finality events to a request by querying for relevant timeout proofs and
124
- * chain state necessary for timeout processing.
125
- *
126
- * This method enhances a request object with additional status events related to the
127
- * timeout flow, including:
128
- * - PENDING_TIMEOUT: When a request has passed its timeout timestamp
129
- * - DESTINATION_FINALIZED: When the destination chain has finalized the timeout timestamp
130
- * - HYPERBRIDGE_FINALIZED_TIMEOUT: When hyperbridge has finalized the timeout state
131
- *
132
- * The method also generates appropriate calldata for submitting timeout proofs.
133
- *
134
- * @param request - Request to fill timeout events for
135
- * @returns Request with timeout events filled in, including any proof calldata for timeout submissions
136
- * @private
137
- */
138
- private addTimeoutFinalityEvents;
139
- /**
140
- * Queries a request by any of its associated hashes and returns it alongside its statuses,
141
- * including any finalization events.
142
- * @param hash - Can be commitment, hyperbridge tx hash, source tx hash, destination tx hash, or timeout tx hash
143
- * @returns Full request data with all inferred status events, including SOURCE_FINALIZED and HYPERBRIDGE_FINALIZED
144
- * @remarks Unlike queryRequest(), this method adds derived finalization status events by querying state machine updates
145
- */
146
- queryRequestWithStatus(hash: string): Promise<RequestWithStatus | undefined>;
147
- /**
148
- * Create a Stream of status updates for a post request.
149
- * Stream ends when either the request reaches the destination or times out.
150
- * If the stream yields TimeoutStatus.PENDING_TIMEOUT, use postRequestTimeoutStream() to begin timeout processing.
151
- * @param hash - Can be commitment, hyperbridge tx hash, source tx hash, destination tx hash, or timeout tx hash
152
- * @returns AsyncGenerator that emits status updates until a terminal state is reached
153
- * @example
154
- *
155
- * let client = new IndexerClient(config)
156
- * let stream = client.postRequestStatusStream(hash)
157
- *
158
- * // you can use a for-await-of loop
159
- * for await (const status of stream) {
160
- * console.log(status)
161
- * }
162
- *
163
- * // you can also use a while loop
164
- * while (true) {
165
- * const status = await stream.next()
166
- * if (status.done) {
167
- * break
168
- * }
169
- * console.log(status.value)
170
- * }
171
- *
172
- */
173
- postRequestStatusStream(hash: HexString): AsyncGenerator<RequestStatusWithMetadata, void>;
174
- timeoutStream(timeoutTimestamp: bigint, chain: IChain): AsyncGenerator<RequestStatusWithMetadata, void>;
175
- /**
176
- * Create a Stream of status updates
177
- * @param hash - Can be commitment, hyperbridge tx hash, source tx hash, destination tx hash, or timeout tx hash
178
- * @returns AsyncGenerator that emits status updates until a terminal state is reached
179
- */
180
- private postRequestStatusStreamInternal;
181
- /**
182
- * Create a Stream of status updates for a timed out post request.
183
- * @param hash - Can be commitment, hyperbridge tx hash, source tx hash, destination tx hash, or timeout tx hash
184
- * @returns AsyncGenerator that emits status updates until a terminal state is reached
185
- * @example
186
- *
187
- * let client = new IndexerClient(config)
188
- * let stream = client.postRequestTimeoutStream(hash)
189
- *
190
- * // you can use a for-await-of loop
191
- * for await (const status of stream) {
192
- * console.log(status)
193
- * }
194
- *
195
- * // you can also use a while loop
196
- * while (true) {
197
- * const status = await stream.next()
198
- * if (status.done) {
199
- * break
200
- * }
201
- * console.log(status.value)
202
- * }
203
- */
204
- postRequestTimeoutStream(hash: HexString): AsyncGenerator<PostRequestTimeoutStatus, void>;
205
- /**
206
- * Executes an async operation with exponential backoff retry
207
- * @param operation - Async function to execute
208
- * @param retryConfig - Optional retry configuration
209
- * @returns Result of the operation
210
- * @throws Last encountered error after all retries are exhausted
211
- *
212
- * @example
213
- * const result = await this.withRetry(() => this.queryStatus(hash));
214
- */
215
- private withRetry;
216
- }