@defuse-protocol/intents-sdk 0.30.1 → 0.31.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.
package/dist/index.cjs CHANGED
@@ -6,6 +6,7 @@ const require_bridge_name_enum = require('./src/constants/bridge-name-enum.cjs')
6
6
  const require_error = require('./src/bridges/direct-bridge/error.cjs');
7
7
  const require_error$1 = require('./src/bridges/hot-bridge/error.cjs');
8
8
  const require_error$2 = require('./src/bridges/omni-bridge/error.cjs');
9
+ const require_intent_hash = require('./src/intents/intent-hash.cjs');
9
10
  const require_expirable_nonce = require('./src/intents/expirable-nonce.cjs');
10
11
  const require_route_config_factory = require('./src/lib/route-config-factory.cjs');
11
12
  const require_intent_payload_builder = require('./src/intents/intent-payload-builder.cjs');
@@ -106,6 +107,7 @@ Object.defineProperty(exports, 'VersionedNonceBuilder', {
106
107
  return require_expirable_nonce.VersionedNonceBuilder;
107
108
  }
108
109
  });
110
+ exports.computeIntentHash = require_intent_hash.computeIntentHash;
109
111
  exports.createDefaultRoute = require_route_config_factory.createDefaultRoute;
110
112
  exports.createHotBridgeRoute = require_route_config_factory.createHotBridgeRoute;
111
113
  exports.createIntentSignerNEP413 = require_factories.createIntentSignerNEP413;
