@defuse-protocol/intents-sdk 0.30.1 → 0.32.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 +2 -0
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/src/intents/intent-hash.cjs +31 -34
- package/dist/src/intents/intent-hash.d.cts +8 -0
- package/dist/src/intents/intent-hash.d.ts +8 -0
- package/dist/src/intents/intent-hash.js +32 -34
- package/dist/src/intents/intent-hashes/erc191.cjs +39 -0
- package/dist/src/intents/intent-hashes/erc191.js +37 -0
- package/dist/src/intents/intent-hashes/nep413.cjs +24 -0
- package/dist/src/intents/intent-hashes/nep413.js +22 -0
- package/dist/src/intents/intent-hashes/raw-ed25519.cjs +27 -0
- package/dist/src/intents/intent-hashes/raw-ed25519.js +25 -0
- package/dist/src/intents/intent-hashes/sep53.cjs +38 -0
- package/dist/src/intents/intent-hashes/sep53.js +35 -0
- package/dist/src/intents/intent-hashes/tip191.cjs +40 -0
- package/dist/src/intents/intent-hashes/tip191.js +38 -0
- package/dist/src/intents/intent-hashes/ton-connect.cjs +106 -0
- package/dist/src/intents/intent-hashes/ton-connect.js +104 -0
- package/dist/src/intents/intent-hashes/webauthn.cjs +27 -0
- package/dist/src/intents/intent-hashes/webauthn.js +25 -0
- package/dist/src/intents/shared-types.d.cts +3 -3
- package/dist/src/intents/shared-types.d.ts +3 -3
- package/dist/src/lib/caip2.cjs +2 -0
- package/dist/src/lib/caip2.d.cts +2 -0
- package/dist/src/lib/caip2.d.ts +2 -0
- package/dist/src/lib/caip2.js +2 -0
- package/dist/src/lib/validateAddress.cjs +67 -4
- package/dist/src/lib/validateAddress.js +65 -2
- package/package.json +3 -3
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('
|
|
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
|
-
*
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
26
|
-
* @returns
|
|
27
|
+
* @param signed - The multi-payload to hash
|
|
28
|
+
* @returns 32-byte hash as Uint8Array
|
|
27
29
|
*/
|
|
28
|
-
async function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
case "
|
|
32
|
-
case "
|
|
33
|
-
|
|
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
|
|
37
|
-
const
|
|
38
|
-
return
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
*
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
23
|
-
* @returns
|
|
25
|
+
* @param signed - The multi-payload to hash
|
|
26
|
+
* @returns 32-byte hash as Uint8Array
|
|
24
27
|
*/
|
|
25
|
-
async function
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
case "
|
|
29
|
-
case "
|
|
30
|
-
|
|
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
|
|
34
|
-
const
|
|
35
|
-
return
|
|
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/dist/src/lib/caip2.cjs
CHANGED
|
@@ -10,11 +10,13 @@ const Chains = {
|
|
|
10
10
|
Bitcoin: "bip122:000000000019d6689c085ae165831e93",
|
|
11
11
|
Zcash: "bip122:00040fe8ec8471911baa1db1266ea15d",
|
|
12
12
|
Dogecoin: "bip122:1a91e3dace36e2be3bf030a65679fe82",
|
|
13
|
+
Litecoin: "bip122:12a765e31ffd4059bada1e25190f6e98",
|
|
13
14
|
Ethereum: "eip155:1",
|
|
14
15
|
Optimism: "eip155:10",
|
|
15
16
|
BNB: "eip155:56",
|
|
16
17
|
Gnosis: "eip155:100",
|
|
17
18
|
Polygon: "eip155:137",
|
|
19
|
+
LayerX: "eip155:196",
|
|
18
20
|
Base: "eip155:8453",
|
|
19
21
|
Arbitrum: "eip155:42161",
|
|
20
22
|
Avalanche: "eip155:43114",
|
package/dist/src/lib/caip2.d.cts
CHANGED
|
@@ -6,11 +6,13 @@ declare const Chains: {
|
|
|
6
6
|
readonly Bitcoin: "bip122:000000000019d6689c085ae165831e93";
|
|
7
7
|
readonly Zcash: "bip122:00040fe8ec8471911baa1db1266ea15d";
|
|
8
8
|
readonly Dogecoin: "bip122:1a91e3dace36e2be3bf030a65679fe82";
|
|
9
|
+
readonly Litecoin: "bip122:12a765e31ffd4059bada1e25190f6e98";
|
|
9
10
|
readonly Ethereum: "eip155:1";
|
|
10
11
|
readonly Optimism: "eip155:10";
|
|
11
12
|
readonly BNB: "eip155:56";
|
|
12
13
|
readonly Gnosis: "eip155:100";
|
|
13
14
|
readonly Polygon: "eip155:137";
|
|
15
|
+
readonly LayerX: "eip155:196";
|
|
14
16
|
readonly Base: "eip155:8453";
|
|
15
17
|
readonly Arbitrum: "eip155:42161";
|
|
16
18
|
readonly Avalanche: "eip155:43114";
|
package/dist/src/lib/caip2.d.ts
CHANGED
|
@@ -6,11 +6,13 @@ declare const Chains: {
|
|
|
6
6
|
readonly Bitcoin: "bip122:000000000019d6689c085ae165831e93";
|
|
7
7
|
readonly Zcash: "bip122:00040fe8ec8471911baa1db1266ea15d";
|
|
8
8
|
readonly Dogecoin: "bip122:1a91e3dace36e2be3bf030a65679fe82";
|
|
9
|
+
readonly Litecoin: "bip122:12a765e31ffd4059bada1e25190f6e98";
|
|
9
10
|
readonly Ethereum: "eip155:1";
|
|
10
11
|
readonly Optimism: "eip155:10";
|
|
11
12
|
readonly BNB: "eip155:56";
|
|
12
13
|
readonly Gnosis: "eip155:100";
|
|
13
14
|
readonly Polygon: "eip155:137";
|
|
15
|
+
readonly LayerX: "eip155:196";
|
|
14
16
|
readonly Base: "eip155:8453";
|
|
15
17
|
readonly Arbitrum: "eip155:42161";
|
|
16
18
|
readonly Avalanche: "eip155:43114";
|
package/dist/src/lib/caip2.js
CHANGED
|
@@ -8,11 +8,13 @@ const Chains = {
|
|
|
8
8
|
Bitcoin: "bip122:000000000019d6689c085ae165831e93",
|
|
9
9
|
Zcash: "bip122:00040fe8ec8471911baa1db1266ea15d",
|
|
10
10
|
Dogecoin: "bip122:1a91e3dace36e2be3bf030a65679fe82",
|
|
11
|
+
Litecoin: "bip122:12a765e31ffd4059bada1e25190f6e98",
|
|
11
12
|
Ethereum: "eip155:1",
|
|
12
13
|
Optimism: "eip155:10",
|
|
13
14
|
BNB: "eip155:56",
|
|
14
15
|
Gnosis: "eip155:100",
|
|
15
16
|
Polygon: "eip155:137",
|
|
17
|
+
LayerX: "eip155:196",
|
|
16
18
|
Base: "eip155:8453",
|
|
17
19
|
Arbitrum: "eip155:42161",
|
|
18
20
|
Avalanche: "eip155:43114",
|
|
@@ -4,8 +4,8 @@ let __defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils"
|
|
|
4
4
|
__defuse_protocol_internal_utils = require_rolldown_runtime.__toESM(__defuse_protocol_internal_utils);
|
|
5
5
|
let viem = require("viem");
|
|
6
6
|
viem = require_rolldown_runtime.__toESM(viem);
|
|
7
|
-
let
|
|
8
|
-
|
|
7
|
+
let __noble_hashes_sha2 = require("@noble/hashes/sha2");
|
|
8
|
+
__noble_hashes_sha2 = require_rolldown_runtime.__toESM(__noble_hashes_sha2);
|
|
9
9
|
let __scure_base = require("@scure/base");
|
|
10
10
|
__scure_base = require_rolldown_runtime.__toESM(__scure_base);
|
|
11
11
|
let __solana_web3_js = require("@solana/web3.js");
|
|
@@ -15,12 +15,12 @@ ripple_address_codec = require_rolldown_runtime.__toESM(ripple_address_codec);
|
|
|
15
15
|
|
|
16
16
|
//#region src/lib/validateAddress.ts
|
|
17
17
|
function validateAddress(address, blockchain) {
|
|
18
|
-
if (blockchain.startsWith("eip155:")) return validateEthAddress(address);
|
|
19
18
|
switch (blockchain) {
|
|
20
19
|
case require_caip2.Chains.Near: return __defuse_protocol_internal_utils.utils.validateNearAddress(address);
|
|
21
20
|
case require_caip2.Chains.Bitcoin: return validateBtcAddress(address);
|
|
22
21
|
case require_caip2.Chains.Solana: return validateSolAddress(address);
|
|
23
22
|
case require_caip2.Chains.Dogecoin: return validateDogeAddress(address);
|
|
23
|
+
case require_caip2.Chains.Litecoin: return validateLitecoinAddress(address);
|
|
24
24
|
case require_caip2.Chains.XRPL: return validateXrpAddress(address);
|
|
25
25
|
case require_caip2.Chains.Zcash: return validateZcashAddress(address);
|
|
26
26
|
case require_caip2.Chains.Tron: return validateTronAddress(address);
|
|
@@ -29,6 +29,16 @@ function validateAddress(address, blockchain) {
|
|
|
29
29
|
case require_caip2.Chains.Stellar: return validateStellarAddress(address);
|
|
30
30
|
case require_caip2.Chains.Aptos: return validateAptosAddress(address);
|
|
31
31
|
case require_caip2.Chains.Cardano: return validateCardanoAddress(address);
|
|
32
|
+
case require_caip2.Chains.Ethereum:
|
|
33
|
+
case require_caip2.Chains.Optimism:
|
|
34
|
+
case require_caip2.Chains.BNB:
|
|
35
|
+
case require_caip2.Chains.Gnosis:
|
|
36
|
+
case require_caip2.Chains.Polygon:
|
|
37
|
+
case require_caip2.Chains.LayerX:
|
|
38
|
+
case require_caip2.Chains.Base:
|
|
39
|
+
case require_caip2.Chains.Arbitrum:
|
|
40
|
+
case require_caip2.Chains.Avalanche:
|
|
41
|
+
case require_caip2.Chains.Berachain: return validateEthAddress(address);
|
|
32
42
|
default: return false;
|
|
33
43
|
}
|
|
34
44
|
}
|
|
@@ -91,7 +101,7 @@ function validateTronBase58Address(address) {
|
|
|
91
101
|
if (decoded.length !== 25) return false;
|
|
92
102
|
const data = decoded.slice(0, 21);
|
|
93
103
|
const checksum = decoded.slice(21);
|
|
94
|
-
const expectedChecksum = (0,
|
|
104
|
+
const expectedChecksum = (0, __noble_hashes_sha2.sha256)((0, __noble_hashes_sha2.sha256)(data)).slice(0, 4);
|
|
95
105
|
for (let i = 0; i < 4; i++) if (checksum[i] !== expectedChecksum[i]) return false;
|
|
96
106
|
return data[0] === 65;
|
|
97
107
|
} catch {
|
|
@@ -132,6 +142,59 @@ function validateCardanoAddress(address) {
|
|
|
132
142
|
return false;
|
|
133
143
|
}
|
|
134
144
|
}
|
|
145
|
+
function validateLitecoinAddress(address) {
|
|
146
|
+
const first = address[0];
|
|
147
|
+
if (first === "L") return validateLitecoinBase58Address(address, 48);
|
|
148
|
+
if (first === "M") return validateLitecoinBase58Address(address, 50);
|
|
149
|
+
if (first === "3") return validateLitecoinBase58Address(address, 5);
|
|
150
|
+
if (!address.toLowerCase().startsWith("ltc1")) return false;
|
|
151
|
+
return validateLitecoinBech32Address(address);
|
|
152
|
+
}
|
|
153
|
+
function validateLitecoinBase58Address(address, expectedVersion) {
|
|
154
|
+
let decoded;
|
|
155
|
+
try {
|
|
156
|
+
decoded = __scure_base.base58.decode(address);
|
|
157
|
+
} catch {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
if (decoded.length !== 25) return false;
|
|
161
|
+
if (decoded[0] !== expectedVersion) return false;
|
|
162
|
+
const payload = decoded.subarray(0, 21);
|
|
163
|
+
const checksum = decoded.subarray(21, 25);
|
|
164
|
+
const expectedChecksum = (0, __noble_hashes_sha2.sha256)((0, __noble_hashes_sha2.sha256)(payload)).subarray(0, 4);
|
|
165
|
+
for (let i = 0; i < 4; i++) if (checksum[i] !== expectedChecksum[i]) return false;
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
function validateLitecoinBech32Address(address) {
|
|
169
|
+
let decoded;
|
|
170
|
+
let isBech32m = false;
|
|
171
|
+
try {
|
|
172
|
+
decoded = __scure_base.bech32.decode(address);
|
|
173
|
+
} catch {
|
|
174
|
+
try {
|
|
175
|
+
decoded = __scure_base.bech32m.decode(address);
|
|
176
|
+
isBech32m = true;
|
|
177
|
+
} catch {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (decoded.prefix.toLowerCase() !== "ltc") return false;
|
|
182
|
+
const { words } = decoded;
|
|
183
|
+
if (!words || words.length < 1) return false;
|
|
184
|
+
const version = words[0];
|
|
185
|
+
if (version == null || version < 0 || version > 16) return false;
|
|
186
|
+
const progLen = __scure_base.bech32.fromWords(words.slice(1)).length;
|
|
187
|
+
if (progLen < 2 || progLen > 40) return false;
|
|
188
|
+
if (version === 0) {
|
|
189
|
+
if (isBech32m) return false;
|
|
190
|
+
return progLen === 20 || progLen === 32;
|
|
191
|
+
}
|
|
192
|
+
if (version === 1) {
|
|
193
|
+
if (!isBech32m) return false;
|
|
194
|
+
return progLen === 32;
|
|
195
|
+
}
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
135
198
|
|
|
136
199
|
//#endregion
|
|
137
200
|
exports.validateAddress = validateAddress;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { Chains } from "./caip2.js";
|
|
2
2
|
import { utils } from "@defuse-protocol/internal-utils";
|
|
3
3
|
import { isAddress } from "viem";
|
|
4
|
-
import { sha256 } from "@noble/hashes/
|
|
4
|
+
import { sha256 } from "@noble/hashes/sha2";
|
|
5
5
|
import { base58, bech32, bech32m, hex } from "@scure/base";
|
|
6
6
|
import { PublicKey } from "@solana/web3.js";
|
|
7
7
|
import { isValidClassicAddress, isValidXAddress } from "ripple-address-codec";
|
|
8
8
|
|
|
9
9
|
//#region src/lib/validateAddress.ts
|
|
10
10
|
function validateAddress(address, blockchain) {
|
|
11
|
-
if (blockchain.startsWith("eip155:")) return validateEthAddress(address);
|
|
12
11
|
switch (blockchain) {
|
|
13
12
|
case Chains.Near: return utils.validateNearAddress(address);
|
|
14
13
|
case Chains.Bitcoin: return validateBtcAddress(address);
|
|
15
14
|
case Chains.Solana: return validateSolAddress(address);
|
|
16
15
|
case Chains.Dogecoin: return validateDogeAddress(address);
|
|
16
|
+
case Chains.Litecoin: return validateLitecoinAddress(address);
|
|
17
17
|
case Chains.XRPL: return validateXrpAddress(address);
|
|
18
18
|
case Chains.Zcash: return validateZcashAddress(address);
|
|
19
19
|
case Chains.Tron: return validateTronAddress(address);
|
|
@@ -22,6 +22,16 @@ function validateAddress(address, blockchain) {
|
|
|
22
22
|
case Chains.Stellar: return validateStellarAddress(address);
|
|
23
23
|
case Chains.Aptos: return validateAptosAddress(address);
|
|
24
24
|
case Chains.Cardano: return validateCardanoAddress(address);
|
|
25
|
+
case Chains.Ethereum:
|
|
26
|
+
case Chains.Optimism:
|
|
27
|
+
case Chains.BNB:
|
|
28
|
+
case Chains.Gnosis:
|
|
29
|
+
case Chains.Polygon:
|
|
30
|
+
case Chains.LayerX:
|
|
31
|
+
case Chains.Base:
|
|
32
|
+
case Chains.Arbitrum:
|
|
33
|
+
case Chains.Avalanche:
|
|
34
|
+
case Chains.Berachain: return validateEthAddress(address);
|
|
25
35
|
default: return false;
|
|
26
36
|
}
|
|
27
37
|
}
|
|
@@ -125,6 +135,59 @@ function validateCardanoAddress(address) {
|
|
|
125
135
|
return false;
|
|
126
136
|
}
|
|
127
137
|
}
|
|
138
|
+
function validateLitecoinAddress(address) {
|
|
139
|
+
const first = address[0];
|
|
140
|
+
if (first === "L") return validateLitecoinBase58Address(address, 48);
|
|
141
|
+
if (first === "M") return validateLitecoinBase58Address(address, 50);
|
|
142
|
+
if (first === "3") return validateLitecoinBase58Address(address, 5);
|
|
143
|
+
if (!address.toLowerCase().startsWith("ltc1")) return false;
|
|
144
|
+
return validateLitecoinBech32Address(address);
|
|
145
|
+
}
|
|
146
|
+
function validateLitecoinBase58Address(address, expectedVersion) {
|
|
147
|
+
let decoded;
|
|
148
|
+
try {
|
|
149
|
+
decoded = base58.decode(address);
|
|
150
|
+
} catch {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
if (decoded.length !== 25) return false;
|
|
154
|
+
if (decoded[0] !== expectedVersion) return false;
|
|
155
|
+
const payload = decoded.subarray(0, 21);
|
|
156
|
+
const checksum = decoded.subarray(21, 25);
|
|
157
|
+
const expectedChecksum = sha256(sha256(payload)).subarray(0, 4);
|
|
158
|
+
for (let i = 0; i < 4; i++) if (checksum[i] !== expectedChecksum[i]) return false;
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
function validateLitecoinBech32Address(address) {
|
|
162
|
+
let decoded;
|
|
163
|
+
let isBech32m = false;
|
|
164
|
+
try {
|
|
165
|
+
decoded = bech32.decode(address);
|
|
166
|
+
} catch {
|
|
167
|
+
try {
|
|
168
|
+
decoded = bech32m.decode(address);
|
|
169
|
+
isBech32m = true;
|
|
170
|
+
} catch {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (decoded.prefix.toLowerCase() !== "ltc") return false;
|
|
175
|
+
const { words } = decoded;
|
|
176
|
+
if (!words || words.length < 1) return false;
|
|
177
|
+
const version = words[0];
|
|
178
|
+
if (version == null || version < 0 || version > 16) return false;
|
|
179
|
+
const progLen = bech32.fromWords(words.slice(1)).length;
|
|
180
|
+
if (progLen < 2 || progLen > 40) return false;
|
|
181
|
+
if (version === 0) {
|
|
182
|
+
if (isBech32m) return false;
|
|
183
|
+
return progLen === 20 || progLen === 32;
|
|
184
|
+
}
|
|
185
|
+
if (version === 1) {
|
|
186
|
+
if (!isBech32m) return false;
|
|
187
|
+
return progLen === 32;
|
|
188
|
+
}
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
128
191
|
|
|
129
192
|
//#endregion
|
|
130
193
|
export { validateAddress };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defuse-protocol/intents-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"ripple-address-codec": "^5.0.0",
|
|
39
39
|
"valibot": "^1.0.0",
|
|
40
40
|
"viem": "^2.0.0",
|
|
41
|
-
"@defuse-protocol/
|
|
42
|
-
"@defuse-protocol/
|
|
41
|
+
"@defuse-protocol/internal-utils": "0.19.0",
|
|
42
|
+
"@defuse-protocol/contract-types": "0.3.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"tsdown": "0.15.5",
|