@hyperbridge/sdk 1.0.0

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 (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +127 -0
  3. package/dist/abis/erc6160.d.ts +370 -0
  4. package/dist/abis/erc6160.js +238 -0
  5. package/dist/abis/erc6160.js.map +1 -0
  6. package/dist/abis/evmHost.d.ts +1752 -0
  7. package/dist/abis/evmHost.js +2250 -0
  8. package/dist/abis/evmHost.js.map +1 -0
  9. package/dist/abis/handler.d.ts +580 -0
  10. package/dist/abis/handler.js +750 -0
  11. package/dist/abis/handler.js.map +1 -0
  12. package/dist/abis/pingModule.d.ts +594 -0
  13. package/dist/abis/pingModule.js +765 -0
  14. package/dist/abis/pingModule.js.map +1 -0
  15. package/dist/abis/tokenGateway.d.ts +839 -0
  16. package/dist/abis/tokenGateway.js +471 -0
  17. package/dist/abis/tokenGateway.js.map +1 -0
  18. package/dist/chain.d.ts +83 -0
  19. package/dist/chain.js +34 -0
  20. package/dist/chain.js.map +1 -0
  21. package/dist/chains/evm.d.ts +86 -0
  22. package/dist/chains/evm.js +249 -0
  23. package/dist/chains/evm.js.map +1 -0
  24. package/dist/chains/substrate.d.ts +88 -0
  25. package/dist/chains/substrate.js +287 -0
  26. package/dist/chains/substrate.js.map +1 -0
  27. package/dist/client.d.ts +216 -0
  28. package/dist/client.js +774 -0
  29. package/dist/client.js.map +1 -0
  30. package/dist/index.d.ts +6 -0
  31. package/dist/index.js +7 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/queries.d.ts +3 -0
  34. package/dist/queries.js +78 -0
  35. package/dist/queries.js.map +1 -0
  36. package/dist/tests/hyperbridgeRequests.test.d.ts +1 -0
  37. package/dist/tests/hyperbridgeRequests.test.js +415 -0
  38. package/dist/tests/hyperbridgeRequests.test.js.map +1 -0
  39. package/dist/tests/postRequest.test.d.ts +1 -0
  40. package/dist/tests/postRequest.test.js +293 -0
  41. package/dist/tests/postRequest.test.js.map +1 -0
  42. package/dist/tests/setup.d.ts +1 -0
  43. package/dist/tests/setup.js +6 -0
  44. package/dist/tests/setup.js.map +1 -0
  45. package/dist/tests/tokenGateway.test.d.ts +1 -0
  46. package/dist/tests/tokenGateway.test.js +85 -0
  47. package/dist/tests/tokenGateway.test.js.map +1 -0
  48. package/dist/tests/xcmGateway.test.d.ts +1 -0
  49. package/dist/tests/xcmGateway.test.js +71 -0
  50. package/dist/tests/xcmGateway.test.js.map +1 -0
  51. package/dist/types/index.d.ts +238 -0
  52. package/dist/types/index.js +30 -0
  53. package/dist/types/index.js.map +1 -0
  54. package/dist/utils/mmr.d.ts +13 -0
  55. package/dist/utils/mmr.js +153 -0
  56. package/dist/utils/mmr.js.map +1 -0
  57. package/dist/utils/substrate.d.ts +1913 -0
  58. package/dist/utils/substrate.js +361 -0
  59. package/dist/utils/substrate.js.map +1 -0
  60. package/dist/utils/tokenGateway.d.ts +68 -0
  61. package/dist/utils/tokenGateway.js +151 -0
  62. package/dist/utils/tokenGateway.js.map +1 -0
  63. package/dist/utils/xcmGateway.d.ts +81 -0
  64. package/dist/utils/xcmGateway.js +218 -0
  65. package/dist/utils/xcmGateway.js.map +1 -0
  66. package/dist/utils.d.ts +57 -0
  67. package/dist/utils.js +96 -0
  68. package/dist/utils.js.map +1 -0
  69. package/package.json +74 -0
@@ -0,0 +1,86 @@
1
+ import { IChain, IIsmpMessage } from "../chain";
2
+ import { HexString } from "../types";
3
+ /**
4
+ * The default address used as fallback when no address is provided.
5
+ * This represents the zero address in EVM chains.
6
+ */
7
+ export declare const DEFAULT_ADDRESS = "0x0000000000000000000000000000000000000000";
8
+ /**
9
+ * Parameters for an EVM chain.
10
+ */
11
+ export interface EvmChainParams {
12
+ /**
13
+ * The chain ID of the EVM chain.
14
+ */
15
+ chainId: number;
16
+ /**
17
+ * The host address of the EVM chain.
18
+ */
19
+ host: HexString;
20
+ /**
21
+ * The URL of the EVM chain.
22
+ */
23
+ url: string;
24
+ }
25
+ /**
26
+ * Encapsulates an EVM chain.
27
+ */
28
+ export declare class EvmChain implements IChain {
29
+ private readonly params;
30
+ private publicClient;
31
+ constructor(params: EvmChainParams);
32
+ /**
33
+ * Derives the key for the request receipt.
34
+ * @param {HexString} commitment - The commitment to derive the key from.
35
+ * @returns {HexString} The derived key.
36
+ */
37
+ requestReceiptKey(commitment: HexString): HexString;
38
+ /**
39
+ * Queries the request receipt.
40
+ * @param {HexString} commitment - The commitment to query.
41
+ * @returns {Promise<HexString | undefined>} The relayer address responsible for delivering the request.
42
+ */
43
+ queryRequestReceipt(commitment: HexString): Promise<HexString | undefined>;
44
+ /**
45
+ * Queries the proof of the requests.
46
+ * @param {HexString[]} requests - The requests to query.
47
+ * @param {string} counterparty - The counterparty address.
48
+ * @param {bigint} [at] - The block number to query at.
49
+ * @returns {Promise<HexString>} The proof.
50
+ */
51
+ queryRequestsProof(requests: HexString[], counterparty: string, at?: bigint): Promise<HexString>;
52
+ /**
53
+ * Query and return the encoded storage proof for the provided keys at the given height.
54
+ * @param {bigint} at - The block height at which to query the storage proof.
55
+ * @param {HexString[]} keys - The keys for which to query the storage proof.
56
+ * @returns {Promise<HexString>} The encoded storage proof.
57
+ */
58
+ queryStateProof(at: bigint, keys: HexString[]): Promise<HexString>;
59
+ /**
60
+ * Returns the current timestamp of the chain.
61
+ * @returns {Promise<bigint>} The current timestamp.
62
+ */
63
+ timestamp(): Promise<bigint>;
64
+ /**
65
+ * Encodes an ISMP message for the EVM chain.
66
+ * @param {IIsmpMessage} message The ISMP message to encode.
67
+ * @returns {HexString} The encoded calldata.
68
+ */
69
+ encode(message: IIsmpMessage): HexString;
70
+ }
71
+ /**
72
+ * Slot for storing request commitments.
73
+ */
74
+ export declare const REQUEST_COMMITMENTS_SLOT = 0n;
75
+ /**
76
+ * Slot index for response commitments map
77
+ */
78
+ export declare const RESPONSE_COMMITMENTS_SLOT = 1n;
79
+ /**
80
+ * Slot index for requests receipts map
81
+ */
82
+ export declare const REQUEST_RECEIPTS_SLOT = 2n;
83
+ /**
84
+ * Slot index for response receipts map
85
+ */
86
+ export declare const RESPONSE_RECEIPTS_SLOT = 3n;
@@ -0,0 +1,249 @@
1
+ import { bytesToBigInt, bytesToHex, createPublicClient, encodeFunctionData, hexToBytes, http, toHex, keccak256, toBytes, pad, } from "viem";
2
+ import { mainnet, arbitrum, arbitrumSepolia, optimism, optimismSepolia, base, baseSepolia, soneium, bsc, bscTestnet, gnosis, gnosisChiado, } from "viem/chains";
3
+ import flatten from "lodash/flatten";
4
+ import zip from "lodash/zip";
5
+ import { match } from "ts-pattern";
6
+ import EvmHost from "../abis/evmHost.js";
7
+ import HandlerV1 from "../abis/handler.js";
8
+ import { calculateMMRSize, EvmStateProof, mmrPositionToKIndex, MmrProof, SubstrateStateProof } from "../utils.js";
9
+ const chains = {
10
+ [mainnet.id]: mainnet,
11
+ [arbitrum.id]: arbitrum,
12
+ [arbitrumSepolia.id]: arbitrumSepolia,
13
+ [optimism.id]: optimism,
14
+ [optimismSepolia.id]: optimismSepolia,
15
+ [base.id]: base,
16
+ [baseSepolia.id]: baseSepolia,
17
+ [soneium.id]: soneium,
18
+ [bsc.id]: bsc,
19
+ [bscTestnet.id]: bscTestnet,
20
+ [gnosis.id]: gnosis,
21
+ [gnosisChiado.id]: gnosisChiado,
22
+ };
23
+ /**
24
+ * The default address used as fallback when no address is provided.
25
+ * This represents the zero address in EVM chains.
26
+ */
27
+ export const DEFAULT_ADDRESS = "0x0000000000000000000000000000000000000000";
28
+ /**
29
+ * Encapsulates an EVM chain.
30
+ */
31
+ export class EvmChain {
32
+ constructor(params) {
33
+ this.params = params;
34
+ // @ts-ignore
35
+ this.publicClient = createPublicClient({
36
+ // @ts-ignore
37
+ chain: chains[params.chainId],
38
+ transport: http(params.url),
39
+ });
40
+ }
41
+ /**
42
+ * Derives the key for the request receipt.
43
+ * @param {HexString} commitment - The commitment to derive the key from.
44
+ * @returns {HexString} The derived key.
45
+ */
46
+ requestReceiptKey(commitment) {
47
+ return deriveMapKey(hexToBytes(commitment), REQUEST_RECEIPTS_SLOT);
48
+ }
49
+ /**
50
+ * Queries the request receipt.
51
+ * @param {HexString} commitment - The commitment to query.
52
+ * @returns {Promise<HexString | undefined>} The relayer address responsible for delivering the request.
53
+ */
54
+ async queryRequestReceipt(commitment) {
55
+ const relayer = await this.publicClient.readContract({
56
+ address: this.params.host,
57
+ abi: EvmHost.ABI,
58
+ functionName: "requestReceipts",
59
+ args: [commitment],
60
+ });
61
+ // solidity returns zeroes if the storage slot is empty
62
+ return relayer === DEFAULT_ADDRESS ? undefined : relayer;
63
+ }
64
+ /**
65
+ * Queries the proof of the requests.
66
+ * @param {HexString[]} requests - The requests to query.
67
+ * @param {string} counterparty - The counterparty address.
68
+ * @param {bigint} [at] - The block number to query at.
69
+ * @returns {Promise<HexString>} The proof.
70
+ */
71
+ async queryRequestsProof(requests, counterparty, at) {
72
+ const self = this;
73
+ // for each request derive the commitment key collect into a new array
74
+ const commitmentKeys = requests.map(requestCommitmentKey);
75
+ const config = {
76
+ address: this.params.host,
77
+ storageKeys: commitmentKeys,
78
+ };
79
+ if (!at) {
80
+ config.blockTag = "latest";
81
+ }
82
+ else {
83
+ config.blockNumber = at;
84
+ }
85
+ const proof = await self.publicClient.getProof(config);
86
+ const flattenedProof = Array.from(new Set(flatten(proof.storageProof.map((item) => item.proof))));
87
+ const encoded = EvmStateProof.enc({
88
+ contractProof: proof.accountProof.map((item) => Array.from(hexToBytes(item))),
89
+ storageProof: [
90
+ [Array.from(hexToBytes(self.params.host)), flattenedProof.map((item) => Array.from(hexToBytes(item)))],
91
+ ],
92
+ });
93
+ return toHex(encoded);
94
+ }
95
+ /**
96
+ * Query and return the encoded storage proof for the provided keys at the given height.
97
+ * @param {bigint} at - The block height at which to query the storage proof.
98
+ * @param {HexString[]} keys - The keys for which to query the storage proof.
99
+ * @returns {Promise<HexString>} The encoded storage proof.
100
+ */
101
+ async queryStateProof(at, keys) {
102
+ const self = this;
103
+ const config = {
104
+ address: this.params.host,
105
+ storageKeys: keys,
106
+ };
107
+ if (!at) {
108
+ config.blockTag = "latest";
109
+ }
110
+ else {
111
+ config.blockNumber = at;
112
+ }
113
+ const proof = await self.publicClient.getProof(config);
114
+ const flattenedProof = Array.from(new Set(flatten(proof.storageProof.map((item) => item.proof))));
115
+ const encoded = EvmStateProof.enc({
116
+ contractProof: proof.accountProof.map((item) => Array.from(hexToBytes(item))),
117
+ storageProof: [
118
+ [Array.from(hexToBytes(self.params.host)), flattenedProof.map((item) => Array.from(hexToBytes(item)))],
119
+ ],
120
+ });
121
+ return toHex(encoded);
122
+ }
123
+ /**
124
+ * Returns the current timestamp of the chain.
125
+ * @returns {Promise<bigint>} The current timestamp.
126
+ */
127
+ async timestamp() {
128
+ const data = await this.publicClient.readContract({
129
+ address: this.params.host,
130
+ abi: EvmHost.ABI,
131
+ functionName: "timestamp",
132
+ });
133
+ return BigInt(data);
134
+ }
135
+ /**
136
+ * Encodes an ISMP message for the EVM chain.
137
+ * @param {IIsmpMessage} message The ISMP message to encode.
138
+ * @returns {HexString} The encoded calldata.
139
+ */
140
+ encode(message) {
141
+ const encoded = match(message)
142
+ .with({ kind: "PostRequest" }, (request) => {
143
+ const mmrProof = MmrProof.dec(request.proof.proof);
144
+ const requests = zip(request.requests, mmrProof.leafIndexAndPos)
145
+ .map(([req, leafIndexAndPos]) => {
146
+ if (!req || !leafIndexAndPos)
147
+ return;
148
+ const [[, kIndex]] = mmrPositionToKIndex([leafIndexAndPos?.pos], calculateMMRSize(mmrProof.leafCount));
149
+ return {
150
+ request: {
151
+ source: toHex(req.source),
152
+ dest: toHex(req.dest),
153
+ to: req.to,
154
+ from: req.from,
155
+ nonce: req.nonce,
156
+ timeoutTimestamp: req.timeoutTimestamp,
157
+ body: req.body,
158
+ },
159
+ index: leafIndexAndPos?.leafIndex,
160
+ kIndex,
161
+ };
162
+ })
163
+ .filter((item) => !!item);
164
+ const proof = {
165
+ height: {
166
+ stateMachineId: BigInt(parseInt(request.proof.stateMachine.split("-")[1])),
167
+ height: request.proof.height,
168
+ },
169
+ multiproof: mmrProof.items.map((item) => bytesToHex(new Uint8Array(item))),
170
+ leafCount: mmrProof.leafCount,
171
+ };
172
+ const encoded = encodeFunctionData({
173
+ abi: HandlerV1.ABI,
174
+ functionName: "handlePostRequests",
175
+ args: [
176
+ this.params.host,
177
+ {
178
+ proof,
179
+ requests,
180
+ },
181
+ ],
182
+ });
183
+ return encoded;
184
+ })
185
+ .with({ kind: "TimeoutPostRequest" }, (timeout) => {
186
+ const proof = SubstrateStateProof.dec(timeout.proof.proof).value.storageProof.map((item) => toHex(new Uint8Array(item)));
187
+ const encoded = encodeFunctionData({
188
+ abi: HandlerV1.ABI,
189
+ functionName: "handlePostRequestTimeouts",
190
+ args: [
191
+ this.params.host,
192
+ {
193
+ height: {
194
+ stateMachineId: BigInt(parseInt(timeout.proof.stateMachine.split("-")[1])),
195
+ height: timeout.proof.height,
196
+ },
197
+ timeouts: timeout.requests.map((req) => ({
198
+ source: toHex(req.source),
199
+ dest: toHex(req.dest),
200
+ to: req.to,
201
+ from: req.from,
202
+ nonce: req.nonce,
203
+ timeoutTimestamp: req.timeoutTimestamp,
204
+ body: req.body,
205
+ })),
206
+ proof,
207
+ },
208
+ ],
209
+ });
210
+ return encoded;
211
+ })
212
+ .exhaustive();
213
+ return encoded;
214
+ }
215
+ }
216
+ /**
217
+ * Slot for storing request commitments.
218
+ */
219
+ export const REQUEST_COMMITMENTS_SLOT = 0n;
220
+ /**
221
+ * Slot index for response commitments map
222
+ */
223
+ export const RESPONSE_COMMITMENTS_SLOT = 1n;
224
+ /**
225
+ * Slot index for requests receipts map
226
+ */
227
+ export const REQUEST_RECEIPTS_SLOT = 2n;
228
+ /**
229
+ * Slot index for response receipts map
230
+ */
231
+ export const RESPONSE_RECEIPTS_SLOT = 3n;
232
+ function requestCommitmentKey(key) {
233
+ // First derive the map key
234
+ const keyBytes = hexToBytes(key);
235
+ const mappedKey = deriveMapKey(keyBytes, REQUEST_COMMITMENTS_SLOT);
236
+ // Convert the derived key to BigInt and add 1
237
+ const number = bytesToBigInt(hexToBytes(mappedKey)) + 1n;
238
+ // Convert back to 32-byte hex
239
+ return pad(`0x${number.toString(16)}`, { size: 32 });
240
+ }
241
+ function deriveMapKey(key, slot) {
242
+ // Convert slot to 32-byte big-endian representation
243
+ const slotBytes = pad(`0x${slot.toString(16)}`, { size: 32 });
244
+ // Combine key and slot bytes
245
+ const combined = new Uint8Array([...key, ...toBytes(slotBytes)]);
246
+ // Calculate keccak256 hash
247
+ return keccak256(combined);
248
+ }
249
+ //# sourceMappingURL=evm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evm.js","sourceRoot":"","sources":["../../src/chains/evm.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,kBAAkB,EAClB,UAAU,EACV,IAAI,EAEJ,KAAK,EACL,SAAS,EACT,OAAO,EACP,GAAG,GACH,MAAM,MAAM,CAAA;AACb,OAAO,EACN,OAAO,EACP,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,eAAe,EACf,IAAI,EACJ,WAAW,EACX,OAAO,EACP,GAAG,EACH,UAAU,EACV,MAAM,EACN,YAAY,GACZ,MAAM,aAAa,CAAA;AAGpB,OAAO,OAAO,MAAM,gBAAgB,CAAA;AACpC,OAAO,GAAG,MAAM,YAAY,CAAA;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAElC,OAAO,OAAO,MAAM,gBAAgB,CAAA;AAEpC,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,mBAAmB,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAG7G,MAAM,MAAM,GAAG;IACd,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,OAAO;IACrB,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,QAAQ;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;IACrC,2BAA2B;IAC3B,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,CAAA;IAChC,MAAM,SAAS,GAAG,YAAY,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAA;IAElE,8CAA8C;IAC9C,MAAM,MAAM,GAAG,aAAa,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,CAAA;IAExD,8BAA8B;IAC9B,OAAO,GAAG,CAAC,KAAK,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAA;AACrD,CAAC;AAED,SAAS,YAAY,CAAC,GAAe,EAAE,IAAY;IAClD,oDAAoD;IACpD,MAAM,SAAS,GAAG,GAAG,CAAC,KAAK,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAA;IAE7D,6BAA6B;IAC7B,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;IAEhE,2BAA2B;IAC3B,OAAO,SAAS,CAAC,QAAQ,CAAC,CAAA;AAC3B,CAAC"}
@@ -0,0 +1,88 @@
1
+ import { ApiPromise } from "@polkadot/api";
2
+ import { IStateMachine } from "../utils";
3
+ import { IChain, IIsmpMessage } from "../chain";
4
+ import { HexString } from "../types";
5
+ export interface SubstrateChainParams {
6
+ ws: string;
7
+ hasher: "Keccak" | "Blake2";
8
+ }
9
+ export declare class SubstrateChain implements IChain {
10
+ private readonly params;
11
+ api?: ApiPromise;
12
+ constructor(params: SubstrateChainParams);
13
+ connect(): Promise<void>;
14
+ /**
15
+ * Returns the storage key for a request receipt in the child trie
16
+ * The request commitment is the key
17
+ * @param key - The H256 hash key (as a 0x-prefixed hex string)
18
+ * @returns The storage key as a hex string
19
+ */
20
+ requestReceiptKey(key: HexString): HexString;
21
+ /**
22
+ * Returns the storage key for a request commitment 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
+ requestCommitmentKey(key: HexString): HexString;
28
+ /**
29
+ * Queries a request commitment from the ISMP child trie storage.
30
+ * @param {HexString} commitment - The commitment hash to look up.
31
+ * @returns {Promise<HexString | undefined>} The commitment data if found, undefined otherwise.
32
+ */
33
+ queryRequestCommitment(commitment: HexString): Promise<HexString | undefined>;
34
+ /**
35
+ * Queries the request receipt.
36
+ * @param {HexString} commitment - The commitment to query.
37
+ * @returns {Promise<HexString | undefined>} The relayer address responsible for delivering the request.
38
+ */
39
+ queryRequestReceipt(commitment: HexString): Promise<HexString | undefined>;
40
+ /**
41
+ * Returns the current timestamp of the chain.
42
+ * @returns {Promise<bigint>} The current timestamp.
43
+ */
44
+ timestamp(): Promise<bigint>;
45
+ /**
46
+ * Queries the proof of the requests.
47
+ * @param {HexString[]} requests - The requests to query.
48
+ * @param {string} counterparty - The counterparty address.
49
+ * @param {bigint} [at] - The block number to query at.
50
+ * @returns {Promise<HexString>} The proof.
51
+ */
52
+ queryRequestsProof(requests: HexString[], counterparty: string, at?: bigint): Promise<HexString>;
53
+ /**
54
+ * Submit an unsigned ISMP transaction to the chain. Resolves when the transaction is finalized.
55
+ * @param message - The message to be submitted.
56
+ * @returns A promise that resolves to an object containing the transaction hash, block hash, and block number.
57
+ */
58
+ submitUnsigned(message: IIsmpMessage): Promise<{
59
+ transactionHash: string;
60
+ blockHash: string;
61
+ blockNumber: number;
62
+ }>;
63
+ /**
64
+ * Query the state proof for a given set of keys at a specific block height.
65
+ * @param at The block height to query the state proof at.
66
+ * @param keys The keys to query the state proof for.
67
+ * @returns The state proof as a hexadecimal string.
68
+ */
69
+ queryStateProof(at: bigint, keys: HexString[]): Promise<HexString>;
70
+ /**
71
+ * Encode an ISMP calldata for a substrate chain.
72
+ * @param message The ISMP message to encode.
73
+ * @returns The encoded message as a hexadecimal string.
74
+ */
75
+ encode(message: IIsmpMessage): HexString;
76
+ /**
77
+ * Returns the index of a pallet by its name, by looking up the pallets in the runtime metadata.
78
+ * @param {string} name - The name of the pallet.
79
+ * @returns {number} The index of the pallet.
80
+ */
81
+ private getPalletIndex;
82
+ }
83
+ /**
84
+ * Converts a state machine ID string to an enum value.
85
+ * @param {string} id - The state machine ID string.
86
+ * @returns {IStateMachine} The corresponding enum value.
87
+ */
88
+ export declare function convertStateMachineIdToEnum(id: string): IStateMachine;