@defuse-protocol/intents-sdk 0.50.0 → 0.52.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.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/src/bridges/poa-bridge/poa-bridge-utils.cjs +4 -2
- package/dist/src/bridges/poa-bridge/poa-bridge-utils.js +4 -2
- package/dist/src/intents/intent-signer-impl/factories.d.cts +6 -7
- package/dist/src/intents/intent-signer-impl/factories.d.ts +6 -7
- package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.d.cts +9 -1
- package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.d.ts +9 -2
- package/dist/src/intents/intent-signer-impl/intent-signer-nep413.cjs +21 -14
- package/dist/src/intents/intent-signer-impl/intent-signer-nep413.d.cts +17 -1
- package/dist/src/intents/intent-signer-impl/intent-signer-nep413.d.ts +17 -1
- package/dist/src/intents/intent-signer-impl/intent-signer-nep413.js +21 -14
- package/dist/src/intents/intent-signer-impl/intent-signer-viem.cjs +13 -9
- package/dist/src/intents/intent-signer-impl/intent-signer-viem.d.cts +13 -1
- package/dist/src/intents/intent-signer-impl/intent-signer-viem.d.ts +13 -1
- package/dist/src/intents/intent-signer-impl/intent-signer-viem.js +13 -9
- package/dist/src/lib/caip2.cjs +2 -1
- package/dist/src/lib/caip2.d.cts +1 -0
- package/dist/src/lib/caip2.d.ts +1 -0
- package/dist/src/lib/caip2.js +2 -1
- package/dist/src/lib/validateAddress.cjs +149 -0
- package/dist/src/lib/validateAddress.js +149 -0
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -8,6 +8,8 @@ import { Chain, Chains } from "./src/lib/caip2.cjs";
|
|
|
8
8
|
import { BatchWithdrawalResult, FeeEstimation, HotBridgeRouteConfig, IntentPublishResult, IntentSettlementStatus, InternalTransferRouteConfig, NearTxInfo, NearWithdrawalRouteConfig, OmniBridgeRouteConfig, ParsedAssetInfo, PoaBridgeRouteConfig, ProcessWithdrawalArgs, RouteConfig, SignAndSendArgs, SignAndSendWithdrawalArgs, SignedIntentsComposition, TxInfo, TxNoInfo, VirtualChainRouteConfig, WithdrawalIdentifier, WithdrawalParams, WithdrawalResult } from "./src/shared-types.cjs";
|
|
9
9
|
import { IntentPayloadBuilder } from "./src/intents/intent-payload-builder.cjs";
|
|
10
10
|
import { IntentsSDK, IntentsSDKConfig } from "./src/sdk.cjs";
|
|
11
|
+
import { Nep413RawPayload } from "./src/intents/intent-signer-impl/intent-signer-nep413.cjs";
|
|
12
|
+
import { Erc191RawPayload } from "./src/intents/intent-signer-impl/intent-signer-viem.cjs";
|
|
11
13
|
import { createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem } from "./src/intents/intent-signer-impl/factories.cjs";
|
|
12
14
|
import { createDefaultRoute, createHotBridgeRoute, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute } from "./src/lib/route-config-factory.cjs";
|
|
13
15
|
import { POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE } from "./src/constants/poa-tokens-routable-through-omni-bridge.cjs";
|
|
@@ -19,4 +21,4 @@ import { InsufficientUtxoForOmniBridgeWithdrawalError, InsufficientUtxoForOmniBr
|
|
|
19
21
|
import { computeIntentHash } from "./src/intents/intent-hash.cjs";
|
|
20
22
|
import { validateAddress } from "./src/lib/validateAddress.cjs";
|
|
21
23
|
import { AssertionError, AssertionErrorType, BaseError, BaseErrorType, EnvConfig, HttpRequestError, HttpRequestErrorType, ILogger, IntentSettlementError, IntentSettlementErrorType, NearIntentsEnv, PoaWithdrawalInvariantError, PoaWithdrawalInvariantErrorType, PoaWithdrawalNotFoundError, PoaWithdrawalNotFoundErrorType, PoaWithdrawalPendingError, PoaWithdrawalPendingErrorType, QuoteError, QuoteErrorType, RelayPublishError, RelayPublishErrorType, RetryOptions, RpcEndpoint, RpcEndpointConfig, RpcRequestError, RpcRequestErrorType, TimeoutError, TimeoutErrorType } from "@defuse-protocol/internal-utils";
|
|
22
|
-
export { AssertionError, type AssertionErrorType, BaseError, type BaseErrorType, type BatchWithdrawalResult, BridgeNameEnum, type BridgeNameEnumValues, type Chain, Chains, DestinationExplicitNearAccountDoesntExistError, type DestinationExplicitNearAccountDoesntExistErrorType, type EnvConfig, type FeeEstimation, FeeExceedsAmountError, type FeeExceedsAmountErrorType, type HotBridgeRouteConfig, HotWithdrawalApiFeeRequestTimeoutError, type HotWithdrawalApiFeeRequestTimeoutErrorType, HotWithdrawalNotFoundError, type HotWithdrawalNotFoundErrorType, HttpRequestError, type HttpRequestErrorType, type IIntentSigner, type ILogger, InsufficientUtxoForOmniBridgeWithdrawalError, type InsufficientUtxoForOmniBridgeWithdrawalErrorType, type IntentPayload, IntentPayloadBuilder, type IntentPayloadFactory, type IntentPrimitive, type IntentPublishResult, type IntentRelayParamsFactory, IntentSettlementError, type IntentSettlementErrorType, type IntentSettlementStatus, IntentsNearOmniAvailableBalanceTooLowError, type IntentsNearOmniAvailableBalanceTooLowErrorType, IntentsSDK, type IntentsSDKConfig, type InternalTransferRouteConfig, InvalidFeeValueError, type InvalidFeeValueErrorType, MinWithdrawalAmountError, type MinWithdrawalAmountErrorType, type MultiPayload, type NearIntentsEnv, type NearTxInfo, type NearWithdrawalRouteConfig, type OmniBridgeRouteConfig, OmniWithdrawalApiFeeRequestTimeoutError, type OmniWithdrawalApiFeeRequestTimeoutErrorType, type OnBeforePublishIntentHook, POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE, 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, type RpcEndpoint, type RpcEndpointConfig, 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, WithdrawalFailedError, type WithdrawalFailedErrorType, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, WithdrawalWatchError, type WithdrawalWatchErrorType, computeIntentHash, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute, validateAddress as validateAddressFormat };
|
|
24
|
+
export { AssertionError, type AssertionErrorType, BaseError, type BaseErrorType, type BatchWithdrawalResult, BridgeNameEnum, type BridgeNameEnumValues, type Chain, Chains, DestinationExplicitNearAccountDoesntExistError, type DestinationExplicitNearAccountDoesntExistErrorType, type EnvConfig, type Erc191RawPayload, type FeeEstimation, FeeExceedsAmountError, type FeeExceedsAmountErrorType, type HotBridgeRouteConfig, HotWithdrawalApiFeeRequestTimeoutError, type HotWithdrawalApiFeeRequestTimeoutErrorType, HotWithdrawalNotFoundError, type HotWithdrawalNotFoundErrorType, HttpRequestError, type HttpRequestErrorType, type IIntentSigner, type ILogger, InsufficientUtxoForOmniBridgeWithdrawalError, type InsufficientUtxoForOmniBridgeWithdrawalErrorType, type IntentPayload, IntentPayloadBuilder, type IntentPayloadFactory, type IntentPrimitive, type IntentPublishResult, type IntentRelayParamsFactory, IntentSettlementError, type IntentSettlementErrorType, type IntentSettlementStatus, IntentsNearOmniAvailableBalanceTooLowError, type IntentsNearOmniAvailableBalanceTooLowErrorType, IntentsSDK, type IntentsSDKConfig, type InternalTransferRouteConfig, InvalidFeeValueError, type InvalidFeeValueErrorType, MinWithdrawalAmountError, type MinWithdrawalAmountErrorType, type MultiPayload, type NearIntentsEnv, type NearTxInfo, type NearWithdrawalRouteConfig, type Nep413RawPayload, type OmniBridgeRouteConfig, OmniWithdrawalApiFeeRequestTimeoutError, type OmniWithdrawalApiFeeRequestTimeoutErrorType, type OnBeforePublishIntentHook, POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE, 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, type RpcEndpoint, type RpcEndpointConfig, 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, WithdrawalFailedError, type WithdrawalFailedErrorType, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, WithdrawalWatchError, type WithdrawalWatchErrorType, computeIntentHash, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute, validateAddress as validateAddressFormat };
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ import { Chain, Chains } from "./src/lib/caip2.js";
|
|
|
8
8
|
import { BatchWithdrawalResult, FeeEstimation, HotBridgeRouteConfig, IntentPublishResult, IntentSettlementStatus, InternalTransferRouteConfig, NearTxInfo, NearWithdrawalRouteConfig, OmniBridgeRouteConfig, ParsedAssetInfo, PoaBridgeRouteConfig, ProcessWithdrawalArgs, RouteConfig, SignAndSendArgs, SignAndSendWithdrawalArgs, SignedIntentsComposition, TxInfo, TxNoInfo, VirtualChainRouteConfig, WithdrawalIdentifier, WithdrawalParams, WithdrawalResult } from "./src/shared-types.js";
|
|
9
9
|
import { IntentPayloadBuilder } from "./src/intents/intent-payload-builder.js";
|
|
10
10
|
import { IntentsSDK, IntentsSDKConfig } from "./src/sdk.js";
|
|
11
|
+
import { Nep413RawPayload } from "./src/intents/intent-signer-impl/intent-signer-nep413.js";
|
|
12
|
+
import { Erc191RawPayload } from "./src/intents/intent-signer-impl/intent-signer-viem.js";
|
|
11
13
|
import { createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem } from "./src/intents/intent-signer-impl/factories.js";
|
|
12
14
|
import { createDefaultRoute, createHotBridgeRoute, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute } from "./src/lib/route-config-factory.js";
|
|
13
15
|
import { POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE } from "./src/constants/poa-tokens-routable-through-omni-bridge.js";
|
|
@@ -19,4 +21,4 @@ import { InsufficientUtxoForOmniBridgeWithdrawalError, InsufficientUtxoForOmniBr
|
|
|
19
21
|
import { computeIntentHash } from "./src/intents/intent-hash.js";
|
|
20
22
|
import { validateAddress } from "./src/lib/validateAddress.js";
|
|
21
23
|
import { AssertionError, AssertionErrorType, BaseError, BaseErrorType, EnvConfig, HttpRequestError, HttpRequestErrorType, ILogger, IntentSettlementError, IntentSettlementErrorType, NearIntentsEnv, PoaWithdrawalInvariantError, PoaWithdrawalInvariantErrorType, PoaWithdrawalNotFoundError, PoaWithdrawalNotFoundErrorType, PoaWithdrawalPendingError, PoaWithdrawalPendingErrorType, QuoteError, QuoteErrorType, RelayPublishError, RelayPublishErrorType, RetryOptions, RpcEndpoint, RpcEndpointConfig, RpcRequestError, RpcRequestErrorType, TimeoutError, TimeoutErrorType } from "@defuse-protocol/internal-utils";
|
|
22
|
-
export { AssertionError, type AssertionErrorType, BaseError, type BaseErrorType, type BatchWithdrawalResult, BridgeNameEnum, type BridgeNameEnumValues, type Chain, Chains, DestinationExplicitNearAccountDoesntExistError, type DestinationExplicitNearAccountDoesntExistErrorType, type EnvConfig, type FeeEstimation, FeeExceedsAmountError, type FeeExceedsAmountErrorType, type HotBridgeRouteConfig, HotWithdrawalApiFeeRequestTimeoutError, type HotWithdrawalApiFeeRequestTimeoutErrorType, HotWithdrawalNotFoundError, type HotWithdrawalNotFoundErrorType, HttpRequestError, type HttpRequestErrorType, type IIntentSigner, type ILogger, InsufficientUtxoForOmniBridgeWithdrawalError, type InsufficientUtxoForOmniBridgeWithdrawalErrorType, type IntentPayload, IntentPayloadBuilder, type IntentPayloadFactory, type IntentPrimitive, type IntentPublishResult, type IntentRelayParamsFactory, IntentSettlementError, type IntentSettlementErrorType, type IntentSettlementStatus, IntentsNearOmniAvailableBalanceTooLowError, type IntentsNearOmniAvailableBalanceTooLowErrorType, IntentsSDK, type IntentsSDKConfig, type InternalTransferRouteConfig, InvalidFeeValueError, type InvalidFeeValueErrorType, MinWithdrawalAmountError, type MinWithdrawalAmountErrorType, type MultiPayload, type NearIntentsEnv, type NearTxInfo, type NearWithdrawalRouteConfig, type OmniBridgeRouteConfig, OmniWithdrawalApiFeeRequestTimeoutError, type OmniWithdrawalApiFeeRequestTimeoutErrorType, type OnBeforePublishIntentHook, POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE, 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, type RpcEndpoint, type RpcEndpointConfig, 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, WithdrawalFailedError, type WithdrawalFailedErrorType, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, WithdrawalWatchError, type WithdrawalWatchErrorType, computeIntentHash, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute, validateAddress as validateAddressFormat };
|
|
24
|
+
export { AssertionError, type AssertionErrorType, BaseError, type BaseErrorType, type BatchWithdrawalResult, BridgeNameEnum, type BridgeNameEnumValues, type Chain, Chains, DestinationExplicitNearAccountDoesntExistError, type DestinationExplicitNearAccountDoesntExistErrorType, type EnvConfig, type Erc191RawPayload, type FeeEstimation, FeeExceedsAmountError, type FeeExceedsAmountErrorType, type HotBridgeRouteConfig, HotWithdrawalApiFeeRequestTimeoutError, type HotWithdrawalApiFeeRequestTimeoutErrorType, HotWithdrawalNotFoundError, type HotWithdrawalNotFoundErrorType, HttpRequestError, type HttpRequestErrorType, type IIntentSigner, type ILogger, InsufficientUtxoForOmniBridgeWithdrawalError, type InsufficientUtxoForOmniBridgeWithdrawalErrorType, type IntentPayload, IntentPayloadBuilder, type IntentPayloadFactory, type IntentPrimitive, type IntentPublishResult, type IntentRelayParamsFactory, IntentSettlementError, type IntentSettlementErrorType, type IntentSettlementStatus, IntentsNearOmniAvailableBalanceTooLowError, type IntentsNearOmniAvailableBalanceTooLowErrorType, IntentsSDK, type IntentsSDKConfig, type InternalTransferRouteConfig, InvalidFeeValueError, type InvalidFeeValueErrorType, MinWithdrawalAmountError, type MinWithdrawalAmountErrorType, type MultiPayload, type NearIntentsEnv, type NearTxInfo, type NearWithdrawalRouteConfig, type Nep413RawPayload, type OmniBridgeRouteConfig, OmniWithdrawalApiFeeRequestTimeoutError, type OmniWithdrawalApiFeeRequestTimeoutErrorType, type OnBeforePublishIntentHook, POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE, 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, type RpcEndpoint, type RpcEndpointConfig, 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, WithdrawalFailedError, type WithdrawalFailedErrorType, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, WithdrawalWatchError, type WithdrawalWatchErrorType, computeIntentHash, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute, validateAddress as validateAddressFormat };
|
|
@@ -40,7 +40,8 @@ const caip2Mapping = {
|
|
|
40
40
|
[require_caip2.Chains.Aptos]: "aptos:mainnet",
|
|
41
41
|
[require_caip2.Chains.Cardano]: "cardano:mainnet",
|
|
42
42
|
[require_caip2.Chains.Litecoin]: "ltc:mainnet",
|
|
43
|
-
[require_caip2.Chains.Starknet]: "starknet:mainnet"
|
|
43
|
+
[require_caip2.Chains.Starknet]: "starknet:mainnet",
|
|
44
|
+
[require_caip2.Chains.Aleo]: "aleo:mainnet"
|
|
44
45
|
};
|
|
45
46
|
function toPoaNetwork(caip2) {
|
|
46
47
|
if (caip2Mapping[caip2] == null) throw new Error(`Unsupported POA Bridge chain = ${caip2}`);
|
|
@@ -63,7 +64,8 @@ const tokenPrefixMapping = {
|
|
|
63
64
|
aptos: require_caip2.Chains.Aptos,
|
|
64
65
|
cardano: require_caip2.Chains.Cardano,
|
|
65
66
|
ltc: require_caip2.Chains.Litecoin,
|
|
66
|
-
starknet: require_caip2.Chains.Starknet
|
|
67
|
+
starknet: require_caip2.Chains.Starknet,
|
|
68
|
+
aleo: require_caip2.Chains.Aleo
|
|
67
69
|
};
|
|
68
70
|
function contractIdToCaip2(contractId) {
|
|
69
71
|
for (const [prefix, caip2] of Object.entries(tokenPrefixMapping)) if (contractId.startsWith(`${prefix}.`) || contractId.startsWith(`${prefix}-`)) return caip2;
|
|
@@ -39,7 +39,8 @@ const caip2Mapping = {
|
|
|
39
39
|
[Chains.Aptos]: "aptos:mainnet",
|
|
40
40
|
[Chains.Cardano]: "cardano:mainnet",
|
|
41
41
|
[Chains.Litecoin]: "ltc:mainnet",
|
|
42
|
-
[Chains.Starknet]: "starknet:mainnet"
|
|
42
|
+
[Chains.Starknet]: "starknet:mainnet",
|
|
43
|
+
[Chains.Aleo]: "aleo:mainnet"
|
|
43
44
|
};
|
|
44
45
|
function toPoaNetwork(caip2) {
|
|
45
46
|
if (caip2Mapping[caip2] == null) throw new Error(`Unsupported POA Bridge chain = ${caip2}`);
|
|
@@ -62,7 +63,8 @@ const tokenPrefixMapping = {
|
|
|
62
63
|
aptos: Chains.Aptos,
|
|
63
64
|
cardano: Chains.Cardano,
|
|
64
65
|
ltc: Chains.Litecoin,
|
|
65
|
-
starknet: Chains.Starknet
|
|
66
|
+
starknet: Chains.Starknet,
|
|
67
|
+
aleo: Chains.Aleo
|
|
66
68
|
};
|
|
67
69
|
function contractIdToCaip2(contractId) {
|
|
68
70
|
for (const [prefix, caip2] of Object.entries(tokenPrefixMapping)) if (contractId.startsWith(`${prefix}.`) || contractId.startsWith(`${prefix}-`)) return caip2;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { IntentSignerViemConfig } from "./intent-signer-viem.cjs";
|
|
1
|
+
import { IntentSignerNEP413, IntentSignerNEP413Config } from "./intent-signer-nep413.cjs";
|
|
2
|
+
import { IntentSignerNearKeypair, IntentSignerNearKeypairConfig } from "./intent-signer-near-keypair.cjs";
|
|
3
|
+
import { IntentSignerViem, IntentSignerViemConfig } from "./intent-signer-viem.cjs";
|
|
5
4
|
|
|
6
5
|
//#region src/intents/intent-signer-impl/factories.d.ts
|
|
7
|
-
declare function createIntentSignerNEP413(config: IntentSignerNEP413Config):
|
|
8
|
-
declare function createIntentSignerNearKeyPair(config: IntentSignerNearKeypairConfig):
|
|
9
|
-
declare function createIntentSignerViem(config: IntentSignerViemConfig):
|
|
6
|
+
declare function createIntentSignerNEP413(config: IntentSignerNEP413Config): IntentSignerNEP413;
|
|
7
|
+
declare function createIntentSignerNearKeyPair(config: IntentSignerNearKeypairConfig): IntentSignerNearKeypair;
|
|
8
|
+
declare function createIntentSignerViem(config: IntentSignerViemConfig): IntentSignerViem;
|
|
10
9
|
//#endregion
|
|
11
10
|
export { createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem };
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { IntentSignerViemConfig } from "./intent-signer-viem.js";
|
|
1
|
+
import { IntentSignerNEP413, IntentSignerNEP413Config } from "./intent-signer-nep413.js";
|
|
2
|
+
import { IntentSignerNearKeypair, IntentSignerNearKeypairConfig } from "./intent-signer-near-keypair.js";
|
|
3
|
+
import { IntentSignerViem, IntentSignerViemConfig } from "./intent-signer-viem.js";
|
|
5
4
|
|
|
6
5
|
//#region src/intents/intent-signer-impl/factories.d.ts
|
|
7
|
-
declare function createIntentSignerNEP413(config: IntentSignerNEP413Config):
|
|
8
|
-
declare function createIntentSignerNearKeyPair(config: IntentSignerNearKeypairConfig):
|
|
9
|
-
declare function createIntentSignerViem(config: IntentSignerViemConfig):
|
|
6
|
+
declare function createIntentSignerNEP413(config: IntentSignerNEP413Config): IntentSignerNEP413;
|
|
7
|
+
declare function createIntentSignerNearKeyPair(config: IntentSignerNearKeypairConfig): IntentSignerNearKeypair;
|
|
8
|
+
declare function createIntentSignerViem(config: IntentSignerViemConfig): IntentSignerViem;
|
|
10
9
|
//#endregion
|
|
11
10
|
export { createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { IIntentSigner } from "../interfaces/intent-signer.cjs";
|
|
2
|
+
import { IntentSignerNEP413 } from "./intent-signer-nep413.cjs";
|
|
1
3
|
import * as near_api_js0 from "near-api-js";
|
|
2
4
|
|
|
3
5
|
//#region src/intents/intent-signer-impl/intent-signer-near-keypair.d.ts
|
|
@@ -11,5 +13,11 @@ interface IntentSignerNearKeypairConfig {
|
|
|
11
13
|
*/
|
|
12
14
|
accountId: string;
|
|
13
15
|
}
|
|
16
|
+
declare class IntentSignerNearKeypair extends IntentSignerNEP413 implements IIntentSigner {
|
|
17
|
+
constructor({
|
|
18
|
+
signer,
|
|
19
|
+
accountId
|
|
20
|
+
}: IntentSignerNearKeypairConfig);
|
|
21
|
+
}
|
|
14
22
|
//#endregion
|
|
15
|
-
export { IntentSignerNearKeypairConfig };
|
|
23
|
+
export { IntentSignerNearKeypair, IntentSignerNearKeypairConfig };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import "
|
|
1
|
+
import { IIntentSigner } from "../interfaces/intent-signer.js";
|
|
2
|
+
import { IntentSignerNEP413 } from "./intent-signer-nep413.js";
|
|
2
3
|
import * as near_api_js0 from "near-api-js";
|
|
3
4
|
|
|
4
5
|
//#region src/intents/intent-signer-impl/intent-signer-near-keypair.d.ts
|
|
@@ -12,5 +13,11 @@ interface IntentSignerNearKeypairConfig {
|
|
|
12
13
|
*/
|
|
13
14
|
accountId: string;
|
|
14
15
|
}
|
|
16
|
+
declare class IntentSignerNearKeypair extends IntentSignerNEP413 implements IIntentSigner {
|
|
17
|
+
constructor({
|
|
18
|
+
signer,
|
|
19
|
+
accountId
|
|
20
|
+
}: IntentSignerNearKeypairConfig);
|
|
21
|
+
}
|
|
15
22
|
//#endregion
|
|
16
|
-
export { IntentSignerNearKeypairConfig };
|
|
23
|
+
export { IntentSignerNearKeypair, IntentSignerNearKeypairConfig };
|
|
@@ -5,32 +5,39 @@ let _scure_base = require("@scure/base");
|
|
|
5
5
|
//#region src/intents/intent-signer-impl/intent-signer-nep413.ts
|
|
6
6
|
var IntentSignerNEP413 = class {
|
|
7
7
|
constructor({ signMessage, accountId }) {
|
|
8
|
-
this.
|
|
8
|
+
this.standard = "nep413";
|
|
9
|
+
this.signMessageFn = signMessage;
|
|
9
10
|
this.accountId = accountId;
|
|
10
11
|
}
|
|
11
|
-
async
|
|
12
|
+
async signRaw(input) {
|
|
12
13
|
const nep413Payload = {
|
|
13
|
-
|
|
14
|
-
nonce: Array.from(_scure_base.base64.decode(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
intents: intent.intents,
|
|
18
|
-
signer_id: intent.signer_id ?? this.accountId
|
|
19
|
-
})
|
|
14
|
+
message: input.payload.message,
|
|
15
|
+
nonce: Array.from(_scure_base.base64.decode(input.payload.nonce)),
|
|
16
|
+
recipient: input.payload.recipient,
|
|
17
|
+
callback_url: input.payload.callbackUrl
|
|
20
18
|
};
|
|
21
19
|
const nep413Hash = await require_nep413.hashNEP413Message(nep413Payload);
|
|
22
|
-
const { publicKey, signature } = await this.
|
|
20
|
+
const { publicKey, signature } = await this.signMessageFn(nep413Payload, nep413Hash);
|
|
23
21
|
const signatureFormatted = signature.startsWith("ed25519:") ? signature : `ed25519:${_scure_base.base58.encode(_scure_base.base64.decode(signature))}`;
|
|
24
22
|
return {
|
|
25
23
|
standard: "nep413",
|
|
26
|
-
payload:
|
|
27
|
-
...nep413Payload,
|
|
28
|
-
nonce: intent.nonce
|
|
29
|
-
},
|
|
24
|
+
payload: input.payload,
|
|
30
25
|
public_key: publicKey,
|
|
31
26
|
signature: signatureFormatted
|
|
32
27
|
};
|
|
33
28
|
}
|
|
29
|
+
/** Builds payload from IntentPayload and signs it via signRaw() */
|
|
30
|
+
async signIntent(intent) {
|
|
31
|
+
return this.signRaw({ payload: {
|
|
32
|
+
message: JSON.stringify({
|
|
33
|
+
deadline: intent.deadline,
|
|
34
|
+
intents: intent.intents,
|
|
35
|
+
signer_id: intent.signer_id ?? this.accountId
|
|
36
|
+
}),
|
|
37
|
+
nonce: intent.nonce,
|
|
38
|
+
recipient: intent.verifying_contract
|
|
39
|
+
} });
|
|
40
|
+
}
|
|
34
41
|
};
|
|
35
42
|
|
|
36
43
|
//#endregion
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { IntentPayload } from "../shared-types.cjs";
|
|
2
|
+
import { IIntentSigner } from "../interfaces/intent-signer.cjs";
|
|
1
3
|
import { NEP413Payload } from "../../lib/nep413.cjs";
|
|
4
|
+
import { MultiPayloadNep413 } from "@defuse-protocol/contract-types";
|
|
2
5
|
|
|
3
6
|
//#region src/intents/intent-signer-impl/intent-signer-nep413.d.ts
|
|
7
|
+
type Nep413RawPayload = Pick<MultiPayloadNep413, "payload">;
|
|
4
8
|
type MaybePromise<T> = T | Promise<T>;
|
|
5
9
|
type SignMessageNEP413 = (nep413Payload: NEP413Payload, nep413Hash: Uint8Array) => MaybePromise<{
|
|
6
10
|
publicKey: string;
|
|
@@ -10,5 +14,17 @@ interface IntentSignerNEP413Config {
|
|
|
10
14
|
signMessage: SignMessageNEP413;
|
|
11
15
|
accountId: string;
|
|
12
16
|
}
|
|
17
|
+
declare class IntentSignerNEP413 implements IIntentSigner {
|
|
18
|
+
readonly standard: "nep413";
|
|
19
|
+
private signMessageFn;
|
|
20
|
+
protected accountId: string;
|
|
21
|
+
constructor({
|
|
22
|
+
signMessage,
|
|
23
|
+
accountId
|
|
24
|
+
}: IntentSignerNEP413Config);
|
|
25
|
+
signRaw(input: Nep413RawPayload): Promise<MultiPayloadNep413>;
|
|
26
|
+
/** Builds payload from IntentPayload and signs it via signRaw() */
|
|
27
|
+
signIntent(intent: IntentPayload): Promise<MultiPayloadNep413>;
|
|
28
|
+
}
|
|
13
29
|
//#endregion
|
|
14
|
-
export { IntentSignerNEP413Config };
|
|
30
|
+
export { IntentSignerNEP413, IntentSignerNEP413Config, Nep413RawPayload };
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { IntentPayload } from "../shared-types.js";
|
|
2
|
+
import { IIntentSigner } from "../interfaces/intent-signer.js";
|
|
1
3
|
import { NEP413Payload } from "../../lib/nep413.js";
|
|
4
|
+
import { MultiPayloadNep413 } from "@defuse-protocol/contract-types";
|
|
2
5
|
|
|
3
6
|
//#region src/intents/intent-signer-impl/intent-signer-nep413.d.ts
|
|
7
|
+
type Nep413RawPayload = Pick<MultiPayloadNep413, "payload">;
|
|
4
8
|
type MaybePromise<T> = T | Promise<T>;
|
|
5
9
|
type SignMessageNEP413 = (nep413Payload: NEP413Payload, nep413Hash: Uint8Array) => MaybePromise<{
|
|
6
10
|
publicKey: string;
|
|
@@ -10,5 +14,17 @@ interface IntentSignerNEP413Config {
|
|
|
10
14
|
signMessage: SignMessageNEP413;
|
|
11
15
|
accountId: string;
|
|
12
16
|
}
|
|
17
|
+
declare class IntentSignerNEP413 implements IIntentSigner {
|
|
18
|
+
readonly standard: "nep413";
|
|
19
|
+
private signMessageFn;
|
|
20
|
+
protected accountId: string;
|
|
21
|
+
constructor({
|
|
22
|
+
signMessage,
|
|
23
|
+
accountId
|
|
24
|
+
}: IntentSignerNEP413Config);
|
|
25
|
+
signRaw(input: Nep413RawPayload): Promise<MultiPayloadNep413>;
|
|
26
|
+
/** Builds payload from IntentPayload and signs it via signRaw() */
|
|
27
|
+
signIntent(intent: IntentPayload): Promise<MultiPayloadNep413>;
|
|
28
|
+
}
|
|
13
29
|
//#endregion
|
|
14
|
-
export { IntentSignerNEP413Config };
|
|
30
|
+
export { IntentSignerNEP413, IntentSignerNEP413Config, Nep413RawPayload };
|
|
@@ -4,32 +4,39 @@ import { base58, base64 } from "@scure/base";
|
|
|
4
4
|
//#region src/intents/intent-signer-impl/intent-signer-nep413.ts
|
|
5
5
|
var IntentSignerNEP413 = class {
|
|
6
6
|
constructor({ signMessage, accountId }) {
|
|
7
|
-
this.
|
|
7
|
+
this.standard = "nep413";
|
|
8
|
+
this.signMessageFn = signMessage;
|
|
8
9
|
this.accountId = accountId;
|
|
9
10
|
}
|
|
10
|
-
async
|
|
11
|
+
async signRaw(input) {
|
|
11
12
|
const nep413Payload = {
|
|
12
|
-
|
|
13
|
-
nonce: Array.from(base64.decode(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
intents: intent.intents,
|
|
17
|
-
signer_id: intent.signer_id ?? this.accountId
|
|
18
|
-
})
|
|
13
|
+
message: input.payload.message,
|
|
14
|
+
nonce: Array.from(base64.decode(input.payload.nonce)),
|
|
15
|
+
recipient: input.payload.recipient,
|
|
16
|
+
callback_url: input.payload.callbackUrl
|
|
19
17
|
};
|
|
20
18
|
const nep413Hash = await hashNEP413Message(nep413Payload);
|
|
21
|
-
const { publicKey, signature } = await this.
|
|
19
|
+
const { publicKey, signature } = await this.signMessageFn(nep413Payload, nep413Hash);
|
|
22
20
|
const signatureFormatted = signature.startsWith("ed25519:") ? signature : `ed25519:${base58.encode(base64.decode(signature))}`;
|
|
23
21
|
return {
|
|
24
22
|
standard: "nep413",
|
|
25
|
-
payload:
|
|
26
|
-
...nep413Payload,
|
|
27
|
-
nonce: intent.nonce
|
|
28
|
-
},
|
|
23
|
+
payload: input.payload,
|
|
29
24
|
public_key: publicKey,
|
|
30
25
|
signature: signatureFormatted
|
|
31
26
|
};
|
|
32
27
|
}
|
|
28
|
+
/** Builds payload from IntentPayload and signs it via signRaw() */
|
|
29
|
+
async signIntent(intent) {
|
|
30
|
+
return this.signRaw({ payload: {
|
|
31
|
+
message: JSON.stringify({
|
|
32
|
+
deadline: intent.deadline,
|
|
33
|
+
intents: intent.intents,
|
|
34
|
+
signer_id: intent.signer_id ?? this.accountId
|
|
35
|
+
}),
|
|
36
|
+
nonce: intent.nonce,
|
|
37
|
+
recipient: intent.verifying_contract
|
|
38
|
+
} });
|
|
39
|
+
}
|
|
33
40
|
};
|
|
34
41
|
|
|
35
42
|
//#endregion
|
|
@@ -5,9 +5,20 @@ let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils")
|
|
|
5
5
|
var IntentSignerViem = class {
|
|
6
6
|
constructor(config) {
|
|
7
7
|
this.config = config;
|
|
8
|
+
this.standard = "erc191";
|
|
8
9
|
}
|
|
10
|
+
async signRaw(input) {
|
|
11
|
+
const signature = await this.config.signer.signMessage?.({ message: input.payload });
|
|
12
|
+
if (signature == null) throw new Error("No signature is returned");
|
|
13
|
+
return {
|
|
14
|
+
standard: "erc191",
|
|
15
|
+
payload: input.payload,
|
|
16
|
+
signature: _defuse_protocol_internal_utils.utils.transformERC191Signature(signature)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** Builds payload from IntentPayload and signs it via signRaw() */
|
|
9
20
|
async signIntent(intent) {
|
|
10
|
-
|
|
21
|
+
return this.signRaw({ payload: JSON.stringify({
|
|
11
22
|
signer_id: intent.signer_id ?? this.config.accountId ?? _defuse_protocol_internal_utils.utils.authHandleToIntentsUserId({
|
|
12
23
|
identifier: this.config.signer.address,
|
|
13
24
|
method: "evm"
|
|
@@ -16,14 +27,7 @@ var IntentSignerViem = class {
|
|
|
16
27
|
deadline: intent.deadline,
|
|
17
28
|
nonce: intent.nonce,
|
|
18
29
|
intents: intent.intents
|
|
19
|
-
});
|
|
20
|
-
const signature = await this.config.signer.signMessage?.({ message: payload });
|
|
21
|
-
if (signature == null) throw new Error("No signature is returned");
|
|
22
|
-
return {
|
|
23
|
-
standard: "erc191",
|
|
24
|
-
payload,
|
|
25
|
-
signature: _defuse_protocol_internal_utils.utils.transformERC191Signature(signature)
|
|
26
|
-
};
|
|
30
|
+
}) });
|
|
27
31
|
}
|
|
28
32
|
};
|
|
29
33
|
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { IntentPayload } from "../shared-types.cjs";
|
|
2
|
+
import { IIntentSigner } from "../interfaces/intent-signer.cjs";
|
|
3
|
+
import { MultiPayloadErc191 } from "@defuse-protocol/contract-types";
|
|
1
4
|
import { Account } from "viem";
|
|
2
5
|
|
|
3
6
|
//#region src/intents/intent-signer-impl/intent-signer-viem.d.ts
|
|
7
|
+
type Erc191RawPayload = Pick<MultiPayloadErc191, "payload">;
|
|
4
8
|
type IntentSignerViemConfig = {
|
|
5
9
|
/**
|
|
6
10
|
* Instance of viem's Account type
|
|
@@ -13,5 +17,13 @@ type IntentSignerViemConfig = {
|
|
|
13
17
|
*/
|
|
14
18
|
accountId?: string;
|
|
15
19
|
};
|
|
20
|
+
declare class IntentSignerViem implements IIntentSigner {
|
|
21
|
+
private config;
|
|
22
|
+
readonly standard: "erc191";
|
|
23
|
+
constructor(config: IntentSignerViemConfig);
|
|
24
|
+
signRaw(input: Erc191RawPayload): Promise<MultiPayloadErc191>;
|
|
25
|
+
/** Builds payload from IntentPayload and signs it via signRaw() */
|
|
26
|
+
signIntent(intent: IntentPayload): Promise<MultiPayloadErc191>;
|
|
27
|
+
}
|
|
16
28
|
//#endregion
|
|
17
|
-
export { IntentSignerViemConfig };
|
|
29
|
+
export { Erc191RawPayload, IntentSignerViem, IntentSignerViemConfig };
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { IntentPayload } from "../shared-types.js";
|
|
2
|
+
import { IIntentSigner } from "../interfaces/intent-signer.js";
|
|
1
3
|
import { Account } from "viem";
|
|
4
|
+
import { MultiPayloadErc191 } from "@defuse-protocol/contract-types";
|
|
2
5
|
|
|
3
6
|
//#region src/intents/intent-signer-impl/intent-signer-viem.d.ts
|
|
7
|
+
type Erc191RawPayload = Pick<MultiPayloadErc191, "payload">;
|
|
4
8
|
type IntentSignerViemConfig = {
|
|
5
9
|
/**
|
|
6
10
|
* Instance of viem's Account type
|
|
@@ -13,5 +17,13 @@ type IntentSignerViemConfig = {
|
|
|
13
17
|
*/
|
|
14
18
|
accountId?: string;
|
|
15
19
|
};
|
|
20
|
+
declare class IntentSignerViem implements IIntentSigner {
|
|
21
|
+
private config;
|
|
22
|
+
readonly standard: "erc191";
|
|
23
|
+
constructor(config: IntentSignerViemConfig);
|
|
24
|
+
signRaw(input: Erc191RawPayload): Promise<MultiPayloadErc191>;
|
|
25
|
+
/** Builds payload from IntentPayload and signs it via signRaw() */
|
|
26
|
+
signIntent(intent: IntentPayload): Promise<MultiPayloadErc191>;
|
|
27
|
+
}
|
|
16
28
|
//#endregion
|
|
17
|
-
export { IntentSignerViemConfig };
|
|
29
|
+
export { Erc191RawPayload, IntentSignerViem, IntentSignerViemConfig };
|
|
@@ -4,9 +4,20 @@ import { utils } from "@defuse-protocol/internal-utils";
|
|
|
4
4
|
var IntentSignerViem = class {
|
|
5
5
|
constructor(config) {
|
|
6
6
|
this.config = config;
|
|
7
|
+
this.standard = "erc191";
|
|
7
8
|
}
|
|
9
|
+
async signRaw(input) {
|
|
10
|
+
const signature = await this.config.signer.signMessage?.({ message: input.payload });
|
|
11
|
+
if (signature == null) throw new Error("No signature is returned");
|
|
12
|
+
return {
|
|
13
|
+
standard: "erc191",
|
|
14
|
+
payload: input.payload,
|
|
15
|
+
signature: utils.transformERC191Signature(signature)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** Builds payload from IntentPayload and signs it via signRaw() */
|
|
8
19
|
async signIntent(intent) {
|
|
9
|
-
|
|
20
|
+
return this.signRaw({ payload: JSON.stringify({
|
|
10
21
|
signer_id: intent.signer_id ?? this.config.accountId ?? utils.authHandleToIntentsUserId({
|
|
11
22
|
identifier: this.config.signer.address,
|
|
12
23
|
method: "evm"
|
|
@@ -15,14 +26,7 @@ var IntentSignerViem = class {
|
|
|
15
26
|
deadline: intent.deadline,
|
|
16
27
|
nonce: intent.nonce,
|
|
17
28
|
intents: intent.intents
|
|
18
|
-
});
|
|
19
|
-
const signature = await this.config.signer.signMessage?.({ message: payload });
|
|
20
|
-
if (signature == null) throw new Error("No signature is returned");
|
|
21
|
-
return {
|
|
22
|
-
standard: "erc191",
|
|
23
|
-
payload,
|
|
24
|
-
signature: utils.transformERC191Signature(signature)
|
|
25
|
-
};
|
|
29
|
+
}) });
|
|
26
30
|
}
|
|
27
31
|
};
|
|
28
32
|
|
package/dist/src/lib/caip2.cjs
CHANGED
|
@@ -34,7 +34,8 @@ const Chains = {
|
|
|
34
34
|
Cardano: "cip34:1-764824073",
|
|
35
35
|
Starknet: "starknet:SN_MAIN",
|
|
36
36
|
Plasma: "eip155:9745",
|
|
37
|
-
Scroll: "eip155:534352"
|
|
37
|
+
Scroll: "eip155:534352",
|
|
38
|
+
Aleo: "aleo:0"
|
|
38
39
|
};
|
|
39
40
|
function getEIP155ChainId(chain) {
|
|
40
41
|
(0, _defuse_protocol_internal_utils.assert)(chain.startsWith("eip155:"), "Chain is not an EIP-155 chain");
|
package/dist/src/lib/caip2.d.cts
CHANGED
package/dist/src/lib/caip2.d.ts
CHANGED
package/dist/src/lib/caip2.js
CHANGED
|
@@ -33,7 +33,8 @@ const Chains = {
|
|
|
33
33
|
Cardano: "cip34:1-764824073",
|
|
34
34
|
Starknet: "starknet:SN_MAIN",
|
|
35
35
|
Plasma: "eip155:9745",
|
|
36
|
-
Scroll: "eip155:534352"
|
|
36
|
+
Scroll: "eip155:534352",
|
|
37
|
+
Aleo: "aleo:0"
|
|
37
38
|
};
|
|
38
39
|
function getEIP155ChainId(chain) {
|
|
39
40
|
assert(chain.startsWith("eip155:"), "Chain is not an EIP-155 chain");
|
|
@@ -46,6 +46,7 @@ function validateAddress(address, blockchain) {
|
|
|
46
46
|
case require_caip2.Chains.Berachain:
|
|
47
47
|
case require_caip2.Chains.Plasma:
|
|
48
48
|
case require_caip2.Chains.Scroll: return validateEthAddress(address);
|
|
49
|
+
case require_caip2.Chains.Aleo: return validateAleoAddress(address);
|
|
49
50
|
default: return false;
|
|
50
51
|
}
|
|
51
52
|
}
|
|
@@ -266,6 +267,154 @@ function validateLitecoinBech32Address(address) {
|
|
|
266
267
|
}
|
|
267
268
|
return false;
|
|
268
269
|
}
|
|
270
|
+
/** Base field modulus (= scalar field order of BLS12-377). */
|
|
271
|
+
const P = 8444461749428370424248824938781546531375899335154063827935233455917409239041n;
|
|
272
|
+
/** Edwards curve coefficient d. Curve: -x² + y² = 1 + d·x²·y² (a = -1). */
|
|
273
|
+
const D = 3021n;
|
|
274
|
+
/** Prime-order subgroup order (= scalar field of Edwards BLS12-377, cofactor = 4). */
|
|
275
|
+
const SUBGROUP_ORDER = 2111115437357092606062206234695386632838870926408408195193685246394721360383n;
|
|
276
|
+
function modPow(base, exp, m) {
|
|
277
|
+
let result = 1n;
|
|
278
|
+
base = (base % m + m) % m;
|
|
279
|
+
while (exp > 0n) {
|
|
280
|
+
if (exp & 1n) result = result * base % m;
|
|
281
|
+
exp >>= 1n;
|
|
282
|
+
base = base * base % m;
|
|
283
|
+
}
|
|
284
|
+
return result;
|
|
285
|
+
}
|
|
286
|
+
/** Tonelli-Shanks square root in F_P. Returns null when n is a non-residue. */
|
|
287
|
+
function modSqrt(n) {
|
|
288
|
+
n = (n % P + P) % P;
|
|
289
|
+
if (n === 0n) return 0n;
|
|
290
|
+
if (modPow(n, (P - 1n) / 2n, P) !== 1n) return null;
|
|
291
|
+
let s = 0;
|
|
292
|
+
let q = P - 1n;
|
|
293
|
+
while ((q & 1n) === 0n) {
|
|
294
|
+
s++;
|
|
295
|
+
q >>= 1n;
|
|
296
|
+
}
|
|
297
|
+
let z = 2n;
|
|
298
|
+
while (modPow(z, (P - 1n) / 2n, P) !== P - 1n) z++;
|
|
299
|
+
let m = s;
|
|
300
|
+
let c = modPow(z, q, P);
|
|
301
|
+
let t = modPow(n, q, P);
|
|
302
|
+
let r = modPow(n, (q + 1n) / 2n, P);
|
|
303
|
+
for (;;) {
|
|
304
|
+
if (t === 1n) return r;
|
|
305
|
+
let i = 1;
|
|
306
|
+
let tmp = t * t % P;
|
|
307
|
+
while (tmp !== 1n) {
|
|
308
|
+
tmp = tmp * tmp % P;
|
|
309
|
+
i++;
|
|
310
|
+
}
|
|
311
|
+
let b = c;
|
|
312
|
+
for (let j = 0; j < m - i - 1; j++) b = b * b % P;
|
|
313
|
+
m = i;
|
|
314
|
+
c = b * b % P;
|
|
315
|
+
t = t * c % P;
|
|
316
|
+
r = r * b % P;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
const EXT_ZERO = [
|
|
320
|
+
0n,
|
|
321
|
+
1n,
|
|
322
|
+
0n,
|
|
323
|
+
1n
|
|
324
|
+
];
|
|
325
|
+
function extAdd(a, b) {
|
|
326
|
+
const [X1, Y1, T1, Z1] = a;
|
|
327
|
+
const [X2, Y2, T2, Z2] = b;
|
|
328
|
+
const A = X1 * X2 % P;
|
|
329
|
+
const B = Y1 * Y2 % P;
|
|
330
|
+
const C = T1 * D % P * T2 % P;
|
|
331
|
+
const Dd = Z1 * Z2 % P;
|
|
332
|
+
const E = ((X1 + Y1) % P * ((X2 + Y2) % P) % P - A - B + 2n * P) % P;
|
|
333
|
+
const F = ((Dd - C) % P + P) % P;
|
|
334
|
+
const G = (Dd + C) % P;
|
|
335
|
+
const H = (B + A) % P;
|
|
336
|
+
return [
|
|
337
|
+
E * F % P,
|
|
338
|
+
G * H % P,
|
|
339
|
+
E * H % P,
|
|
340
|
+
F * G % P
|
|
341
|
+
];
|
|
342
|
+
}
|
|
343
|
+
function extDouble(a) {
|
|
344
|
+
const [X, Y, _T, Z] = a;
|
|
345
|
+
const A = X * X % P;
|
|
346
|
+
const B = Y * Y % P;
|
|
347
|
+
const C = 2n * (Z * Z % P) % P;
|
|
348
|
+
const Dd = (P - A) % P;
|
|
349
|
+
const E = ((X + Y) % P * ((X + Y) % P) % P - A - B + 2n * P) % P;
|
|
350
|
+
const G = (Dd + B) % P;
|
|
351
|
+
const F = ((G - C) % P + P) % P;
|
|
352
|
+
const H = ((Dd - B) % P + P) % P;
|
|
353
|
+
return [
|
|
354
|
+
E * F % P,
|
|
355
|
+
G * H % P,
|
|
356
|
+
E * H % P,
|
|
357
|
+
F * G % P
|
|
358
|
+
];
|
|
359
|
+
}
|
|
360
|
+
function scalarMul(pt, scalar) {
|
|
361
|
+
let result = EXT_ZERO;
|
|
362
|
+
let base = pt;
|
|
363
|
+
let s = scalar;
|
|
364
|
+
while (s > 0n) {
|
|
365
|
+
if (s & 1n) result = extAdd(result, base);
|
|
366
|
+
base = extDouble(base);
|
|
367
|
+
s >>= 1n;
|
|
368
|
+
}
|
|
369
|
+
return result;
|
|
370
|
+
}
|
|
371
|
+
/** Check whether an extended point is the identity (0, 1). */
|
|
372
|
+
function isIdentity(pt) {
|
|
373
|
+
return pt[0] === 0n && pt[1] === pt[3];
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Validates an Aleo address by decoding the bech32m payload, decompressing
|
|
377
|
+
* the Edwards BLS12-377 point, and verifying it lies in the prime-order
|
|
378
|
+
* subgroup — matching snarkVM's `Group::from_x_coordinate` exactly.
|
|
379
|
+
*
|
|
380
|
+
* Compressed format: x-coordinate (little-endian, 32 bytes) with y-sign
|
|
381
|
+
* flag in bit 7 of byte 31.
|
|
382
|
+
*/
|
|
383
|
+
function validateAleoAddress(address) {
|
|
384
|
+
try {
|
|
385
|
+
const decoded = _scure_base.bech32m.decodeToBytes(address);
|
|
386
|
+
if (decoded.prefix !== "aleo") return false;
|
|
387
|
+
if (decoded.bytes.length !== 32) return false;
|
|
388
|
+
const bytes = new Uint8Array(decoded.bytes);
|
|
389
|
+
bytes[31] = bytes[31] & 127;
|
|
390
|
+
let x = 0n;
|
|
391
|
+
for (let i = 31; i >= 0; i--) x = x << 8n | BigInt(bytes[i]);
|
|
392
|
+
if (x >= P) return false;
|
|
393
|
+
const x2 = x * x % P;
|
|
394
|
+
const num = (1n + x2) % P;
|
|
395
|
+
const den = ((1n - D * x2 % P) % P + P) % P;
|
|
396
|
+
if (den === 0n) return false;
|
|
397
|
+
const y = modSqrt(num * modPow(den, P - 2n, P) % P);
|
|
398
|
+
if (y === null) return false;
|
|
399
|
+
const negY = y === 0n ? 0n : P - y;
|
|
400
|
+
const p1 = [
|
|
401
|
+
x,
|
|
402
|
+
y,
|
|
403
|
+
x * y % P,
|
|
404
|
+
1n
|
|
405
|
+
];
|
|
406
|
+
const p2 = [
|
|
407
|
+
x,
|
|
408
|
+
negY,
|
|
409
|
+
x * negY % P,
|
|
410
|
+
1n
|
|
411
|
+
];
|
|
412
|
+
for (const pt of [p1, p2]) if (isIdentity(scalarMul(pt, SUBGROUP_ORDER))) return true;
|
|
413
|
+
return false;
|
|
414
|
+
} catch {
|
|
415
|
+
return false;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
269
418
|
|
|
270
419
|
//#endregion
|
|
271
420
|
exports.validateAddress = validateAddress;
|
|
@@ -45,6 +45,7 @@ function validateAddress(address, blockchain) {
|
|
|
45
45
|
case Chains.Berachain:
|
|
46
46
|
case Chains.Plasma:
|
|
47
47
|
case Chains.Scroll: return validateEthAddress(address);
|
|
48
|
+
case Chains.Aleo: return validateAleoAddress(address);
|
|
48
49
|
default: return false;
|
|
49
50
|
}
|
|
50
51
|
}
|
|
@@ -265,6 +266,154 @@ function validateLitecoinBech32Address(address) {
|
|
|
265
266
|
}
|
|
266
267
|
return false;
|
|
267
268
|
}
|
|
269
|
+
/** Base field modulus (= scalar field order of BLS12-377). */
|
|
270
|
+
const P = 8444461749428370424248824938781546531375899335154063827935233455917409239041n;
|
|
271
|
+
/** Edwards curve coefficient d. Curve: -x² + y² = 1 + d·x²·y² (a = -1). */
|
|
272
|
+
const D = 3021n;
|
|
273
|
+
/** Prime-order subgroup order (= scalar field of Edwards BLS12-377, cofactor = 4). */
|
|
274
|
+
const SUBGROUP_ORDER = 2111115437357092606062206234695386632838870926408408195193685246394721360383n;
|
|
275
|
+
function modPow(base, exp, m) {
|
|
276
|
+
let result = 1n;
|
|
277
|
+
base = (base % m + m) % m;
|
|
278
|
+
while (exp > 0n) {
|
|
279
|
+
if (exp & 1n) result = result * base % m;
|
|
280
|
+
exp >>= 1n;
|
|
281
|
+
base = base * base % m;
|
|
282
|
+
}
|
|
283
|
+
return result;
|
|
284
|
+
}
|
|
285
|
+
/** Tonelli-Shanks square root in F_P. Returns null when n is a non-residue. */
|
|
286
|
+
function modSqrt(n) {
|
|
287
|
+
n = (n % P + P) % P;
|
|
288
|
+
if (n === 0n) return 0n;
|
|
289
|
+
if (modPow(n, (P - 1n) / 2n, P) !== 1n) return null;
|
|
290
|
+
let s = 0;
|
|
291
|
+
let q = P - 1n;
|
|
292
|
+
while ((q & 1n) === 0n) {
|
|
293
|
+
s++;
|
|
294
|
+
q >>= 1n;
|
|
295
|
+
}
|
|
296
|
+
let z = 2n;
|
|
297
|
+
while (modPow(z, (P - 1n) / 2n, P) !== P - 1n) z++;
|
|
298
|
+
let m = s;
|
|
299
|
+
let c = modPow(z, q, P);
|
|
300
|
+
let t = modPow(n, q, P);
|
|
301
|
+
let r = modPow(n, (q + 1n) / 2n, P);
|
|
302
|
+
for (;;) {
|
|
303
|
+
if (t === 1n) return r;
|
|
304
|
+
let i = 1;
|
|
305
|
+
let tmp = t * t % P;
|
|
306
|
+
while (tmp !== 1n) {
|
|
307
|
+
tmp = tmp * tmp % P;
|
|
308
|
+
i++;
|
|
309
|
+
}
|
|
310
|
+
let b = c;
|
|
311
|
+
for (let j = 0; j < m - i - 1; j++) b = b * b % P;
|
|
312
|
+
m = i;
|
|
313
|
+
c = b * b % P;
|
|
314
|
+
t = t * c % P;
|
|
315
|
+
r = r * b % P;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
const EXT_ZERO = [
|
|
319
|
+
0n,
|
|
320
|
+
1n,
|
|
321
|
+
0n,
|
|
322
|
+
1n
|
|
323
|
+
];
|
|
324
|
+
function extAdd(a, b) {
|
|
325
|
+
const [X1, Y1, T1, Z1] = a;
|
|
326
|
+
const [X2, Y2, T2, Z2] = b;
|
|
327
|
+
const A = X1 * X2 % P;
|
|
328
|
+
const B = Y1 * Y2 % P;
|
|
329
|
+
const C = T1 * D % P * T2 % P;
|
|
330
|
+
const Dd = Z1 * Z2 % P;
|
|
331
|
+
const E = ((X1 + Y1) % P * ((X2 + Y2) % P) % P - A - B + 2n * P) % P;
|
|
332
|
+
const F = ((Dd - C) % P + P) % P;
|
|
333
|
+
const G = (Dd + C) % P;
|
|
334
|
+
const H = (B + A) % P;
|
|
335
|
+
return [
|
|
336
|
+
E * F % P,
|
|
337
|
+
G * H % P,
|
|
338
|
+
E * H % P,
|
|
339
|
+
F * G % P
|
|
340
|
+
];
|
|
341
|
+
}
|
|
342
|
+
function extDouble(a) {
|
|
343
|
+
const [X, Y, _T, Z] = a;
|
|
344
|
+
const A = X * X % P;
|
|
345
|
+
const B = Y * Y % P;
|
|
346
|
+
const C = 2n * (Z * Z % P) % P;
|
|
347
|
+
const Dd = (P - A) % P;
|
|
348
|
+
const E = ((X + Y) % P * ((X + Y) % P) % P - A - B + 2n * P) % P;
|
|
349
|
+
const G = (Dd + B) % P;
|
|
350
|
+
const F = ((G - C) % P + P) % P;
|
|
351
|
+
const H = ((Dd - B) % P + P) % P;
|
|
352
|
+
return [
|
|
353
|
+
E * F % P,
|
|
354
|
+
G * H % P,
|
|
355
|
+
E * H % P,
|
|
356
|
+
F * G % P
|
|
357
|
+
];
|
|
358
|
+
}
|
|
359
|
+
function scalarMul(pt, scalar) {
|
|
360
|
+
let result = EXT_ZERO;
|
|
361
|
+
let base = pt;
|
|
362
|
+
let s = scalar;
|
|
363
|
+
while (s > 0n) {
|
|
364
|
+
if (s & 1n) result = extAdd(result, base);
|
|
365
|
+
base = extDouble(base);
|
|
366
|
+
s >>= 1n;
|
|
367
|
+
}
|
|
368
|
+
return result;
|
|
369
|
+
}
|
|
370
|
+
/** Check whether an extended point is the identity (0, 1). */
|
|
371
|
+
function isIdentity(pt) {
|
|
372
|
+
return pt[0] === 0n && pt[1] === pt[3];
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Validates an Aleo address by decoding the bech32m payload, decompressing
|
|
376
|
+
* the Edwards BLS12-377 point, and verifying it lies in the prime-order
|
|
377
|
+
* subgroup — matching snarkVM's `Group::from_x_coordinate` exactly.
|
|
378
|
+
*
|
|
379
|
+
* Compressed format: x-coordinate (little-endian, 32 bytes) with y-sign
|
|
380
|
+
* flag in bit 7 of byte 31.
|
|
381
|
+
*/
|
|
382
|
+
function validateAleoAddress(address) {
|
|
383
|
+
try {
|
|
384
|
+
const decoded = bech32m.decodeToBytes(address);
|
|
385
|
+
if (decoded.prefix !== "aleo") return false;
|
|
386
|
+
if (decoded.bytes.length !== 32) return false;
|
|
387
|
+
const bytes = new Uint8Array(decoded.bytes);
|
|
388
|
+
bytes[31] = bytes[31] & 127;
|
|
389
|
+
let x = 0n;
|
|
390
|
+
for (let i = 31; i >= 0; i--) x = x << 8n | BigInt(bytes[i]);
|
|
391
|
+
if (x >= P) return false;
|
|
392
|
+
const x2 = x * x % P;
|
|
393
|
+
const num = (1n + x2) % P;
|
|
394
|
+
const den = ((1n - D * x2 % P) % P + P) % P;
|
|
395
|
+
if (den === 0n) return false;
|
|
396
|
+
const y = modSqrt(num * modPow(den, P - 2n, P) % P);
|
|
397
|
+
if (y === null) return false;
|
|
398
|
+
const negY = y === 0n ? 0n : P - y;
|
|
399
|
+
const p1 = [
|
|
400
|
+
x,
|
|
401
|
+
y,
|
|
402
|
+
x * y % P,
|
|
403
|
+
1n
|
|
404
|
+
];
|
|
405
|
+
const p2 = [
|
|
406
|
+
x,
|
|
407
|
+
negY,
|
|
408
|
+
x * negY % P,
|
|
409
|
+
1n
|
|
410
|
+
];
|
|
411
|
+
for (const pt of [p1, p2]) if (isIdentity(scalarMul(pt, SUBGROUP_ORDER))) return true;
|
|
412
|
+
return false;
|
|
413
|
+
} catch {
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
268
417
|
|
|
269
418
|
//#endregion
|
|
270
419
|
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.52.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"valibot": "^1.0.0",
|
|
47
47
|
"viem": "^2.0.0",
|
|
48
48
|
"@defuse-protocol/contract-types": "0.6.0",
|
|
49
|
-
"@defuse-protocol/internal-utils": "0.
|
|
49
|
+
"@defuse-protocol/internal-utils": "0.27.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"tsdown": "0.19.0"
|