@hyperbridge/sdk 1.0.0 → 1.2.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 (78) hide show
  1. package/README.md +45 -3
  2. package/dist/browser/index.d.ts +2190 -0
  3. package/dist/browser/index.js +11662 -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 +2190 -0
  7. package/dist/node/index.js +11613 -0
  8. package/dist/node/index.js.map +1 -0
  9. package/dist/node/node_bg.wasm +0 -0
  10. package/package.json +46 -16
  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,218 +0,0 @@
1
- import { u8aToHex } from "@polkadot/util";
2
- import { decodeAddress } from "@polkadot/util-crypto";
3
- import { parseUnits } from "viem";
4
- const DECIMALS = 10;
5
- /**
6
- * Teleports DOT tokens from Polkadot relay chain to an EVM-based destination chain
7
- * using XCM (Cross-Consensus Message Format).
8
- *
9
- * This function initiates a teleport transaction, monitors its status, and yields events
10
- * about the transaction's progress through an AsyncGenerator. It handles the complete
11
- * lifecycle of a teleport operation:
12
- * 1. Transaction preparation and signing
13
- * 2. Broadcasting to the relay chain
14
- * 3. Tracking the transaction until it's included in a block
15
- * 4. Monitoring Hyperbridge for the commitment hash
16
- *
17
- * @param relayApi - Polkadot API instance connected to the relay chain
18
- * @param hyperbridge - Polkadot API instance connected to the Hyperbridge parachain
19
- * @param who - Sender's SS58Address address
20
- * @param options - Transaction signing options
21
- * @param params - Teleport parameters including destination, recipient, and amount
22
- * @yields {HyperbridgeTxEvents} Stream of events indicating transaction status
23
- * @throws {Error} If there's an issue getting the Hyperbridge block or other failures
24
- */
25
- export async function teleportDot(relayApi, hyperbridge, who, options, params) {
26
- // 2. initiate the transaction
27
- const destination = {
28
- V3: {
29
- parents: 0,
30
- interior: {
31
- X1: {
32
- Parachain: params.paraId,
33
- },
34
- },
35
- },
36
- };
37
- const beneficiary = {
38
- V3: {
39
- parents: 0,
40
- interior: {
41
- X3: [
42
- {
43
- AccountId32: {
44
- id: u8aToHex(decodeAddress(who, false, 42)),
45
- network: null,
46
- },
47
- },
48
- {
49
- AccountKey20: {
50
- network: {
51
- Ethereum: {
52
- chainId: params.destination,
53
- },
54
- },
55
- key: params.recipient,
56
- },
57
- },
58
- {
59
- GeneralIndex: params.timeout,
60
- },
61
- ],
62
- },
63
- },
64
- };
65
- const assets = {
66
- V3: [
67
- {
68
- id: {
69
- Concrete: {
70
- parents: 0,
71
- interior: "Here",
72
- },
73
- },
74
- fun: {
75
- Fungible: parseUnits(params.amount.toString(), DECIMALS),
76
- },
77
- },
78
- ],
79
- };
80
- const feeAssetItem = 0;
81
- const weightLimit = "Unlimited";
82
- const tx = relayApi.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
83
- const finalizedHash = await hyperbridge.rpc.chain.getFinalizedHead();
84
- const finalizedHead = await hyperbridge.rpc.chain.getHeader(finalizedHash);
85
- const hyperbridgeBlock = finalizedHead.number.toNumber();
86
- if (!hyperbridgeBlock)
87
- throw new Error("Error getting Hyperbridge Block");
88
- let unsubscribe;
89
- const stream = new ReadableStream({
90
- async start(controller) {
91
- unsubscribe = await tx.signAndSend(who, options, async (result) => {
92
- try {
93
- const { status, dispatchError, txHash } = result;
94
- // @ts-expect-error Type Mismatch
95
- const events = result.events;
96
- if (dispatchError) {
97
- controller.enqueue({
98
- kind: "Error",
99
- error: `Error watching extrinsic: ${dispatchError.toString()}`,
100
- });
101
- return;
102
- }
103
- if (status.isReady) {
104
- // send tx hash as soon as it is available
105
- controller.enqueue({
106
- kind: "Ready",
107
- transaction_hash: txHash.toHex(),
108
- });
109
- }
110
- else if (status.isInBlock) {
111
- await relayApi.rpc.chain.getHeader(status.asInBlock);
112
- const { commitment, block_number } = await watchForRequestCommitment(hyperbridge, who, params, hyperbridgeBlock);
113
- // send block number once available
114
- controller.enqueue({
115
- kind: "Dispatched",
116
- block_number: block_number,
117
- transaction_hash: txHash.toHex(),
118
- commitment,
119
- events: events,
120
- });
121
- }
122
- if (status.isFinalized) {
123
- controller.enqueue({
124
- kind: "Finalized",
125
- transaction_hash: txHash.toHex(),
126
- events: events,
127
- });
128
- }
129
- }
130
- catch (err) {
131
- controller.enqueue({
132
- kind: "Error",
133
- error: String(err),
134
- });
135
- }
136
- });
137
- },
138
- pull() {
139
- // We don't really need a pull in this example
140
- },
141
- cancel() {
142
- // This is called if the reader cancels,
143
- unsubscribe?.();
144
- },
145
- }, {
146
- highWaterMark: 3,
147
- size: () => 1,
148
- });
149
- return stream;
150
- }
151
- // Watch for the request to be dispatched from hyperbridge
152
- async function watchForRequestCommitment(hyperbridge, who, params, start_block) {
153
- return new Promise((resolve, reject) => {
154
- let blockCount = 0;
155
- let last_block = start_block;
156
- let unsubscribeHyperbridgeEvents = () => { };
157
- const handleLatestHeader = async (lastHeader) => {
158
- const finalized = lastHeader.number.toNumber();
159
- blockCount += Math.max(finalized - last_block, 1);
160
- for (let block_number = last_block; block_number <= finalized; block_number++) {
161
- const block_hash = await hyperbridge.rpc.chain.getBlockHash(block_number);
162
- // just to be safe, query events at this specific hash
163
- const apiAt = await hyperbridge.at(block_hash);
164
- const events = (await apiAt.query.system.events());
165
- for (const record of events) {
166
- const { event } = record;
167
- if (event.section === "xcmGateway" && event.method === "AssetTeleported") {
168
- const commitment = extractCommitmentHashFromEvent({
169
- record,
170
- from: who,
171
- params,
172
- });
173
- if (commitment) {
174
- unsubscribeHyperbridgeEvents?.();
175
- resolve({
176
- commitment,
177
- block_hash: block_hash.toHex(),
178
- block_number: BigInt(block_number),
179
- });
180
- }
181
- }
182
- }
183
- }
184
- last_block = finalized + 1;
185
- if (blockCount >= 30) {
186
- unsubscribeHyperbridgeEvents?.();
187
- reject(new Error("No commitment received"));
188
- }
189
- };
190
- hyperbridge.rpc.chain
191
- .subscribeFinalizedHeads((header) => {
192
- // @ts-expect-error Issue referencing type
193
- return handleLatestHeader(header);
194
- })
195
- .then((unsubscribe) => {
196
- unsubscribeHyperbridgeEvents = unsubscribe;
197
- })
198
- .catch(reject);
199
- });
200
- }
201
- /**
202
- * Extracts the commitment hash from the event data if the event data
203
- * matches the expected data
204
- */
205
- export function extractCommitmentHashFromEvent({ record, from: who, params, }) {
206
- const { event } = record;
207
- const [from, to, _amount, dest, commitment] = event.data;
208
- const decodedFrom = u8aToHex(decodeAddress(from.toString(), false));
209
- const decodedWho = u8aToHex(decodeAddress(who, false));
210
- const isExpectedEvent = decodedFrom === decodedWho &&
211
- to.toString().toLowerCase() === params.recipient.toLowerCase() &&
212
- dest.toString().includes(params.destination?.toString());
213
- if (!isExpectedEvent) {
214
- throw new Error("Error extracting commitment. Data mismatch");
215
- }
216
- return commitment.toString();
217
- }
218
- //# sourceMappingURL=xcmGateway.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"xcmGateway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K,UAAU;QAC1B,EAAE,CAAC,QAAQ,EAAE,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC,SAAS,CAAC,WAAW,EAAE;QAC9D,IAAI,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,EAAE,CAAC,CAAA;IAEzD,IAAI,CAAC,eAAe,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;IAC9D,CAAC;IAED,OAAO,UAAU,CAAC,QAAQ,EAAe,CAAA;AAC1C,CAAC"}
package/dist/utils.d.ts DELETED
@@ -1,57 +0,0 @@
1
- import { HexString, IPostRequest, RequestStatus, TimeoutStatus } from "./types";
2
- export * from "./utils/mmr";
3
- export * from "./utils/substrate";
4
- export declare const DEFAULT_POLL_INTERVAL = 5000;
5
- /**
6
- * Sleeps for the specified number of milliseconds.
7
- * @param ms The number of milliseconds to sleep.
8
- */
9
- export declare function sleep(ms?: number): Promise<unknown>;
10
- /**
11
- * Checks if the given state machine ID represents an EVM chain.
12
- * @param stateMachineId The state machine ID to check.
13
- */
14
- export declare function isEvmChain(stateMachineId: string): boolean;
15
- /**
16
- * Checks if the given state machine ID represents a Substrate chain.
17
- * @param stateMachineId The state machine ID to check.
18
- */
19
- export declare function isSubstrateChain(stateMachineId: string): boolean;
20
- /**
21
- * Checks if the given string is a valid UTF-8 string.
22
- * @param str The string to check.
23
- */
24
- export declare function isValidUTF8(str: string): boolean;
25
- /**
26
- * Calculates the commitment hash for a post request.
27
- * @param post The post request to calculate the commitment hash for.
28
- * @returns The commitment hash.
29
- */
30
- export declare function postRequestCommitment(post: IPostRequest): HexString;
31
- /**
32
- ** Calculates the weight of a request status.
33
- * Used to determine the progression of a request through its lifecycle.
34
- * Higher weights represent more advanced states in the processing pipeline.
35
- * @returns A record mapping each RequestStatus to its corresponding weight value.
36
- */
37
- export declare const REQUEST_STATUS_WEIGHTS: Record<RequestStatus, number>;
38
- /**
39
- * Calculates the weight of a timeout status.
40
- * Used to determine the progression of a timeout through its lifecycle.
41
- * Higher weights represent more advanced states in the timeout processing.
42
- * @returns A record mapping each TimeoutStatus to its corresponding weight value.
43
- */
44
- export declare const TIMEOUT_STATUS_WEIGHTS: Record<TimeoutStatus, number>;
45
- /**
46
- * Combines both request and timeout status weights into a single mapping.
47
- * This provides a comprehensive view of all possible states a request can be in,
48
- * with higher weights representing more advanced states in either the normal
49
- * processing pipeline or the timeout handling process.
50
- *
51
- * The weights follow this progression:
52
- * 0-4: Normal request processing (SOURCE to DESTINATION)
53
- * 5-9: Timeout handling progression (PENDING_TIMEOUT to TIMED_OUT)
54
- *
55
- * @returns A record mapping each RequestStatus and TimeoutStatus to its corresponding weight value.
56
- */
57
- export declare const COMBINED_STATUS_WEIGHTS: Record<RequestStatus | TimeoutStatus, number>;
package/dist/utils.js DELETED
@@ -1,96 +0,0 @@
1
- import { RequestStatus, TimeoutStatus } from "./types/index.js";
2
- import { encodePacked, keccak256, toHex } from "viem";
3
- export * from "./utils/mmr.js";
4
- export * from "./utils/substrate.js";
5
- export const DEFAULT_POLL_INTERVAL = 5000;
6
- /**
7
- * Sleeps for the specified number of milliseconds.
8
- * @param ms The number of milliseconds to sleep.
9
- */
10
- export function sleep(ms) {
11
- return new Promise((resolve) => setTimeout(resolve, ms || DEFAULT_POLL_INTERVAL));
12
- }
13
- /**
14
- * Checks if the given state machine ID represents an EVM chain.
15
- * @param stateMachineId The state machine ID to check.
16
- */
17
- export function isEvmChain(stateMachineId) {
18
- return stateMachineId.startsWith("EVM");
19
- }
20
- /**
21
- * Checks if the given state machine ID represents a Substrate chain.
22
- * @param stateMachineId The state machine ID to check.
23
- */
24
- export function isSubstrateChain(stateMachineId) {
25
- return (stateMachineId.startsWith("POLKADOT") ||
26
- stateMachineId.startsWith("KUSAMA") ||
27
- stateMachineId.startsWith("SUBSTRATE"));
28
- }
29
- /**
30
- * Checks if the given string is a valid UTF-8 string.
31
- * @param str The string to check.
32
- */
33
- export function isValidUTF8(str) {
34
- return Buffer.from(str).toString("utf8") === str;
35
- }
36
- /**
37
- * Calculates the commitment hash for a post request.
38
- * @param post The post request to calculate the commitment hash for.
39
- * @returns The commitment hash.
40
- */
41
- export function postRequestCommitment(post) {
42
- return keccak256(encodePacked(["bytes", "bytes", "uint64", "uint64", "bytes", "bytes", "bytes"], [toHex(post.source), toHex(post.dest), post.nonce, post.timeoutTimestamp, post.from, post.to, post.body]));
43
- }
44
- /**
45
- ** Calculates the weight of a request status.
46
- * Used to determine the progression of a request through its lifecycle.
47
- * Higher weights represent more advanced states in the processing pipeline.
48
- * @returns A record mapping each RequestStatus to its corresponding weight value.
49
- */
50
- export const REQUEST_STATUS_WEIGHTS = {
51
- [RequestStatus.SOURCE]: 0,
52
- [RequestStatus.SOURCE_FINALIZED]: 1,
53
- [RequestStatus.HYPERBRIDGE_DELIVERED]: 2,
54
- [RequestStatus.HYPERBRIDGE_FINALIZED]: 3,
55
- [RequestStatus.DESTINATION]: 4,
56
- [RequestStatus.HYPERBRIDGE_TIMED_OUT]: 5,
57
- [RequestStatus.TIMED_OUT]: 6,
58
- };
59
- /**
60
- * Calculates the weight of a timeout status.
61
- * Used to determine the progression of a timeout through its lifecycle.
62
- * Higher weights represent more advanced states in the timeout processing.
63
- * @returns A record mapping each TimeoutStatus to its corresponding weight value.
64
- */
65
- export const TIMEOUT_STATUS_WEIGHTS = {
66
- [TimeoutStatus.PENDING_TIMEOUT]: 1,
67
- [TimeoutStatus.DESTINATION_FINALIZED_TIMEOUT]: 2,
68
- [TimeoutStatus.HYPERBRIDGE_TIMED_OUT]: 3,
69
- [TimeoutStatus.HYPERBRIDGE_FINALIZED_TIMEOUT]: 4,
70
- [TimeoutStatus.TIMED_OUT]: 5,
71
- };
72
- /**
73
- * Combines both request and timeout status weights into a single mapping.
74
- * This provides a comprehensive view of all possible states a request can be in,
75
- * with higher weights representing more advanced states in either the normal
76
- * processing pipeline or the timeout handling process.
77
- *
78
- * The weights follow this progression:
79
- * 0-4: Normal request processing (SOURCE to DESTINATION)
80
- * 5-9: Timeout handling progression (PENDING_TIMEOUT to TIMED_OUT)
81
- *
82
- * @returns A record mapping each RequestStatus and TimeoutStatus to its corresponding weight value.
83
- */
84
- export const COMBINED_STATUS_WEIGHTS = {
85
- [RequestStatus.SOURCE]: 0,
86
- [RequestStatus.SOURCE_FINALIZED]: 1,
87
- [RequestStatus.HYPERBRIDGE_DELIVERED]: 2,
88
- [RequestStatus.HYPERBRIDGE_FINALIZED]: 3,
89
- [RequestStatus.DESTINATION]: 4,
90
- [TimeoutStatus.PENDING_TIMEOUT]: 5,
91
- [TimeoutStatus.DESTINATION_FINALIZED_TIMEOUT]: 6,
92
- [TimeoutStatus.HYPERBRIDGE_TIMED_OUT]: 7,
93
- [TimeoutStatus.HYPERBRIDGE_FINALIZED_TIMEOUT]: 8,
94
- [TimeoutStatus.TIMED_OUT]: 9,
95
- };
96
- //# sourceMappingURL=utils.js.map
package/dist/utils.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,aAAa,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC/E,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,MAAM,CAAA;AAErD,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AAEjC,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAK,CAAA;AAE1C;;;GAGG;AACH,MAAM,UAAU,KAAK,CAAC,EAAW;IAChC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,IAAI,qBAAqB,CAAC,CAAC,CAAA;AAClF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,cAAsB;IAChD,OAAO,cAAc,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;AACxC,CAAC;AAED;;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