@hyperbridge/sdk 1.4.7-rc0000000001 → 1.4.7

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.
@@ -1104,6 +1104,15 @@ declare class SubstrateChain implements IChain {
1104
1104
  * @returns {IStateMachine} The corresponding enum value.
1105
1105
  */
1106
1106
  declare function convertStateMachineIdToEnum(id: string): IStateMachine;
1107
+ /**
1108
+ * Converts a state machine enum representation to a string.
1109
+ * @param {IStateMachine} stateMachine - The state machine enum object.
1110
+ * @returns {string} The state machine ID string like "EVM-97" or "SUBSTRATE-cere".
1111
+ */
1112
+ declare function convertStateMachineEnumToString(stateMachine: {
1113
+ tag: string;
1114
+ value: number | number[];
1115
+ }): string;
1107
1116
  /**
1108
1117
  * Converts a stateId object back to the state_id format used by the RPC.
1109
1118
  * @param stateId - The stateId object from StateMachineIdParams
@@ -1115,6 +1124,73 @@ declare function convertStateIdToStateMachineId(stateId: {
1115
1124
  Polkadot?: number;
1116
1125
  Kusama?: number;
1117
1126
  }): string;
1127
+ /**
1128
+ * Converts an IGetRequest object to a codec representation.
1129
+ * @param {IGetRequest} request - The IGetRequest object.
1130
+ * @returns The codec representation of the request.
1131
+ */
1132
+ declare function convertIGetRequestToCodec(request: IGetRequest): {
1133
+ readonly source: IStateMachine;
1134
+ readonly dest: IStateMachine;
1135
+ readonly from: number[];
1136
+ readonly nonce: bigint;
1137
+ readonly keys: number[][];
1138
+ readonly context: number[];
1139
+ readonly timeoutTimestamp: bigint;
1140
+ readonly height: bigint;
1141
+ };
1142
+ /**
1143
+ * Convert codec representation back to IGetRequest
1144
+ */
1145
+ declare function convertCodecToIGetRequest(codec: {
1146
+ source: {
1147
+ tag: string;
1148
+ value: number | number[];
1149
+ };
1150
+ dest: {
1151
+ tag: string;
1152
+ value: number | number[];
1153
+ };
1154
+ from: number[];
1155
+ nonce: bigint;
1156
+ keys: number[][];
1157
+ height: bigint;
1158
+ context: number[];
1159
+ timeoutTimestamp: bigint;
1160
+ }): IGetRequest;
1161
+ /**
1162
+ * Converts an IProof object to a codec representation.
1163
+ * @param {IProof} proof - The IProof object.
1164
+ * @returns The codec representation of the proof.
1165
+ */
1166
+ declare function convertIProofToCodec(proof: IProof): {
1167
+ readonly height: {
1168
+ readonly height: bigint;
1169
+ readonly id: {
1170
+ readonly consensusStateId: number[];
1171
+ readonly id: IStateMachine;
1172
+ };
1173
+ };
1174
+ readonly proof: number[];
1175
+ };
1176
+ /**
1177
+ * Converts a codec representation back to an IProof object.
1178
+ * @param {any} codec - The codec representation of the proof.
1179
+ * @returns {IProof} The IProof object.
1180
+ */
1181
+ declare function convertCodecToIProof(codec: {
1182
+ height: {
1183
+ height: bigint;
1184
+ id: {
1185
+ consensusStateId: number[];
1186
+ id: {
1187
+ tag: string;
1188
+ value: number | number[];
1189
+ };
1190
+ };
1191
+ };
1192
+ proof: number[];
1193
+ }): IProof;
1118
1194
  declare function encodeISMPMessage(message: IIsmpMessage): Uint8Array;
1119
1195
 
1120
1196
  /**
@@ -3399,4 +3475,4 @@ declare const popularTokens: {
3399
3475
  "EVM-130": string[];
3400
3476
  };
3401
3477
 
3402
- export { ADDRESS_ZERO, type AllStatusKey, type AssetTeleported, type AssetTeleportedResponse, type BlockMetadata, type CancelOptions, type ChainConfig, ChainConfigService, type ChainId, Chains, type ClientConfig, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DUMMY_PRIVATE_KEY, type DecodedOrderPlacedLog, type DecodedPostRequestEvent, type DecodedPostResponseEvent, type DispatchGet, type DispatchPost, ERC20Method, type EstimateGasCallData, EvmChain, type EvmChainParams, type ExecutionResult, type FillOptions, type FillerConfig, type GetRequestResponse, type GetRequestWithStatus, type GetResponseByRequestIdResponse, type GetResponseStorageValues, type HexString, type HostParams, HyperClientStatus, type HyperbridgeTxEvents, type IChain, type IConfig, type IEvmConfig, type IGetRequest, type IGetRequestMessage, type IGetResponse, type IGetResponseMessage, type IHyperbridgeConfig, type IIsmpMessage, type IMessage, type IPostRequest, type IPostResponse, type IProof, type IRequestMessage, type ISubstrateConfig, type ITimeoutPostRequestMessage, IndexerClient, type IndexerQueryClient, IntentGateway, type IntentGatewayParams, type IsmpRequest, type NewDeployment, type Order, type OrderResponse, OrderStatus, type OrderStatusMetadata, type OrderWithStatus, type Params, type PaymentInfo, type PostRequestStatus, type PostRequestTimeoutStatus, type PostRequestWithStatus, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, type RequestBody, type RequestCommitment, RequestKind, type RequestResponse, RequestStatus, type RequestStatusKey, type RequestStatusWithMetadata, type ResponseCommitmentWithValues, type RetryConfig, STATE_COMMITMENTS_SLOT, type StateMachineHeight, type StateMachineIdParams, type StateMachineResponse, type StateMachineUpdate, type StorageFacade, SubstrateChain, TESTNET_CHAINS, TeleportStatus, TimeoutStatus, type TimeoutStatusKey, type TokenGatewayAssetTeleportedResponse, type TokenGatewayAssetTeleportedWithStatus, type TokenInfo, type TokenPrice, type TokenPricesResponse, type TokenRegistry, type TokenRegistryResponse, type Transaction, USE_ETHERSCAN_CHAINS, WrappedNativeDecimals, type XcmGatewayParams, __test, addresses, adjustFeeDecimals, assets, bytes20ToBytes32, bytes32ToBytes20, chainIds, coingeckoIds, consensusStateIds, constructRedeemEscrowRequestBody, convertStateIdToStateMachineId, convertStateMachineIdToEnum, createChain, createEvmChain, createIndexerClient, createQueryClient, createRpcUrls, encodeISMPMessage, estimateGasForPost, fetchPrice, generateRootWithProof, getChain, getGasPriceFromEtherscan, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, hexToString, maxBigInt, orderCommitment, popularTokens, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, requestCommitmentKey, retryPromise, teleport, teleportDot, viemChains };
3478
+ export { ADDRESS_ZERO, type AllStatusKey, type AssetTeleported, type AssetTeleportedResponse, type BlockMetadata, type CancelOptions, type ChainConfig, ChainConfigService, type ChainId, Chains, type ClientConfig, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DUMMY_PRIVATE_KEY, type DecodedOrderPlacedLog, type DecodedPostRequestEvent, type DecodedPostResponseEvent, type DispatchGet, type DispatchPost, ERC20Method, type EstimateGasCallData, EvmChain, type EvmChainParams, type ExecutionResult, type FillOptions, type FillerConfig, type GetRequestResponse, type GetRequestWithStatus, type GetResponseByRequestIdResponse, type GetResponseStorageValues, type HexString, type HostParams, HyperClientStatus, type HyperbridgeTxEvents, type IChain, type IConfig, type IEvmConfig, type IGetRequest, type IGetRequestMessage, type IGetResponse, type IGetResponseMessage, type IHyperbridgeConfig, type IIsmpMessage, type IMessage, type IPostRequest, type IPostResponse, type IProof, type IRequestMessage, type ISubstrateConfig, type ITimeoutPostRequestMessage, IndexerClient, type IndexerQueryClient, IntentGateway, type IntentGatewayParams, type IsmpRequest, type NewDeployment, type Order, type OrderResponse, OrderStatus, type OrderStatusMetadata, type OrderWithStatus, type Params, type PaymentInfo, type PostRequestStatus, type PostRequestTimeoutStatus, type PostRequestWithStatus, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, type RequestBody, type RequestCommitment, RequestKind, type RequestResponse, RequestStatus, type RequestStatusKey, type RequestStatusWithMetadata, type ResponseCommitmentWithValues, type RetryConfig, STATE_COMMITMENTS_SLOT, type StateMachineHeight, type StateMachineIdParams, type StateMachineResponse, type StateMachineUpdate, type StorageFacade, SubstrateChain, TESTNET_CHAINS, TeleportStatus, TimeoutStatus, type TimeoutStatusKey, type TokenGatewayAssetTeleportedResponse, type TokenGatewayAssetTeleportedWithStatus, type TokenInfo, type TokenPrice, type TokenPricesResponse, type TokenRegistry, type TokenRegistryResponse, type Transaction, USE_ETHERSCAN_CHAINS, WrappedNativeDecimals, type XcmGatewayParams, __test, addresses, adjustFeeDecimals, assets, bytes20ToBytes32, bytes32ToBytes20, chainIds, coingeckoIds, consensusStateIds, constructRedeemEscrowRequestBody, convertCodecToIGetRequest, convertCodecToIProof, convertIGetRequestToCodec, convertIProofToCodec, convertStateIdToStateMachineId, convertStateMachineEnumToString, convertStateMachineIdToEnum, createChain, createEvmChain, createIndexerClient, createQueryClient, createRpcUrls, encodeISMPMessage, estimateGasForPost, fetchPrice, generateRootWithProof, getChain, getGasPriceFromEtherscan, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, hexToString, maxBigInt, orderCommitment, popularTokens, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, requestCommitmentKey, retryPromise, teleport, teleportDot, viemChains };
@@ -13,7 +13,6 @@ import { WsProvider, ApiPromise } from '@polkadot/api';
13
13
  import { keccakAsU8a, decodeAddress, keccakAsHex, xxhashAsU8a } from '@polkadot/util-crypto';
14
14
  import { GraphQLClient } from 'graphql-request';
15
15
  import { Decimal } from 'decimal.js';
16
- import stringify from 'safe-stable-stringify';
17
16
  import { createStorage } from 'unstorage';
18
17
  import inMemoryDriver from 'unstorage/drivers/memory';
19
18
  import fsDriver from 'unstorage/drivers/fs';
@@ -6561,6 +6560,17 @@ function convertStateMachineIdToEnum(id) {
6561
6560
  }
6562
6561
  return { tag, value };
6563
6562
  }
6563
+ function convertStateMachineEnumToString(stateMachine) {
6564
+ const tag = stateMachine.tag.toUpperCase();
6565
+ if (tag === "EVM" || tag === "POLKADOT" || tag === "KUSAMA") {
6566
+ return `${tag}-${stateMachine.value}`;
6567
+ } else {
6568
+ const bytes = new Uint8Array(stateMachine.value);
6569
+ const decoder = new TextDecoder("utf-8");
6570
+ const decoded = decoder.decode(bytes);
6571
+ return `${tag}-${decoded}`;
6572
+ }
6573
+ }
6564
6574
  function convertStateIdToStateMachineId(stateId) {
6565
6575
  switch (true) {
6566
6576
  case stateId.Evm !== void 0:
@@ -6605,6 +6615,41 @@ function convertIGetRequestToCodec(request) {
6605
6615
  height: request.height
6606
6616
  };
6607
6617
  }
6618
+ function convertCodecToIGetRequest(codec) {
6619
+ return {
6620
+ source: convertStateMachineEnumToString(codec.source),
6621
+ dest: convertStateMachineEnumToString(codec.dest),
6622
+ from: bytesToHex(new Uint8Array(codec.from)),
6623
+ nonce: codec.nonce,
6624
+ keys: codec.keys.map((key) => bytesToHex(new Uint8Array(key))),
6625
+ height: codec.height,
6626
+ context: bytesToHex(new Uint8Array(codec.context)),
6627
+ timeoutTimestamp: codec.timeoutTimestamp
6628
+ };
6629
+ }
6630
+ function convertIProofToCodec(proof) {
6631
+ return {
6632
+ height: {
6633
+ height: proof.height,
6634
+ id: {
6635
+ consensusStateId: Array.from(toBytes(proof.consensusStateId)),
6636
+ id: convertStateMachineIdToEnum(proof.stateMachine)
6637
+ }
6638
+ },
6639
+ proof: Array.from(hexToBytes(proof.proof))
6640
+ };
6641
+ }
6642
+ function convertCodecToIProof(codec) {
6643
+ const consensusStateIdBytes = new Uint8Array(codec.height.id.consensusStateId);
6644
+ const decoder = new TextDecoder("utf-8");
6645
+ const consensusStateId = decoder.decode(consensusStateIdBytes);
6646
+ return {
6647
+ height: codec.height.height,
6648
+ stateMachine: convertStateMachineEnumToString(codec.height.id.id),
6649
+ consensusStateId,
6650
+ proof: bytesToHex(new Uint8Array(codec.proof))
6651
+ };
6652
+ }
6608
6653
  function encodeISMPMessage(message) {
6609
6654
  try {
6610
6655
  return match(message).with({ kind: "PostRequest" }, (message2) => {
@@ -10005,35 +10050,26 @@ var IntentGateway_default = { ABI: ABI4 };
10005
10050
  var loadDriver = ({ options }) => {
10006
10051
  return fsDriver({ base: options?.basePath ?? "./.hyperbridge-cache" });
10007
10052
  };
10008
-
10009
- // src/storage/index.ts
10010
- var convertBigIntsToSerializable = (value) => {
10011
- if (value === null || value === void 0) return value;
10012
- if (typeof value === "bigint") return { __type: "bigint", value: value.toString() };
10013
- if (Array.isArray(value)) return value.map(convertBigIntsToSerializable);
10014
- if (typeof value === "object") {
10015
- return Object.entries(value).reduce((acc, [k, v]) => {
10016
- acc[k] = convertBigIntsToSerializable(v);
10017
- return acc;
10018
- }, {});
10019
- }
10020
- return value;
10021
- };
10022
- var convertSerializableToBigInts = (value) => {
10023
- if (value === null || value === void 0) return value;
10024
- if (Array.isArray(value)) return value.map(convertSerializableToBigInts);
10025
- if (typeof value === "object" && value !== null) {
10026
- const obj = value;
10027
- if (obj.__type === "bigint" && typeof obj.value === "string") {
10028
- return BigInt(obj.value);
10029
- }
10030
- return Object.entries(obj).reduce((acc, [k, v]) => {
10031
- acc[k] = convertSerializableToBigInts(v);
10032
- return acc;
10033
- }, {});
10034
- }
10035
- return value;
10036
- };
10053
+ function encodeIGetRequest(request) {
10054
+ const codec = convertIGetRequestToCodec(request);
10055
+ const encoded = GetRequest.enc(codec);
10056
+ return bytesToHex(encoded);
10057
+ }
10058
+ function decodeIGetRequest(hex) {
10059
+ const bytes = hexToBytes(hex);
10060
+ const decoded = GetRequest.dec(bytes);
10061
+ return convertCodecToIGetRequest(decoded);
10062
+ }
10063
+ function encodeIProof(proof) {
10064
+ const codec = convertIProofToCodec(proof);
10065
+ const encoded = Proof.enc(codec);
10066
+ return bytesToHex(encoded);
10067
+ }
10068
+ function decodeIProof(hex) {
10069
+ const bytes = hexToBytes(hex);
10070
+ const decoded = Proof.dec(bytes);
10071
+ return convertCodecToIProof(decoded);
10072
+ }
10037
10073
  var detectEnvironment = () => {
10038
10074
  if (typeof process !== "undefined" && !!process.versions?.node) return "node";
10039
10075
  if (typeof globalThis !== "undefined" && "localStorage" in globalThis) return "localstorage";
@@ -10042,24 +10078,36 @@ var detectEnvironment = () => {
10042
10078
  };
10043
10079
  function createCancellationStorage(options = {}) {
10044
10080
  options.env ?? detectEnvironment();
10045
- const driver = loadDriver({ options }) ?? inMemoryDriver;
10081
+ const driver = loadDriver({ options }) ?? inMemoryDriver();
10046
10082
  const baseStorage = createStorage({ driver });
10047
10083
  const getItem = async (key2) => {
10048
10084
  const value = await baseStorage.getItem(key2);
10049
10085
  if (!value) return null;
10050
- try {
10051
- return convertSerializableToBigInts(JSON.parse(value));
10052
- } catch {
10053
- return value;
10086
+ if (key2.includes("getRequest")) {
10087
+ const decoded = decodeIGetRequest(value);
10088
+ return decoded;
10054
10089
  }
10090
+ if (key2.includes("Proof")) {
10091
+ const decoded = decodeIProof(value);
10092
+ return decoded;
10093
+ }
10094
+ throw new Error(`Unknown storage key type: ${key2}`);
10055
10095
  };
10056
10096
  const setItem = async (key2, value) => {
10057
- const serializable = convertBigIntsToSerializable(value);
10058
- const stringified = stringify(serializable) ?? "null";
10059
- await baseStorage.setItem(key2, stringified);
10097
+ if (key2.includes("getRequest") && value && typeof value === "object") {
10098
+ const encoded = encodeIGetRequest(value);
10099
+ await baseStorage.setItem(key2, encoded);
10100
+ return;
10101
+ }
10102
+ if (key2.includes("Proof") && value && typeof value === "object") {
10103
+ const encoded = encodeIProof(value);
10104
+ await baseStorage.setItem(key2, encoded);
10105
+ return;
10106
+ }
10107
+ throw new Error(`Unknown storage key type: ${key2}`);
10060
10108
  };
10061
10109
  const removeItem = async (key2) => {
10062
- baseStorage.removeItem(key2);
10110
+ await baseStorage.removeItem(key2);
10063
10111
  };
10064
10112
  return Object.freeze({
10065
10113
  ...baseStorage,
@@ -12836,6 +12884,8 @@ var IntentGateway = class {
12836
12884
  if (!destIProof) {
12837
12885
  destIProof = yield* this.fetchDestinationProof(order, indexerClient);
12838
12886
  await this.storage.setItem(STORAGE_KEYS.destProof(orderId), destIProof);
12887
+ } else {
12888
+ yield { status: "DESTINATION_FINALIZED", data: { proof: destIProof } };
12839
12889
  }
12840
12890
  let getRequest = await this.storage.getItem(STORAGE_KEYS.getRequest(orderId));
12841
12891
  if (!getRequest) {
@@ -13288,6 +13338,6 @@ async function teleportDot(param_) {
13288
13338
  return stream;
13289
13339
  }
13290
13340
 
13291
- export { ADDRESS_ZERO, ChainConfigService, Chains, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DUMMY_PRIVATE_KEY, ERC20Method, EvmChain, HyperClientStatus, IndexerClient, IntentGateway, OrderStatus, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, RequestKind, RequestStatus, STATE_COMMITMENTS_SLOT, SubstrateChain, TESTNET_CHAINS, TeleportStatus, TimeoutStatus, USE_ETHERSCAN_CHAINS, WrappedNativeDecimals, __test, addresses, adjustFeeDecimals, assets, bytes20ToBytes32, bytes32ToBytes20, chainIds, coingeckoIds, consensusStateIds, constructRedeemEscrowRequestBody, convertStateIdToStateMachineId, convertStateMachineIdToEnum, createChain, createEvmChain, createIndexerClient, createQueryClient, createRpcUrls, encodeISMPMessage, estimateGasForPost, fetchPrice, generateRootWithProof, getChain, getGasPriceFromEtherscan, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, hexToString, maxBigInt, orderCommitment, popularTokens, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, requestCommitmentKey, retryPromise, teleport, teleportDot, viemChains };
13341
+ export { ADDRESS_ZERO, ChainConfigService, Chains, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DUMMY_PRIVATE_KEY, ERC20Method, EvmChain, HyperClientStatus, IndexerClient, IntentGateway, OrderStatus, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, RequestKind, RequestStatus, STATE_COMMITMENTS_SLOT, SubstrateChain, TESTNET_CHAINS, TeleportStatus, TimeoutStatus, USE_ETHERSCAN_CHAINS, WrappedNativeDecimals, __test, addresses, adjustFeeDecimals, assets, bytes20ToBytes32, bytes32ToBytes20, chainIds, coingeckoIds, consensusStateIds, constructRedeemEscrowRequestBody, convertCodecToIGetRequest, convertCodecToIProof, convertIGetRequestToCodec, convertIProofToCodec, convertStateIdToStateMachineId, convertStateMachineEnumToString, convertStateMachineIdToEnum, createChain, createEvmChain, createIndexerClient, createQueryClient, createRpcUrls, encodeISMPMessage, estimateGasForPost, fetchPrice, generateRootWithProof, getChain, getGasPriceFromEtherscan, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, hexToString, maxBigInt, orderCommitment, popularTokens, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, requestCommitmentKey, retryPromise, teleport, teleportDot, viemChains };
13292
13342
  //# sourceMappingURL=index.js.map
13293
13343
  //# sourceMappingURL=index.js.map