package/dist/index.d.cts CHANGED
@@ -14,5 +14,6 @@ import { FeeExceedsAmountError, FeeExceedsAmountErrorType, MinWithdrawalAmountEr
14
14
  import { DestinationExplicitNearAccountDoesntExistError, DestinationExplicitNearAccountDoesntExistErrorType } from "./src/bridges/direct-bridge/error.cjs";
15
15
  import { HotWithdrawalCancelledError, HotWithdrawalCancelledErrorType, HotWithdrawalNotFoundError, HotWithdrawalNotFoundErrorType, HotWithdrawalPendingError, HotWithdrawalPendingErrorType } from "./src/bridges/hot-bridge/error.cjs";
16
16
  import { FailedToFetchFeeError, FailedToFetchFeeErrorType, IntentsNearOmniAvailableBalanceTooLowError, IntentsNearOmniAvailableBalanceTooLowErrorType, OmniTokenNormalisationCheckError, OmniTokenNormalisationCheckErrorType, OmniTransferDestinationChainHashNotFoundError, OmniTransferDestinationChainHashNotFoundErrorType, OmniTransferNotFoundError, OmniTransferNotFoundErrorType, TokenNotFoundInDestinationChainError, TokenNotFoundInDestinationChainErrorType } from "./src/bridges/omni-bridge/error.cjs";
17
+ import { computeIntentHash } from "./src/intents/intent-hash.cjs";
17
18
  import { AssertionError, AssertionErrorType, BaseError, BaseErrorType, HttpRequestError, HttpRequestErrorType, ILogger, IntentSettlementError, IntentSettlementErrorType, NearIntentsEnv, PoaWithdrawalInvariantError, PoaWithdrawalInvariantErrorType, PoaWithdrawalNotFoundError, PoaWithdrawalNotFoundErrorType, PoaWithdrawalPendingError, PoaWithdrawalPendingErrorType, QuoteError, QuoteErrorType, RelayPublishError, RelayPublishErrorType, RetryOptions, RpcRequestError, RpcRequestErrorType, TimeoutError, TimeoutErrorType } from "@defuse-protocol/internal-utils";
18
- export { AssertionError, type AssertionErrorType, BaseError, type BaseErrorType, type BatchWithdrawalResult, BridgeNameEnum, type BridgeNameEnumValues, type Chain, Chains, DestinationExplicitNearAccountDoesntExistError, type DestinationExplicitNearAccountDoesntExistErrorType, FailedToFetchFeeError, type FailedToFetchFeeErrorType, type FeeEstimation, FeeExceedsAmountError, type FeeExceedsAmountErrorType, type HotBridgeRouteConfig, HotWithdrawalCancelledError, type HotWithdrawalCancelledErrorType, HotWithdrawalNotFoundError, type HotWithdrawalNotFoundErrorType, HotWithdrawalPendingError, type HotWithdrawalPendingErrorType, HttpRequestError, type HttpRequestErrorType, type IIntentSigner, type ILogger, type IntentPayload, IntentPayloadBuilder, type IntentPayloadFactory, type IntentPrimitive, type IntentPublishResult, type IntentRelayParamsFactory, IntentSettlementError, type IntentSettlementErrorType, type IntentSettlementStatus, IntentsNearOmniAvailableBalanceTooLowError, type IntentsNearOmniAvailableBalanceTooLowErrorType, IntentsSDK, type IntentsSDKConfig, type InternalTransferRouteConfig, MinWithdrawalAmountError, type MinWithdrawalAmountErrorType, type MultiPayload, type NearIntentsEnv, type NearTxInfo, type NearWithdrawalRouteConfig, type OmniBridgeRouteConfig, OmniTokenNormalisationCheckError, type OmniTokenNormalisationCheckErrorType, OmniTransferDestinationChainHashNotFoundError, type OmniTransferDestinationChainHashNotFoundErrorType, OmniTransferNotFoundError, type OmniTransferNotFoundErrorType, type OnBeforePublishIntentHook, type ParsedAssetInfo, type PoaBridgeRouteConfig, PoaWithdrawalInvariantError, type PoaWithdrawalInvariantErrorType, PoaWithdrawalNotFoundError, type PoaWithdrawalNotFoundErrorType, PoaWithdrawalPendingError, type PoaWithdrawalPendingErrorType, type ProcessWithdrawalArgs, QuoteError, type QuoteErrorType, RelayPublishError, type RelayPublishErrorType, type RetryOptions, type RouteConfig, RouteEnum, type RouteEnumValues, RpcRequestError, type RpcRequestErrorType, type SignAndSendArgs, type SignAndSendWithdrawalArgs, type SignedIntentsComposition, TimeoutError, type TimeoutErrorType, TokenNotFoundInDestinationChainError, type TokenNotFoundInDestinationChainErrorType, TrustlineNotFoundError, type TrustlineNotFoundErrorType, type TxInfo, type TxNoInfo, UnsupportedAssetIdError, type UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, type UnsupportedDestinationMemoErrorType, VersionedNonceBuilder, type VirtualChainRouteConfig, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
19
+ export { AssertionError, type AssertionErrorType, BaseError, type BaseErrorType, type BatchWithdrawalResult, BridgeNameEnum, type BridgeNameEnumValues, type Chain, Chains, DestinationExplicitNearAccountDoesntExistError, type DestinationExplicitNearAccountDoesntExistErrorType, FailedToFetchFeeError, type FailedToFetchFeeErrorType, type FeeEstimation, FeeExceedsAmountError, type FeeExceedsAmountErrorType, type HotBridgeRouteConfig, HotWithdrawalCancelledError, type HotWithdrawalCancelledErrorType, HotWithdrawalNotFoundError, type HotWithdrawalNotFoundErrorType, HotWithdrawalPendingError, type HotWithdrawalPendingErrorType, HttpRequestError, type HttpRequestErrorType, type IIntentSigner, type ILogger, type IntentPayload, IntentPayloadBuilder, type IntentPayloadFactory, type IntentPrimitive, type IntentPublishResult, type IntentRelayParamsFactory, IntentSettlementError, type IntentSettlementErrorType, type IntentSettlementStatus, IntentsNearOmniAvailableBalanceTooLowError, type IntentsNearOmniAvailableBalanceTooLowErrorType, IntentsSDK, type IntentsSDKConfig, type InternalTransferRouteConfig, MinWithdrawalAmountError, type MinWithdrawalAmountErrorType, type MultiPayload, type NearIntentsEnv, type NearTxInfo, type NearWithdrawalRouteConfig, type OmniBridgeRouteConfig, OmniTokenNormalisationCheckError, type OmniTokenNormalisationCheckErrorType, OmniTransferDestinationChainHashNotFoundError, type OmniTransferDestinationChainHashNotFoundErrorType, OmniTransferNotFoundError, type OmniTransferNotFoundErrorType, type OnBeforePublishIntentHook, type ParsedAssetInfo, type PoaBridgeRouteConfig, PoaWithdrawalInvariantError, type PoaWithdrawalInvariantErrorType, PoaWithdrawalNotFoundError, type PoaWithdrawalNotFoundErrorType, PoaWithdrawalPendingError, type PoaWithdrawalPendingErrorType, type ProcessWithdrawalArgs, QuoteError, type QuoteErrorType, RelayPublishError, type RelayPublishErrorType, type RetryOptions, type RouteConfig, RouteEnum, type RouteEnumValues, RpcRequestError, type RpcRequestErrorType, type SignAndSendArgs, type SignAndSendWithdrawalArgs, type SignedIntentsComposition, TimeoutError, type TimeoutErrorType, TokenNotFoundInDestinationChainError, type TokenNotFoundInDestinationChainErrorType, TrustlineNotFoundError, type TrustlineNotFoundErrorType, type TxInfo, type TxNoInfo, UnsupportedAssetIdError, type UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, type UnsupportedDestinationMemoErrorType, VersionedNonceBuilder, type VirtualChainRouteConfig, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, computeIntentHash, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
package/dist/index.d.ts CHANGED
@@ -14,5 +14,6 @@ import { FeeExceedsAmountError, FeeExceedsAmountErrorType, MinWithdrawalAmountEr
14
14
  import { DestinationExplicitNearAccountDoesntExistError, DestinationExplicitNearAccountDoesntExistErrorType } from "./src/bridges/direct-bridge/error.js";
15
15
  import { HotWithdrawalCancelledError, HotWithdrawalCancelledErrorType, HotWithdrawalNotFoundError, HotWithdrawalNotFoundErrorType, HotWithdrawalPendingError, HotWithdrawalPendingErrorType } from "./src/bridges/hot-bridge/error.js";
16
16
  import { FailedToFetchFeeError, FailedToFetchFeeErrorType, IntentsNearOmniAvailableBalanceTooLowError, IntentsNearOmniAvailableBalanceTooLowErrorType, OmniTokenNormalisationCheckError, OmniTokenNormalisationCheckErrorType, OmniTransferDestinationChainHashNotFoundError, OmniTransferDestinationChainHashNotFoundErrorType, OmniTransferNotFoundError, OmniTransferNotFoundErrorType, TokenNotFoundInDestinationChainError, TokenNotFoundInDestinationChainErrorType } from "./src/bridges/omni-bridge/error.js";
17
+ import { computeIntentHash } from "./src/intents/intent-hash.js";
17
18
  import { AssertionError, AssertionErrorType, BaseError, BaseErrorType, HttpRequestError, HttpRequestErrorType, ILogger, IntentSettlementError, IntentSettlementErrorType, NearIntentsEnv, PoaWithdrawalInvariantError, PoaWithdrawalInvariantErrorType, PoaWithdrawalNotFoundError, PoaWithdrawalNotFoundErrorType, PoaWithdrawalPendingError, PoaWithdrawalPendingErrorType, QuoteError, QuoteErrorType, RelayPublishError, RelayPublishErrorType, RetryOptions, RpcRequestError, RpcRequestErrorType, TimeoutError, TimeoutErrorType } from "@defuse-protocol/internal-utils";
18
- export { AssertionError, type AssertionErrorType, BaseError, type BaseErrorType, type BatchWithdrawalResult, BridgeNameEnum, type BridgeNameEnumValues, type Chain, Chains, DestinationExplicitNearAccountDoesntExistError, type DestinationExplicitNearAccountDoesntExistErrorType, FailedToFetchFeeError, type FailedToFetchFeeErrorType, type FeeEstimation, FeeExceedsAmountError, type FeeExceedsAmountErrorType, type HotBridgeRouteConfig, HotWithdrawalCancelledError, type HotWithdrawalCancelledErrorType, HotWithdrawalNotFoundError, type HotWithdrawalNotFoundErrorType, HotWithdrawalPendingError, type HotWithdrawalPendingErrorType, HttpRequestError, type HttpRequestErrorType, type IIntentSigner, type ILogger, type IntentPayload, IntentPayloadBuilder, type IntentPayloadFactory, type IntentPrimitive, type IntentPublishResult, type IntentRelayParamsFactory, IntentSettlementError, type IntentSettlementErrorType, type IntentSettlementStatus, IntentsNearOmniAvailableBalanceTooLowError, type IntentsNearOmniAvailableBalanceTooLowErrorType, IntentsSDK, type IntentsSDKConfig, type InternalTransferRouteConfig, MinWithdrawalAmountError, type MinWithdrawalAmountErrorType, type MultiPayload, type NearIntentsEnv, type NearTxInfo, type NearWithdrawalRouteConfig, type OmniBridgeRouteConfig, OmniTokenNormalisationCheckError, type OmniTokenNormalisationCheckErrorType, OmniTransferDestinationChainHashNotFoundError, type OmniTransferDestinationChainHashNotFoundErrorType, OmniTransferNotFoundError, type OmniTransferNotFoundErrorType, type OnBeforePublishIntentHook, type ParsedAssetInfo, type PoaBridgeRouteConfig, PoaWithdrawalInvariantError, type PoaWithdrawalInvariantErrorType, PoaWithdrawalNotFoundError, type PoaWithdrawalNotFoundErrorType, PoaWithdrawalPendingError, type PoaWithdrawalPendingErrorType, type ProcessWithdrawalArgs, QuoteError, type QuoteErrorType, RelayPublishError, type RelayPublishErrorType, type RetryOptions, type RouteConfig, RouteEnum, type RouteEnumValues, RpcRequestError, type RpcRequestErrorType, type SignAndSendArgs, type SignAndSendWithdrawalArgs, type SignedIntentsComposition, TimeoutError, type TimeoutErrorType, TokenNotFoundInDestinationChainError, type TokenNotFoundInDestinationChainErrorType, TrustlineNotFoundError, type TrustlineNotFoundErrorType, type TxInfo, type TxNoInfo, UnsupportedAssetIdError, type UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, type UnsupportedDestinationMemoErrorType, VersionedNonceBuilder, type VirtualChainRouteConfig, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
19
+ export { AssertionError, type AssertionErrorType, BaseError, type BaseErrorType, type BatchWithdrawalResult, BridgeNameEnum, type BridgeNameEnumValues, type Chain, Chains, DestinationExplicitNearAccountDoesntExistError, type DestinationExplicitNearAccountDoesntExistErrorType, FailedToFetchFeeError, type FailedToFetchFeeErrorType, type FeeEstimation, FeeExceedsAmountError, type FeeExceedsAmountErrorType, type HotBridgeRouteConfig, HotWithdrawalCancelledError, type HotWithdrawalCancelledErrorType, HotWithdrawalNotFoundError, type HotWithdrawalNotFoundErrorType, HotWithdrawalPendingError, type HotWithdrawalPendingErrorType, HttpRequestError, type HttpRequestErrorType, type IIntentSigner, type ILogger, type IntentPayload, IntentPayloadBuilder, type IntentPayloadFactory, type IntentPrimitive, type IntentPublishResult, type IntentRelayParamsFactory, IntentSettlementError, type IntentSettlementErrorType, type IntentSettlementStatus, IntentsNearOmniAvailableBalanceTooLowError, type IntentsNearOmniAvailableBalanceTooLowErrorType, IntentsSDK, type IntentsSDKConfig, type InternalTransferRouteConfig, MinWithdrawalAmountError, type MinWithdrawalAmountErrorType, type MultiPayload, type NearIntentsEnv, type NearTxInfo, type NearWithdrawalRouteConfig, type OmniBridgeRouteConfig, OmniTokenNormalisationCheckError, type OmniTokenNormalisationCheckErrorType, OmniTransferDestinationChainHashNotFoundError, type OmniTransferDestinationChainHashNotFoundErrorType, OmniTransferNotFoundError, type OmniTransferNotFoundErrorType, type OnBeforePublishIntentHook, type ParsedAssetInfo, type PoaBridgeRouteConfig, PoaWithdrawalInvariantError, type PoaWithdrawalInvariantErrorType, PoaWithdrawalNotFoundError, type PoaWithdrawalNotFoundErrorType, PoaWithdrawalPendingError, type PoaWithdrawalPendingErrorType, type ProcessWithdrawalArgs, QuoteError, type QuoteErrorType, RelayPublishError, type RelayPublishErrorType, type RetryOptions, type RouteConfig, RouteEnum, type RouteEnumValues, RpcRequestError, type RpcRequestErrorType, type SignAndSendArgs, type SignAndSendWithdrawalArgs, type SignedIntentsComposition, TimeoutError, type TimeoutErrorType, TokenNotFoundInDestinationChainError, type TokenNotFoundInDestinationChainErrorType, TrustlineNotFoundError, type TrustlineNotFoundErrorType, type TxInfo, type TxNoInfo, UnsupportedAssetIdError, type UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, type UnsupportedDestinationMemoErrorType, VersionedNonceBuilder, type VirtualChainRouteConfig, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, computeIntentHash, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ import { BridgeNameEnum } from "./src/constants/bridge-name-enum.js";
5
5
  import { DestinationExplicitNearAccountDoesntExistError } from "./src/bridges/direct-bridge/error.js";
6
6
  import { HotWithdrawalCancelledError, HotWithdrawalNotFoundError, HotWithdrawalPendingError } from "./src/bridges/hot-bridge/error.js";
7
7
  import { FailedToFetchFeeError, IntentsNearOmniAvailableBalanceTooLowError, OmniTokenNormalisationCheckError, OmniTransferDestinationChainHashNotFoundError, OmniTransferNotFoundError, TokenNotFoundInDestinationChainError } from "./src/bridges/omni-bridge/error.js";
8
+ import { computeIntentHash } from "./src/intents/intent-hash.js";
8
9
  import { VersionedNonceBuilder } from "./src/intents/expirable-nonce.js";
9
10
  import { createDefaultRoute, createHotBridgeRoute, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute } from "./src/lib/route-config-factory.js";
10
11
  import { IntentPayloadBuilder } from "./src/intents/intent-payload-builder.js";
@@ -12,4 +13,4 @@ import { IntentsSDK } from "./src/sdk.js";
12
13
  import { createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem } from "./src/intents/intent-signer-impl/factories.js";
13
14
  import { AssertionError, BaseError, HttpRequestError, IntentSettlementError, PoaWithdrawalInvariantError, PoaWithdrawalNotFoundError, PoaWithdrawalPendingError, QuoteError, RelayPublishError, RpcRequestError, TimeoutError } from "@defuse-protocol/internal-utils";
14
15
 
15
- export { AssertionError, BaseError, BridgeNameEnum, Chains, DestinationExplicitNearAccountDoesntExistError, FailedToFetchFeeError, FeeExceedsAmountError, HotWithdrawalCancelledError, HotWithdrawalNotFoundError, HotWithdrawalPendingError, HttpRequestError, IntentPayloadBuilder, IntentSettlementError, IntentsNearOmniAvailableBalanceTooLowError, IntentsSDK, MinWithdrawalAmountError, OmniTokenNormalisationCheckError, OmniTransferDestinationChainHashNotFoundError, OmniTransferNotFoundError, PoaWithdrawalInvariantError, PoaWithdrawalNotFoundError, PoaWithdrawalPendingError, QuoteError, RelayPublishError, RouteEnum, RpcRequestError, TimeoutError, TokenNotFoundInDestinationChainError, TrustlineNotFoundError, UnsupportedAssetIdError, UnsupportedDestinationMemoError, VersionedNonceBuilder, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
16
+ export { AssertionError, BaseError, BridgeNameEnum, Chains, DestinationExplicitNearAccountDoesntExistError, FailedToFetchFeeError, FeeExceedsAmountError, HotWithdrawalCancelledError, HotWithdrawalNotFoundError, HotWithdrawalPendingError, HttpRequestError, IntentPayloadBuilder, IntentSettlementError, IntentsNearOmniAvailableBalanceTooLowError, IntentsSDK, MinWithdrawalAmountError, OmniTokenNormalisationCheckError, OmniTransferDestinationChainHashNotFoundError, OmniTransferNotFoundError, PoaWithdrawalInvariantError, PoaWithdrawalNotFoundError, PoaWithdrawalPendingError, QuoteError, RelayPublishError, RouteEnum, RpcRequestError, TimeoutError, TokenNotFoundInDestinationChainError, TrustlineNotFoundError, UnsupportedAssetIdError, UnsupportedDestinationMemoError, VersionedNonceBuilder, computeIntentHash, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
@@ -1,9 +1,13 @@
1
1
  const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
- const require_nep413 = require('../lib/nep413.cjs');
2
+ const require_nep413 = require('./intent-hashes/nep413.cjs');
3
+ const require_erc191 = require('./intent-hashes/erc191.cjs');
4
+ const require_tip191 = require('./intent-hashes/tip191.cjs');
5
+ const require_raw_ed25519 = require('./intent-hashes/raw-ed25519.cjs');
6
+ const require_webauthn = require('./intent-hashes/webauthn.cjs');
7
+ const require_ton_connect = require('./intent-hashes/ton-connect.cjs');
8
+ const require_sep53 = require('./intent-hashes/sep53.cjs');
3
9
  let __scure_base = require("@scure/base");
4
10
  __scure_base = require_rolldown_runtime.__toESM(__scure_base);
5
- let __noble_hashes_sha3 = require("@noble/hashes/sha3");
6
- __noble_hashes_sha3 = require_rolldown_runtime.__toESM(__noble_hashes_sha3);
7
11
 
8
12
  //#region src/intents/intent-hash.ts
9
13
  /**
@@ -11,41 +15,34 @@ __noble_hashes_sha3 = require_rolldown_runtime.__toESM(__noble_hashes_sha3);
11
15
  * This follows the same logic as the NEAR intents repository:
12
16
  * https://github.com/near/intents/blob/11fe297dddd50936b297485e147548f5f9a69200/core/src/payload/multi.rs#L56
13
17
  *
14
- * @param multiPayload The signed multi-payload for which to compute the hash
15
- * @returns The intent hash as a base58-encoded string
16
- */
17
- async function computeIntentHash(multiPayload) {
18
- const hashBytes = await computeIntentHashBytes(multiPayload);
19
- return __scure_base.base58.encode(hashBytes);
20
- }
21
- /**
22
- * Computes the intent hash bytes for a MultiPayload.
23
- * Different standards use different hashing algorithms.
18
+ * Different standards use different hash functions:
19
+ * - NEP-413: SHA-256 (of Borsh-serialized payload)
20
+ * - ERC-191: Keccak256 (of prefixed message)
21
+ * - TIP-191: Keccak256 (of prefixed message)
22
+ * - Raw Ed25519: SHA-256 (of raw message)
23
+ * - WebAuthn: SHA-256 (of raw message)
24
+ * - TON Connect: SHA-256 (of formatted message)
25
+ * - SEP-53: SHA-256 (of prefixed message)
24
26
  *
25
- * @param multiPayload The signed multi-payload for which to compute the hash
26
- * @returns The intent hash as bytes
27
+ * @param signed - The multi-payload to hash
28
+ * @returns 32-byte hash as Uint8Array
27
29
  */
28
- async function computeIntentHashBytes(multiPayload) {
29
- switch (multiPayload.standard) {
30
- case "nep413": return computeNep413Hash(multiPayload);
31
- case "erc191":
32
- case "tip191": return computeErc191Hash(multiPayload);
33
- default: throw new Error(`Standard is not yet supported: ${multiPayload.standard}`);
30
+ async function computeIntentHashHashBytes(signed) {
31
+ const { standard } = signed;
32
+ switch (standard) {
33
+ case "nep413": return require_nep413.computeSignedNep413Hash(signed);
34
+ case "erc191": return require_erc191.computeSignedErc191Hash(signed);
35
+ case "tip191": return require_tip191.computeSignedTip191Hash(signed);
36
+ case "raw_ed25519": return require_raw_ed25519.computeSignedRawEd25519Hash(signed);
37
+ case "webauthn": return require_webauthn.computeSignedWebAuthnHash(signed);
38
+ case "ton_connect": return require_ton_connect.computeSignedTonConnectHash(signed);
39
+ case "sep53": return require_sep53.computeSignedSep53Hash(signed);
40
+ default: throw new Error(`Unknown payload standard: ${signed.standard}`);
34
41
  }
35
42
  }
36
- async function computeNep413Hash(multiPayload) {
37
- const payload = multiPayload.payload;
38
- return require_nep413.hashNEP413Message({
39
- message: payload.message,
40
- recipient: payload.recipient,
41
- nonce: Array.from(__scure_base.base64.decode(payload.nonce)),
42
- callback_url: payload.callbackUrl
43
- });
44
- }
45
- function computeErc191Hash(multiPayload) {
46
- const message = multiPayload.payload;
47
- const messageWithPrefix = "Ethereum Signed Message:\n" + new TextEncoder().encode(message).length.toString() + message;
48
- return (0, __noble_hashes_sha3.keccak_256)(new TextEncoder().encode(messageWithPrefix));
43
+ async function computeIntentHash(multiPayload) {
44
+ const hashBytes = await computeIntentHashHashBytes(multiPayload);
45
+ return __scure_base.base58.encode(hashBytes);
49
46
  }
50
47
 
51
48
  //#endregion
@@ -0,0 +1,8 @@
1
+ import { IntentHash } from "./shared-types.cjs";
2
+ import { MultiPayload } from "@defuse-protocol/contract-types";
3
+
4
+ //#region src/intents/intent-hash.d.ts
5
+
6
+ declare function computeIntentHash(multiPayload: MultiPayload): Promise<IntentHash>;
7
+ //#endregion
8
+ export { computeIntentHash };
@@ -0,0 +1,8 @@
1
+ import { IntentHash } from "./shared-types.js";
2
+ import { MultiPayload } from "@defuse-protocol/contract-types";
3
+
4
+ //#region src/intents/intent-hash.d.ts
5
+
6
+ declare function computeIntentHash(multiPayload: MultiPayload): Promise<IntentHash>;
7
+ //#endregion
8
+ export { computeIntentHash };
@@ -1,6 +1,11 @@
1
- import { hashNEP413Message } from "../lib/nep413.js";
2
- import { base58, base64 } from "@scure/base";
3
- import { keccak_256 } from "@noble/hashes/sha3";
1
+ import { computeSignedNep413Hash } from "./intent-hashes/nep413.js";
2
+ import { computeSignedErc191Hash } from "./intent-hashes/erc191.js";
3
+ import { computeSignedTip191Hash } from "./intent-hashes/tip191.js";
4
+ import { computeSignedRawEd25519Hash } from "./intent-hashes/raw-ed25519.js";
5
+ import { computeSignedWebAuthnHash } from "./intent-hashes/webauthn.js";
6
+ import { computeSignedTonConnectHash } from "./intent-hashes/ton-connect.js";
7
+ import { computeSignedSep53Hash } from "./intent-hashes/sep53.js";
8
+ import { base58 } from "@scure/base";
4
9
 
5
10
  //#region src/intents/intent-hash.ts
6
11
  /**
@@ -8,41 +13,34 @@ import { keccak_256 } from "@noble/hashes/sha3";
8
13
  * This follows the same logic as the NEAR intents repository:
9
14
  * https://github.com/near/intents/blob/11fe297dddd50936b297485e147548f5f9a69200/core/src/payload/multi.rs#L56
10
15
  *
11
- * @param multiPayload The signed multi-payload for which to compute the hash
12
- * @returns The intent hash as a base58-encoded string
13
- */
14
- async function computeIntentHash(multiPayload) {
15
- const hashBytes = await computeIntentHashBytes(multiPayload);
16
- return base58.encode(hashBytes);
17
- }
18
- /**
19
- * Computes the intent hash bytes for a MultiPayload.
20
- * Different standards use different hashing algorithms.
16
+ * Different standards use different hash functions:
17
+ * - NEP-413: SHA-256 (of Borsh-serialized payload)
18
+ * - ERC-191: Keccak256 (of prefixed message)
19
+ * - TIP-191: Keccak256 (of prefixed message)
20
+ * - Raw Ed25519: SHA-256 (of raw message)
21
+ * - WebAuthn: SHA-256 (of raw message)
22
+ * - TON Connect: SHA-256 (of formatted message)
23
+ * - SEP-53: SHA-256 (of prefixed message)
21
24
  *
22
- * @param multiPayload The signed multi-payload for which to compute the hash
23
- * @returns The intent hash as bytes
25
+ * @param signed - The multi-payload to hash
26
+ * @returns 32-byte hash as Uint8Array
24
27
  */
25
- async function computeIntentHashBytes(multiPayload) {
26
- switch (multiPayload.standard) {
27
- case "nep413": return computeNep413Hash(multiPayload);
28
- case "erc191":
29
- case "tip191": return computeErc191Hash(multiPayload);
30
- default: throw new Error(`Standard is not yet supported: ${multiPayload.standard}`);
28
+ async function computeIntentHashHashBytes(signed) {
29
+ const { standard } = signed;
30
+ switch (standard) {
31
+ case "nep413": return computeSignedNep413Hash(signed);
32
+ case "erc191": return computeSignedErc191Hash(signed);
33
+ case "tip191": return computeSignedTip191Hash(signed);
34
+ case "raw_ed25519": return computeSignedRawEd25519Hash(signed);
35
+ case "webauthn": return computeSignedWebAuthnHash(signed);
36
+ case "ton_connect": return computeSignedTonConnectHash(signed);
37
+ case "sep53": return computeSignedSep53Hash(signed);
38
+ default: throw new Error(`Unknown payload standard: ${signed.standard}`);
31
39
  }
32
40
  }
33
- async function computeNep413Hash(multiPayload) {
34
- const payload = multiPayload.payload;
35
- return hashNEP413Message({
36
- message: payload.message,
37
- recipient: payload.recipient,
38
- nonce: Array.from(base64.decode(payload.nonce)),
39
- callback_url: payload.callbackUrl
40
- });
41
- }
42
- function computeErc191Hash(multiPayload) {
43
- const message = multiPayload.payload;
44
- const messageWithPrefix = "Ethereum Signed Message:\n" + new TextEncoder().encode(message).length.toString() + message;
45
- return keccak_256(new TextEncoder().encode(messageWithPrefix));
41
+ async function computeIntentHash(multiPayload) {
42
+ const hashBytes = await computeIntentHashHashBytes(multiPayload);
43
+ return base58.encode(hashBytes);
46
44
  }
47
45
 
48
46
  //#endregion
@@ -0,0 +1,39 @@
1
+ const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
2
+ let __noble_hashes_sha3 = require("@noble/hashes/sha3");
3
+ __noble_hashes_sha3 = require_rolldown_runtime.__toESM(__noble_hashes_sha3);
4
+
5
+ //#region src/intents/intent-hashes/erc191.ts
6
+ /**
7
+ * Compute the prehash for ERC-191 payload
8
+ * Format: "\x19Ethereum Signed Message:\n" + length + message
9
+ */
10
+ function computeErc191Prehash(payload) {
11
+ const data = new TextEncoder().encode(payload);
12
+ const prefix = new TextEncoder().encode(`\x19Ethereum Signed Message:\n${data.length}`);
13
+ const result = new Uint8Array(prefix.length + data.length);
14
+ result.set(prefix, 0);
15
+ result.set(data, prefix.length);
16
+ return result;
17
+ }
18
+ /**
19
+ * Compute the Keccak256 hash of an ERC-191 payload
20
+ * This is the hash that should be signed
21
+ *
22
+ * @param payload - The message string to hash
23
+ * @returns 32-byte hash as Uint8Array
24
+ */
25
+ function computeErc191Hash(payload) {
26
+ return (0, __noble_hashes_sha3.keccak_256)(computeErc191Prehash(payload));
27
+ }
28
+ /**
29
+ * Compute hash from a signed ERC-191 payload
30
+ *
31
+ * @param signedPayload - The signed ERC-191 payload
32
+ * @returns 32-byte hash as Uint8Array
33
+ */
34
+ function computeSignedErc191Hash(signedPayload) {
35
+ return computeErc191Hash(signedPayload.payload);
36
+ }
37
+
38
+ //#endregion
39
+ exports.computeSignedErc191Hash = computeSignedErc191Hash;
@@ -0,0 +1,37 @@
1
+ import { keccak_256 } from "@noble/hashes/sha3";
2
+
3
+ //#region src/intents/intent-hashes/erc191.ts
4
+ /**
5
+ * Compute the prehash for ERC-191 payload
6
+ * Format: "\x19Ethereum Signed Message:\n" + length + message
7
+ */
8
+ function computeErc191Prehash(payload) {
9
+ const data = new TextEncoder().encode(payload);
10
+ const prefix = new TextEncoder().encode(`\x19Ethereum Signed Message:\n${data.length}`);
11
+ const result = new Uint8Array(prefix.length + data.length);
12
+ result.set(prefix, 0);
13
+ result.set(data, prefix.length);
14
+ return result;
15
+ }
16
+ /**
17
+ * Compute the Keccak256 hash of an ERC-191 payload
18
+ * This is the hash that should be signed
19
+ *
20
+ * @param payload - The message string to hash
21
+ * @returns 32-byte hash as Uint8Array
22
+ */
23
+ function computeErc191Hash(payload) {
24
+ return keccak_256(computeErc191Prehash(payload));
25
+ }
26
+ /**
27
+ * Compute hash from a signed ERC-191 payload
28
+ *
29
+ * @param signedPayload - The signed ERC-191 payload
30
+ * @returns 32-byte hash as Uint8Array
31
+ */
32
+ function computeSignedErc191Hash(signedPayload) {
33
+ return computeErc191Hash(signedPayload.payload);
34
+ }
35
+
36
+ //#endregion
37
+ export { computeSignedErc191Hash };
@@ -0,0 +1,24 @@
1
+ const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
2
+ const require_nep413 = require('../../lib/nep413.cjs');
3
+ let __scure_base = require("@scure/base");
4
+ __scure_base = require_rolldown_runtime.__toESM(__scure_base);
5
+
6
+ //#region src/intents/intent-hashes/nep413.ts
7
+ /**
8
+ * Compute hash from a signed NEP-413 payload
9
+ *
10
+ * @param signed - The signed NEP-413 payload
11
+ * @returns 32-byte hash as Uint8Array
12
+ */
13
+ async function computeSignedNep413Hash(signed) {
14
+ const payload = signed.payload;
15
+ return require_nep413.hashNEP413Message({
16
+ message: payload.message,
17
+ recipient: payload.recipient,
18
+ nonce: Array.from(__scure_base.base64.decode(payload.nonce)),
19
+ callback_url: payload.callbackUrl
20
+ });
21
+ }
22
+
23
+ //#endregion
24
+ exports.computeSignedNep413Hash = computeSignedNep413Hash;
@@ -0,0 +1,22 @@
1
+ import { hashNEP413Message } from "../../lib/nep413.js";
2
+ import { base64 } from "@scure/base";
3
+
4
+ //#region src/intents/intent-hashes/nep413.ts
5
+ /**
6
+ * Compute hash from a signed NEP-413 payload
7
+ *
8
+ * @param signed - The signed NEP-413 payload
9
+ * @returns 32-byte hash as Uint8Array
10
+ */
11
+ async function computeSignedNep413Hash(signed) {
12
+ const payload = signed.payload;
13
+ return hashNEP413Message({
14
+ message: payload.message,
15
+ recipient: payload.recipient,
16
+ nonce: Array.from(base64.decode(payload.nonce)),
17
+ callback_url: payload.callbackUrl
18
+ });
19
+ }
20
+
21
+ //#endregion
22
+ export { computeSignedNep413Hash };
@@ -0,0 +1,27 @@
1
+ const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
2
+ let __noble_hashes_sha2 = require("@noble/hashes/sha2");
3
+ __noble_hashes_sha2 = require_rolldown_runtime.__toESM(__noble_hashes_sha2);
4
+
5
+ //#region src/intents/intent-hashes/raw-ed25519.ts
6
+ /**
7
+ * Compute the SHA-256 hash of a Raw Ed25519 payload
8
+ * This simply hashes the UTF-8 encoded payload string
9
+ *
10
+ * @param payload - The message string to hash
11
+ * @returns 32-byte hash as Uint8Array
12
+ */
13
+ function computeRawEd25519Hash(payload) {
14
+ return (0, __noble_hashes_sha2.sha256)(new TextEncoder().encode(payload));
15
+ }
16
+ /**
17
+ * Compute hash from a signed Raw Ed25519 payload
18
+ *
19
+ * @param signedPayload - The signed Raw Ed25519 payload
20
+ * @returns 32-byte hash as Uint8Array
21
+ */
22
+ function computeSignedRawEd25519Hash(signedPayload) {
23
+ return computeRawEd25519Hash(signedPayload.payload);
24
+ }
25
+
26
+ //#endregion
27
+ exports.computeSignedRawEd25519Hash = computeSignedRawEd25519Hash;
@@ -0,0 +1,25 @@
1
+ import { sha256 } from "@noble/hashes/sha2";
2
+
3
+ //#region src/intents/intent-hashes/raw-ed25519.ts
4
+ /**
5
+ * Compute the SHA-256 hash of a Raw Ed25519 payload
6
+ * This simply hashes the UTF-8 encoded payload string
7
+ *
8
+ * @param payload - The message string to hash
9
+ * @returns 32-byte hash as Uint8Array
10
+ */
11
+ function computeRawEd25519Hash(payload) {
12
+ return sha256(new TextEncoder().encode(payload));
13
+ }
14
+ /**
15
+ * Compute hash from a signed Raw Ed25519 payload
16
+ *
17
+ * @param signedPayload - The signed Raw Ed25519 payload
18
+ * @returns 32-byte hash as Uint8Array
19
+ */
20
+ function computeSignedRawEd25519Hash(signedPayload) {
21
+ return computeRawEd25519Hash(signedPayload.payload);
22
+ }
23
+
24
+ //#endregion
25
+ export { computeSignedRawEd25519Hash };
@@ -0,0 +1,38 @@
1
+ const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
2
+ let __defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
3
+ __defuse_protocol_internal_utils = require_rolldown_runtime.__toESM(__defuse_protocol_internal_utils);
4
+ let __noble_hashes_sha2 = require("@noble/hashes/sha2");
5
+ __noble_hashes_sha2 = require_rolldown_runtime.__toESM(__noble_hashes_sha2);
6
+
7
+ //#region src/intents/intent-hashes/sep53.ts
8
+ /**
9
+ * Compute the prehash for SEP-53 payload
10
+ * Format: "Stellar Signed Message:\n" + message
11
+ */
12
+ function computeSep53Prehash(payload) {
13
+ const prefix = new TextEncoder().encode("Stellar Signed Message:\n");
14
+ const data = new TextEncoder().encode(payload);
15
+ return __defuse_protocol_internal_utils.utils.concatUint8Arrays([prefix, data]);
16
+ }
17
+ /**
18
+ * Compute the SHA-256 hash of a SEP-53 payload
19
+ * This is the hash that should be signed
20
+ *
21
+ * @param payload - The message string to hash
22
+ * @returns 32-byte hash as Uint8Array
23
+ */
24
+ function computeSep53Hash(payload) {
25
+ return (0, __noble_hashes_sha2.sha256)(computeSep53Prehash(payload));
26
+ }
27
+ /**
28
+ * Compute hash from a signed SEP-53 payload
29
+ *
30
+ * @param signedPayload - The signed SEP-53 payload
31
+ * @returns 32-byte hash as Uint8Array
32
+ */
33
+ function computeSignedSep53Hash(signedPayload) {
34
+ return computeSep53Hash(signedPayload.payload);
35
+ }
36
+
37
+ //#endregion
38
+ exports.computeSignedSep53Hash = computeSignedSep53Hash;
@@ -0,0 +1,35 @@
1
+ import { utils } from "@defuse-protocol/internal-utils";
2
+ import { sha256 } from "@noble/hashes/sha2";
3
+
4
+ //#region src/intents/intent-hashes/sep53.ts
5
+ /**
6
+ * Compute the prehash for SEP-53 payload
7
+ * Format: "Stellar Signed Message:\n" + message
8
+ */
9
+ function computeSep53Prehash(payload) {
10
+ const prefix = new TextEncoder().encode("Stellar Signed Message:\n");
11
+ const data = new TextEncoder().encode(payload);
12
+ return utils.concatUint8Arrays([prefix, data]);
13
+ }
14
+ /**
15
+ * Compute the SHA-256 hash of a SEP-53 payload
16
+ * This is the hash that should be signed
17
+ *
18
+ * @param payload - The message string to hash
19
+ * @returns 32-byte hash as Uint8Array
20
+ */
21
+ function computeSep53Hash(payload) {
22
+ return sha256(computeSep53Prehash(payload));
23
+ }
24
+ /**
25
+ * Compute hash from a signed SEP-53 payload
26
+ *
27
+ * @param signedPayload - The signed SEP-53 payload
28
+ * @returns 32-byte hash as Uint8Array
29
+ */
30
+ function computeSignedSep53Hash(signedPayload) {
31
+ return computeSep53Hash(signedPayload.payload);
32
+ }
33
+
34
+ //#endregion
35
+ export { computeSignedSep53Hash };
@@ -0,0 +1,40 @@
1
+ const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
2
+ let __noble_hashes_sha3 = require("@noble/hashes/sha3");
3
+ __noble_hashes_sha3 = require_rolldown_runtime.__toESM(__noble_hashes_sha3);
4
+
5
+ //#region src/intents/intent-hashes/tip191.ts
6
+ /**
7
+ * Compute the prehash for TIP-191 payload
8
+ * Format: "\x19TRON Signed Message:\n" + length + message
9
+ * Note: Prefix from https://tronweb.network/docu/docs/Sign%20and%20Verify%20Message/
10
+ */
11
+ function computeTip191Prehash(payload) {
12
+ const data = new TextEncoder().encode(payload);
13
+ const prefix = new TextEncoder().encode(`\x19TRON Signed Message:\n${data.length}`);
14
+ const result = new Uint8Array(prefix.length + data.length);
15
+ result.set(prefix, 0);
16
+ result.set(data, prefix.length);
17
+ return result;
18
+ }
19
+ /**
20
+ * Compute the Keccak256 hash of a TIP-191 payload
21
+ * This is the hash that should be signed
22
+ *
23
+ * @param payload - The message string to hash
24
+ * @returns 32-byte hash as Uint8Array
25
+ */
26
+ function computeTip191Hash(payload) {
27
+ return (0, __noble_hashes_sha3.keccak_256)(computeTip191Prehash(payload));
28
+ }
29
+ /**
30
+ * Compute hash from a signed TIP-191 payload
31
+ *
32
+ * @param signedPayload - The signed TIP-191 payload
33
+ * @returns 32-byte hash as Uint8Array
34
+ */
35
+ function computeSignedTip191Hash(signedPayload) {
36
+ return computeTip191Hash(signedPayload.payload);
37
+ }
38
+
39
+ //#endregion
40
+ exports.computeSignedTip191Hash = computeSignedTip191Hash;
@@ -0,0 +1,38 @@
1
+ import { keccak_256 } from "@noble/hashes/sha3";
2
+
3
+ //#region src/intents/intent-hashes/tip191.ts
4
+ /**
5
+ * Compute the prehash for TIP-191 payload
6
+ * Format: "\x19TRON Signed Message:\n" + length + message
7
+ * Note: Prefix from https://tronweb.network/docu/docs/Sign%20and%20Verify%20Message/
8
+ */
9
+ function computeTip191Prehash(payload) {
10
+ const data = new TextEncoder().encode(payload);
11
+ const prefix = new TextEncoder().encode(`\x19TRON Signed Message:\n${data.length}`);
12
+ const result = new Uint8Array(prefix.length + data.length);
13
+ result.set(prefix, 0);
14
+ result.set(data, prefix.length);
15
+ return result;
16
+ }
17
+ /**
18
+ * Compute the Keccak256 hash of a TIP-191 payload
19
+ * This is the hash that should be signed
20
+ *
21
+ * @param payload - The message string to hash
22
+ * @returns 32-byte hash as Uint8Array
23
+ */
24
+ function computeTip191Hash(payload) {
25
+ return keccak_256(computeTip191Prehash(payload));
26
+ }
27
+ /**
28
+ * Compute hash from a signed TIP-191 payload
29
+ *
30
+ * @param signedPayload - The signed TIP-191 payload
31
+ * @returns 32-byte hash as Uint8Array
32
+ */
33
+ function computeSignedTip191Hash(signedPayload) {
34
+ return computeTip191Hash(signedPayload.payload);
35
+ }
36
+
37
+ //#endregion
38
+ export { computeSignedTip191Hash };
@@ -0,0 +1,106 @@
1
+ const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
2
+ let __noble_hashes_sha2 = require("@noble/hashes/sha2");
3
+ __noble_hashes_sha2 = require_rolldown_runtime.__toESM(__noble_hashes_sha2);
4
+
5
+ //#region src/intents/intent-hashes/ton-connect.ts
6
+ /**
7
+ * Convert number to big-endian byte array
8
+ */
9
+ function numberToBigEndian(num, bytes) {
10
+ const result = new Uint8Array(bytes);
11
+ for (let i = bytes - 1; i >= 0; i--) {
12
+ result[i] = num & 255;
13
+ num >>= 8;
14
+ }
15
+ return result;
16
+ }
17
+ /**
18
+ * Parse TON address string to TonAddress object
19
+ * Supports raw format: "workchain:address_hex"
20
+ * Example: "0:f4809e5ffac9dc42a6b1d94c5e74ad5fd86378de675c805f2274d0055cbc9378"
21
+ *
22
+ * @param addressString - TON address string in raw format
23
+ * @returns Parsed TonAddress object
24
+ */
25
+ function parseTonAddress(addressString) {
26
+ const parts = addressString.split(":");
27
+ if (parts.length !== 2) throw new Error(`Invalid TON address format: ${addressString}. Expected "workchain:address_hex"`);
28
+ const workchainId = parseInt(parts[0], 10);
29
+ if (Number.isNaN(workchainId)) throw new Error(`Invalid workchain ID: ${parts[0]}`);
30
+ const addressHex = parts[1].startsWith("0x") ? parts[1].slice(2) : parts[1];
31
+ if (addressHex.length !== 64) throw new Error(`Invalid address length: expected 64 hex characters, got ${addressHex.length}`);
32
+ const address = new Uint8Array(32);
33
+ for (let i = 0; i < 32; i++) address[i] = parseInt(addressHex.slice(i * 2, i * 2 + 2), 16);
34
+ return {
35
+ workchainId,
36
+ address
37
+ };
38
+ }
39
+ /**
40
+ * Compute the SHA-256 hash of a TON Connect payload
41
+ *
42
+ * For text and binary payloads:
43
+ * Hash = SHA256(
44
+ * 0xffff +
45
+ * "ton-connect/sign-data/" +
46
+ * workchain_id (4 bytes BE) +
47
+ * address (32 bytes) +
48
+ * domain_len (4 bytes BE) +
49
+ * domain +
50
+ * timestamp (8 bytes BE) +
51
+ * payload_type ("txt" or "bin") +
52
+ * payload_len (4 bytes BE) +
53
+ * payload
54
+ * )
55
+ *
56
+ * For cell payloads: Uses TON TLB message serialization (not fully implemented here)
57
+ *
58
+ * @param payload - The TON Connect payload to hash
59
+ * @returns 32-byte hash as Uint8Array
60
+ */
61
+ function computeTonConnectHash(payload) {
62
+ const { address, domain, timestamp, payload: payloadSchema } = payload;
63
+ const parsedAddress = parseTonAddress(address);
64
+ const schemaType = payloadSchema.type;
65
+ switch (schemaType) {
66
+ case "text": {
67
+ const payloadPrefix = "txt";
68
+ const payloadData = new TextEncoder().encode(payloadSchema.text);
69
+ const parts = [
70
+ new Uint8Array([255, 255]),
71
+ new TextEncoder().encode("ton-connect/sign-data/"),
72
+ numberToBigEndian(parsedAddress.workchainId, 4),
73
+ parsedAddress.address,
74
+ numberToBigEndian(domain.length, 4),
75
+ new TextEncoder().encode(domain),
76
+ numberToBigEndian(Number(timestamp), 8),
77
+ new TextEncoder().encode(payloadPrefix),
78
+ numberToBigEndian(payloadData.length, 4),
79
+ payloadData
80
+ ];
81
+ const totalLength = parts.reduce((sum, part) => sum + part.length, 0);
82
+ const message = new Uint8Array(totalLength);
83
+ let offset = 0;
84
+ for (const part of parts) {
85
+ message.set(part, offset);
86
+ offset += part.length;
87
+ }
88
+ return (0, __noble_hashes_sha2.sha256)(message);
89
+ }
90
+ case "binary": throw new Error("Binary payload hashing is not yet supported");
91
+ case "cell": throw new Error("Cell payload hashing is not yet supported.");
92
+ default: throw new Error(`Unknown TON Connect payload type: ${schemaType}`);
93
+ }
94
+ }
95
+ /**
96
+ * Compute hash from a signed TON Connect payload
97
+ *
98
+ * @param signedPayload - The signed TON Connect payload
99
+ * @returns 32-byte hash as Uint8Array
100
+ */
101
+ function computeSignedTonConnectHash(signedPayload) {
102
+ return computeTonConnectHash(signedPayload);
103
+ }
104
+
105
+ //#endregion
106
+ exports.computeSignedTonConnectHash = computeSignedTonConnectHash;
@@ -0,0 +1,104 @@
1
+ import { sha256 } from "@noble/hashes/sha2";
2
+
3
+ //#region src/intents/intent-hashes/ton-connect.ts
4
+ /**
5
+ * Convert number to big-endian byte array
6
+ */
7
+ function numberToBigEndian(num, bytes) {
8
+ const result = new Uint8Array(bytes);
9
+ for (let i = bytes - 1; i >= 0; i--) {
10
+ result[i] = num & 255;
11
+ num >>= 8;
12
+ }
13
+ return result;
14
+ }
15
+ /**
16
+ * Parse TON address string to TonAddress object
17
+ * Supports raw format: "workchain:address_hex"
18
+ * Example: "0:f4809e5ffac9dc42a6b1d94c5e74ad5fd86378de675c805f2274d0055cbc9378"
19
+ *
20
+ * @param addressString - TON address string in raw format
21
+ * @returns Parsed TonAddress object
22
+ */
23
+ function parseTonAddress(addressString) {
24
+ const parts = addressString.split(":");
25
+ if (parts.length !== 2) throw new Error(`Invalid TON address format: ${addressString}. Expected "workchain:address_hex"`);
26
+ const workchainId = parseInt(parts[0], 10);
27
+ if (Number.isNaN(workchainId)) throw new Error(`Invalid workchain ID: ${parts[0]}`);
28
+ const addressHex = parts[1].startsWith("0x") ? parts[1].slice(2) : parts[1];
29
+ if (addressHex.length !== 64) throw new Error(`Invalid address length: expected 64 hex characters, got ${addressHex.length}`);
30
+ const address = new Uint8Array(32);
31
+ for (let i = 0; i < 32; i++) address[i] = parseInt(addressHex.slice(i * 2, i * 2 + 2), 16);
32
+ return {
33
+ workchainId,
34
+ address
35
+ };
36
+ }
37
+ /**
38
+ * Compute the SHA-256 hash of a TON Connect payload
39
+ *
40
+ * For text and binary payloads:
41
+ * Hash = SHA256(
42
+ * 0xffff +
43
+ * "ton-connect/sign-data/" +
44
+ * workchain_id (4 bytes BE) +
45
+ * address (32 bytes) +
46
+ * domain_len (4 bytes BE) +
47
+ * domain +
48
+ * timestamp (8 bytes BE) +
49
+ * payload_type ("txt" or "bin") +
50
+ * payload_len (4 bytes BE) +
51
+ * payload
52
+ * )
53
+ *
54
+ * For cell payloads: Uses TON TLB message serialization (not fully implemented here)
55
+ *
56
+ * @param payload - The TON Connect payload to hash
57
+ * @returns 32-byte hash as Uint8Array
58
+ */
59
+ function computeTonConnectHash(payload) {
60
+ const { address, domain, timestamp, payload: payloadSchema } = payload;
61
+ const parsedAddress = parseTonAddress(address);
62
+ const schemaType = payloadSchema.type;
63
+ switch (schemaType) {
64
+ case "text": {
65
+ const payloadPrefix = "txt";
66
+ const payloadData = new TextEncoder().encode(payloadSchema.text);
67
+ const parts = [
68
+ new Uint8Array([255, 255]),
69
+ new TextEncoder().encode("ton-connect/sign-data/"),
70
+ numberToBigEndian(parsedAddress.workchainId, 4),
71
+ parsedAddress.address,
72
+ numberToBigEndian(domain.length, 4),
73
+ new TextEncoder().encode(domain),
74
+ numberToBigEndian(Number(timestamp), 8),
75
+ new TextEncoder().encode(payloadPrefix),
76
+ numberToBigEndian(payloadData.length, 4),
77
+ payloadData
78
+ ];
79
+ const totalLength = parts.reduce((sum, part) => sum + part.length, 0);
80
+ const message = new Uint8Array(totalLength);
81
+ let offset = 0;
82
+ for (const part of parts) {
83
+ message.set(part, offset);
84
+ offset += part.length;
85
+ }
86
+ return sha256(message);
87
+ }
88
+ case "binary": throw new Error("Binary payload hashing is not yet supported");
89
+ case "cell": throw new Error("Cell payload hashing is not yet supported.");
90
+ default: throw new Error(`Unknown TON Connect payload type: ${schemaType}`);
91
+ }
92
+ }
93
+ /**
94
+ * Compute hash from a signed TON Connect payload
95
+ *
96
+ * @param signedPayload - The signed TON Connect payload
97
+ * @returns 32-byte hash as Uint8Array
98
+ */
99
+ function computeSignedTonConnectHash(signedPayload) {
100
+ return computeTonConnectHash(signedPayload);
101
+ }
102
+
103
+ //#endregion
104
+ export { computeSignedTonConnectHash };
@@ -0,0 +1,27 @@
1
+ const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
2
+ let __noble_hashes_sha2 = require("@noble/hashes/sha2");
3
+ __noble_hashes_sha2 = require_rolldown_runtime.__toESM(__noble_hashes_sha2);
4
+
5
+ //#region src/intents/intent-hashes/webauthn.ts
6
+ /**
7
+ * Compute the SHA-256 hash of a WebAuthn payload
8
+ * This simply hashes the UTF-8 encoded payload string
9
+ *
10
+ * @param payload - The message string to hash
11
+ * @returns 32-byte hash as Uint8Array
12
+ */
13
+ function computeWebAuthnHash(payload) {
14
+ return (0, __noble_hashes_sha2.sha256)(new TextEncoder().encode(payload));
15
+ }
16
+ /**
17
+ * Compute hash from a signed WebAuthn payload
18
+ *
19
+ * @param signedPayload - The signed WebAuthn payload
20
+ * @returns 32-byte hash as Uint8Array
21
+ */
22
+ function computeSignedWebAuthnHash(signedPayload) {
23
+ return computeWebAuthnHash(signedPayload.payload);
24
+ }
25
+
26
+ //#endregion
27
+ exports.computeSignedWebAuthnHash = computeSignedWebAuthnHash;
@@ -0,0 +1,25 @@
1
+ import { sha256 } from "@noble/hashes/sha2";
2
+
3
+ //#region src/intents/intent-hashes/webauthn.ts
4
+ /**
5
+ * Compute the SHA-256 hash of a WebAuthn payload
6
+ * This simply hashes the UTF-8 encoded payload string
7
+ *
8
+ * @param payload - The message string to hash
9
+ * @returns 32-byte hash as Uint8Array
10
+ */
11
+ function computeWebAuthnHash(payload) {
12
+ return sha256(new TextEncoder().encode(payload));
13
+ }
14
+ /**
15
+ * Compute hash from a signed WebAuthn payload
16
+ *
17
+ * @param signedPayload - The signed WebAuthn payload
18
+ * @returns 32-byte hash as Uint8Array
19
+ */
20
+ function computeSignedWebAuthnHash(signedPayload) {
21
+ return computeWebAuthnHash(signedPayload.payload);
22
+ }
23
+
24
+ //#endregion
25
+ export { computeSignedWebAuthnHash };
@@ -1,4 +1,4 @@
1
- import { Intent, MultiPayload } from "@defuse-protocol/contract-types";
1
+ import { Intent, MultiPayload as MultiPayload$1 } from "@defuse-protocol/contract-types";
2
2
 
3
3
  //#region src/intents/shared-types.d.ts
4
4
  type IntentPrimitive = Intent;
@@ -12,9 +12,9 @@ interface IntentPayload {
12
12
  type IntentPayloadFactory = (intentParams: IntentPayload) => Promise<Partial<IntentPayload>> | Partial<IntentPayload>;
13
13
  type IntentHash = string;
14
14
  interface RelayParamsDefault {
15
- multiPayload: MultiPayload;
15
+ multiPayload: MultiPayload$1;
16
16
  quoteHashes?: string[];
17
17
  }
18
18
  type IntentRelayParamsFactory<RelayParams = Omit<RelayParamsDefault, "multiPayload">> = () => RelayParams | Promise<RelayParams>;
19
19
  //#endregion
20
- export { IntentHash, IntentPayload, IntentPayloadFactory, IntentPrimitive, IntentRelayParamsFactory, type MultiPayload, RelayParamsDefault };
20
+ export { IntentHash, IntentPayload, IntentPayloadFactory, IntentPrimitive, IntentRelayParamsFactory, type MultiPayload$1 as MultiPayload, RelayParamsDefault };
@@ -1,4 +1,4 @@
1
- import { Intent, MultiPayload } from "@defuse-protocol/contract-types";
1
+ import { Intent, MultiPayload as MultiPayload$1 } from "@defuse-protocol/contract-types";
2
2
 
3
3
  //#region src/intents/shared-types.d.ts
4
4
  type IntentPrimitive = Intent;
@@ -12,9 +12,9 @@ interface IntentPayload {
12
12
  type IntentPayloadFactory = (intentParams: IntentPayload) => Promise<Partial<IntentPayload>> | Partial<IntentPayload>;
13
13
  type IntentHash = string;
14
14
  interface RelayParamsDefault {
15
- multiPayload: MultiPayload;
15
+ multiPayload: MultiPayload$1;
16
16
  quoteHashes?: string[];
17
17
  }
18
18
  type IntentRelayParamsFactory<RelayParams = Omit<RelayParamsDefault, "multiPayload">> = () => RelayParams | Promise<RelayParams>;
19
19
  //#endregion
20
- export { IntentHash, IntentPayload, IntentPayloadFactory, IntentPrimitive, IntentRelayParamsFactory, type MultiPayload, RelayParamsDefault };
20
+ export { IntentHash, IntentPayload, IntentPayloadFactory, IntentPrimitive, IntentRelayParamsFactory, type MultiPayload$1 as MultiPayload, RelayParamsDefault };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defuse-protocol/intents-sdk",
3
- "version": "0.30.1",
3
+ "version": "0.31.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -39,7 +39,7 @@
39
39
  "valibot": "^1.0.0",
40
40
  "viem": "^2.0.0",
41
41
  "@defuse-protocol/contract-types": "0.3.0",
42
- "@defuse-protocol/internal-utils": "0.18.2"
42
+ "@defuse-protocol/internal-utils": "0.18.3"
43
43
  },
44
44
  "devDependencies": {
45
45
  "tsdown": "0.15.5",