@naculus/connect-appkit-core 0.8.1 → 0.10.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 +99 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +52 -1
- package/dist/index.d.ts +52 -1
- package/dist/index.js +94 -18
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Namespace, UniversalWalletSession, WalletCapabilities, TokenConfig, WalletError, WalletErrorCode, SimulationResult, NameResolverConfig, NameResolver, NotificationSettings, InAppChannel, NotificationItem, SessionKeyManagerConfig, SessionKeyManager, Hex, UserOperationReceipt, Address, SmartAccountConfig, AtomicityRequirement, ExecutionPlan, SessionKeyInfo, SessionKeyTransaction, delegationTypedData, SessionKeyScope, ScopeCheckResult, SpendRefusal, Authorization, ListedAuthorization, SpendRequest, SettlementVerification, SolanaSessionKeyInfo, SolanaSessionKeyScope, SolanaSessionKeyManager, SolanaPaymentRpc } from '@naculus/connect-core';
|
|
2
|
+
import { X402TypedDataSigner } from '@naculus/payments-x402';
|
|
3
|
+
export { X402TypedDataSigner } from '@naculus/payments-x402';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* The types the framework-neutral half of appkit is built on.
|
|
@@ -861,6 +863,7 @@ interface AuthorizationAssetMetadata {
|
|
|
861
863
|
}
|
|
862
864
|
interface DescribeAuthorizationOptions {
|
|
863
865
|
assets?: Record<AssetId, AuthorizationAssetMetadata>;
|
|
866
|
+
trustedAssets?: readonly string[];
|
|
864
867
|
locale?: string;
|
|
865
868
|
/** Unix timestamp in seconds. */
|
|
866
869
|
now?: number;
|
|
@@ -874,6 +877,7 @@ interface AuthorizationAmountView {
|
|
|
874
877
|
}
|
|
875
878
|
interface AuthorizationGrantView {
|
|
876
879
|
asset: AssetId;
|
|
880
|
+
assetTrust: "trusted" | "unverified" | "unchecked";
|
|
877
881
|
assetLabel: string;
|
|
878
882
|
recipients: AuthorizationRecipientView[];
|
|
879
883
|
perPayment: AuthorizationAmountView;
|
|
@@ -972,6 +976,53 @@ declare function applySettlementVerification(payment: PaymentRecord, result: Set
|
|
|
972
976
|
*/
|
|
973
977
|
declare function describePayment(input: RequestInfo | URL, result: PaymentFetchResult): PaymentRecord | null;
|
|
974
978
|
|
|
979
|
+
type X402SignerUnavailableReason = "no-session" | "not-evm" | "unsupported-wallet-type";
|
|
980
|
+
interface X402Eip1193Provider {
|
|
981
|
+
request(args: {
|
|
982
|
+
method: string;
|
|
983
|
+
params?: unknown[];
|
|
984
|
+
}): Promise<unknown>;
|
|
985
|
+
}
|
|
986
|
+
type X402WalletResolution = {
|
|
987
|
+
provider: X402Eip1193Provider;
|
|
988
|
+
address: `0x${string}`;
|
|
989
|
+
reason: null;
|
|
990
|
+
} | {
|
|
991
|
+
provider: null;
|
|
992
|
+
address: null;
|
|
993
|
+
reason: X402SignerUnavailableReason;
|
|
994
|
+
};
|
|
995
|
+
/** Where a session's EIP-1193 provider can come from; each framework supplies its own. */
|
|
996
|
+
interface X402ProviderSources {
|
|
997
|
+
/** EIP-6963 wallets discovered on the page (`eip6963Connector.getDiscoveredWallets()`). */
|
|
998
|
+
injected?: readonly {
|
|
999
|
+
id: string;
|
|
1000
|
+
provider: X402Eip1193Provider;
|
|
1001
|
+
}[];
|
|
1002
|
+
/** The WalletConnect connector, whose `request` routes to its last session. */
|
|
1003
|
+
walletConnect?: X402Eip1193Provider | null;
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
* The provider that belongs to `session`, chosen by the session's wallet
|
|
1007
|
+
* type (never by connector identity): the injected wallet the session was
|
|
1008
|
+
* made with, or the WalletConnect connector. Null for anything else.
|
|
1009
|
+
*/
|
|
1010
|
+
declare function findX402Provider(session: UniversalWalletSession | null | undefined, sources: X402ProviderSources): X402Eip1193Provider | null;
|
|
1011
|
+
interface X402SignerResolution {
|
|
1012
|
+
signer: X402TypedDataSigner | null;
|
|
1013
|
+
reason: X402SignerUnavailableReason | null;
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Resolve the connected EVM payer without coupling appkit-core to a connector.
|
|
1017
|
+
*
|
|
1018
|
+
* Framework bindings supply the EIP-1193 request facade owned by the active
|
|
1019
|
+
* session. Classification remains session-based: connector identity is never
|
|
1020
|
+
* used as a routing input.
|
|
1021
|
+
*/
|
|
1022
|
+
declare function resolveX402Wallet(session: UniversalWalletSession | null | undefined, provider: X402Eip1193Provider | null | undefined): X402WalletResolution;
|
|
1023
|
+
/** Build the signer after applying the shared session-routing policy. */
|
|
1024
|
+
declare function createX402WalletSigner(session: UniversalWalletSession | null | undefined, provider: X402Eip1193Provider | null | undefined, switchChain: (chainId: string) => Promise<void>): X402SignerResolution;
|
|
1025
|
+
|
|
975
1026
|
/** Request options accepted by a caller-built MPP session fetch. */
|
|
976
1027
|
interface MppSessionRequestInit extends RequestInit {
|
|
977
1028
|
units?: bigint;
|
|
@@ -1152,4 +1203,4 @@ declare function siwxResultToSession<M extends SiwxMessageLike>(result: SiwxResu
|
|
|
1152
1203
|
refreshedAt: null;
|
|
1153
1204
|
};
|
|
1154
1205
|
|
|
1155
|
-
export { type AddressValidationLevel, type AssetId, type AtomicSupport, type AuthorizationAmountView, type AuthorizationAssetMetadata, type AuthorizationDescription, type AuthorizationExpiryView, type AuthorizationGrantView, type AuthorizationRecipientView, type ChainCapabilities, type ChainInfo, type CompareCosts, type CompareCostsInput, type ConnectionStatus, type CostComparison, type CostComparisonOperation, type CostComparisonOptions, DEFAULT_NOTIFICATION_SETTINGS, DEFAULT_VERIFY_RETRY, type DecimalsCache, type DelegationFrameworkAdapterOptions, type DelegationPolicyDeps, type DelegationPolicyFlow, type DelegationPolicyPreview, type DelegationTypedData, type DescribeAuthorizationOptions, type DestinationIssue, type DestinationValidation, type ExecutableQuote, type ExecuteRoute, type ExecuteRouteError, type ExecuteRouteOptions, type ExecuteRouteResult, type GetRouteQuotes, InvalidUserOperationReceiptError, type MppSessionChannel, type MppSessionFetch, type MppSessionFetchResult, type MppSessionForceCloseResult, type MppSessionMeter, type MppSessionReceipt, type MppSessionRequest, type MppSessionRequestInit, NOTIFICATION_SETTINGS_KEY, type NotificationSettingsStorage, type NotificationSettingsUpdate, type PaymentFetch, type PaymentFetchResult, type PaymentRecord, type PaymentVerification, type PaymentVerificationStatus, type PolicyExecutionAdapter, type PolicyExecutionCheck, type PolicyExecutionPreview, type PolicyExecutionRoute, type PolicyExecutionSubmission, type PolicySignatureVerifier, type PreparedPolicyExecution, type RedemptionCodec, type RedemptionRpc, type RedemptionTransaction, type RetryOptions, type RouteQuote, type RouteQuoteInput, type RouteQuoteOptions, type SimulationCallClient, type SimulationTransaction, type SiwxLocation, type SiwxMessageLike, type SiwxResultLike, type SmartAccountOptionsLike, type SmartAccountType, type SolanaIdentity, type SolanaOwnerSigner, type SolanaPayer, type SolanaRoles, type SolanaRolesAbsence, type SolanaRolesSource, type SolanaRolesState, type SolanaSessionKeyFlow, type SolanaSessionKeyFlowDeps, type SolanaSigner, type SolanaWalletFeatures, type SpendExplanation, type TokenIdentity, type TransactionSimulationContext, type VerifyRetryOptions, type ViemChainShape, type WalletChain, type Web3Action, type Web3State, __resetResolverForTests, addInAppNotification, applySettlementVerification, assertHexSignature, atomicSupportFor, bareEvmAddress, buildDelegationPolicyMessage, buildSmartAccountConfig, chainNamespace, chainNumber, chainsForNamespace, channelsUpdate, clearOneInAppNotification, compareCostsKey, createDecimalsCache, createDelegationFrameworkAdapter, createDelegationPolicyFlow, createNotification, createNotificationSettingsStorage, createSolanaSessionKeyFlow, decodeRevertReason, defaultSiwxDomain, defaultSiwxUri, describeAuthorization, describeChain, describePayment, eip155ChainIdToNumber, encodeErc20Approve, encodeErc20Transfer, encodeErc20TransferFrom, explainSpend, fetchUserOperationReceipt, formatAuthorizationAmount, getResolver, getSharedSessionKeyManager, initialWeb3State, isBurnDestination, isEvmChainId, isPositiveIntegerAmount, isQuotableInput, isSiwxExpired, isSiwxNotBeforeValid, isVerifiablePolicy, loadNotificationSettings, mutedChainSettings, normalizeCapabilities, normalizeEip155ChainId, parseUserOperationReceipt, readCurrentMppSessionChannel, readDecimals, readMppRecoveryChannelId, readMppSessionChannel, readMppSessionReceipt, readSolanaRoles, replayNotificationSettings, resetSharedSessionKeyManager, resolveChain, resolveContextSimulationEndpoint, resolveEvmChainId, resolveRevertReason, resolveSimulationEndpoint, resolveUserOpChain, sameExecutionIntent, saveNotificationSettings, selectChainCapabilities, sessionKeyConfigFingerprint, simulateTransactionPreview, siwxResultToSession, toChainSwitchError, toEip155Accounts, toExecuteRouteError, toViemChain, tokenChainMismatch, tokenKey, updateNotificationSettings, validateDestination, validateRouteRecipient, web3Reducer, withRetry, withTimeout, writeDecimals };
|
|
1206
|
+
export { type AddressValidationLevel, type AssetId, type AtomicSupport, type AuthorizationAmountView, type AuthorizationAssetMetadata, type AuthorizationDescription, type AuthorizationExpiryView, type AuthorizationGrantView, type AuthorizationRecipientView, type ChainCapabilities, type ChainInfo, type CompareCosts, type CompareCostsInput, type ConnectionStatus, type CostComparison, type CostComparisonOperation, type CostComparisonOptions, DEFAULT_NOTIFICATION_SETTINGS, DEFAULT_VERIFY_RETRY, type DecimalsCache, type DelegationFrameworkAdapterOptions, type DelegationPolicyDeps, type DelegationPolicyFlow, type DelegationPolicyPreview, type DelegationTypedData, type DescribeAuthorizationOptions, type DestinationIssue, type DestinationValidation, type ExecutableQuote, type ExecuteRoute, type ExecuteRouteError, type ExecuteRouteOptions, type ExecuteRouteResult, type GetRouteQuotes, InvalidUserOperationReceiptError, type MppSessionChannel, type MppSessionFetch, type MppSessionFetchResult, type MppSessionForceCloseResult, type MppSessionMeter, type MppSessionReceipt, type MppSessionRequest, type MppSessionRequestInit, NOTIFICATION_SETTINGS_KEY, type NotificationSettingsStorage, type NotificationSettingsUpdate, type PaymentFetch, type PaymentFetchResult, type PaymentRecord, type PaymentVerification, type PaymentVerificationStatus, type PolicyExecutionAdapter, type PolicyExecutionCheck, type PolicyExecutionPreview, type PolicyExecutionRoute, type PolicyExecutionSubmission, type PolicySignatureVerifier, type PreparedPolicyExecution, type RedemptionCodec, type RedemptionRpc, type RedemptionTransaction, type RetryOptions, type RouteQuote, type RouteQuoteInput, type RouteQuoteOptions, type SimulationCallClient, type SimulationTransaction, type SiwxLocation, type SiwxMessageLike, type SiwxResultLike, type SmartAccountOptionsLike, type SmartAccountType, type SolanaIdentity, type SolanaOwnerSigner, type SolanaPayer, type SolanaRoles, type SolanaRolesAbsence, type SolanaRolesSource, type SolanaRolesState, type SolanaSessionKeyFlow, type SolanaSessionKeyFlowDeps, type SolanaSigner, type SolanaWalletFeatures, type SpendExplanation, type TokenIdentity, type TransactionSimulationContext, type VerifyRetryOptions, type ViemChainShape, type WalletChain, type Web3Action, type Web3State, type X402Eip1193Provider, type X402ProviderSources, type X402SignerResolution, type X402SignerUnavailableReason, type X402WalletResolution, __resetResolverForTests, addInAppNotification, applySettlementVerification, assertHexSignature, atomicSupportFor, bareEvmAddress, buildDelegationPolicyMessage, buildSmartAccountConfig, chainNamespace, chainNumber, chainsForNamespace, channelsUpdate, clearOneInAppNotification, compareCostsKey, createDecimalsCache, createDelegationFrameworkAdapter, createDelegationPolicyFlow, createNotification, createNotificationSettingsStorage, createSolanaSessionKeyFlow, createX402WalletSigner, decodeRevertReason, defaultSiwxDomain, defaultSiwxUri, describeAuthorization, describeChain, describePayment, eip155ChainIdToNumber, encodeErc20Approve, encodeErc20Transfer, encodeErc20TransferFrom, explainSpend, fetchUserOperationReceipt, findX402Provider, formatAuthorizationAmount, getResolver, getSharedSessionKeyManager, initialWeb3State, isBurnDestination, isEvmChainId, isPositiveIntegerAmount, isQuotableInput, isSiwxExpired, isSiwxNotBeforeValid, isVerifiablePolicy, loadNotificationSettings, mutedChainSettings, normalizeCapabilities, normalizeEip155ChainId, parseUserOperationReceipt, readCurrentMppSessionChannel, readDecimals, readMppRecoveryChannelId, readMppSessionChannel, readMppSessionReceipt, readSolanaRoles, replayNotificationSettings, resetSharedSessionKeyManager, resolveChain, resolveContextSimulationEndpoint, resolveEvmChainId, resolveRevertReason, resolveSimulationEndpoint, resolveUserOpChain, resolveX402Wallet, sameExecutionIntent, saveNotificationSettings, selectChainCapabilities, sessionKeyConfigFingerprint, simulateTransactionPreview, siwxResultToSession, toChainSwitchError, toEip155Accounts, toExecuteRouteError, toViemChain, tokenChainMismatch, tokenKey, updateNotificationSettings, validateDestination, validateRouteRecipient, web3Reducer, withRetry, withTimeout, writeDecimals };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Namespace, UniversalWalletSession, WalletCapabilities, TokenConfig, WalletError, WalletErrorCode, SimulationResult, NameResolverConfig, NameResolver, NotificationSettings, InAppChannel, NotificationItem, SessionKeyManagerConfig, SessionKeyManager, Hex, UserOperationReceipt, Address, SmartAccountConfig, AtomicityRequirement, ExecutionPlan, SessionKeyInfo, SessionKeyTransaction, delegationTypedData, SessionKeyScope, ScopeCheckResult, SpendRefusal, Authorization, ListedAuthorization, SpendRequest, SettlementVerification, SolanaSessionKeyInfo, SolanaSessionKeyScope, SolanaSessionKeyManager, SolanaPaymentRpc } from '@naculus/connect-core';
|
|
2
|
+
import { X402TypedDataSigner } from '@naculus/payments-x402';
|
|
3
|
+
export { X402TypedDataSigner } from '@naculus/payments-x402';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* The types the framework-neutral half of appkit is built on.
|
|
@@ -861,6 +863,7 @@ interface AuthorizationAssetMetadata {
|
|
|
861
863
|
}
|
|
862
864
|
interface DescribeAuthorizationOptions {
|
|
863
865
|
assets?: Record<AssetId, AuthorizationAssetMetadata>;
|
|
866
|
+
trustedAssets?: readonly string[];
|
|
864
867
|
locale?: string;
|
|
865
868
|
/** Unix timestamp in seconds. */
|
|
866
869
|
now?: number;
|
|
@@ -874,6 +877,7 @@ interface AuthorizationAmountView {
|
|
|
874
877
|
}
|
|
875
878
|
interface AuthorizationGrantView {
|
|
876
879
|
asset: AssetId;
|
|
880
|
+
assetTrust: "trusted" | "unverified" | "unchecked";
|
|
877
881
|
assetLabel: string;
|
|
878
882
|
recipients: AuthorizationRecipientView[];
|
|
879
883
|
perPayment: AuthorizationAmountView;
|
|
@@ -972,6 +976,53 @@ declare function applySettlementVerification(payment: PaymentRecord, result: Set
|
|
|
972
976
|
*/
|
|
973
977
|
declare function describePayment(input: RequestInfo | URL, result: PaymentFetchResult): PaymentRecord | null;
|
|
974
978
|
|
|
979
|
+
type X402SignerUnavailableReason = "no-session" | "not-evm" | "unsupported-wallet-type";
|
|
980
|
+
interface X402Eip1193Provider {
|
|
981
|
+
request(args: {
|
|
982
|
+
method: string;
|
|
983
|
+
params?: unknown[];
|
|
984
|
+
}): Promise<unknown>;
|
|
985
|
+
}
|
|
986
|
+
type X402WalletResolution = {
|
|
987
|
+
provider: X402Eip1193Provider;
|
|
988
|
+
address: `0x${string}`;
|
|
989
|
+
reason: null;
|
|
990
|
+
} | {
|
|
991
|
+
provider: null;
|
|
992
|
+
address: null;
|
|
993
|
+
reason: X402SignerUnavailableReason;
|
|
994
|
+
};
|
|
995
|
+
/** Where a session's EIP-1193 provider can come from; each framework supplies its own. */
|
|
996
|
+
interface X402ProviderSources {
|
|
997
|
+
/** EIP-6963 wallets discovered on the page (`eip6963Connector.getDiscoveredWallets()`). */
|
|
998
|
+
injected?: readonly {
|
|
999
|
+
id: string;
|
|
1000
|
+
provider: X402Eip1193Provider;
|
|
1001
|
+
}[];
|
|
1002
|
+
/** The WalletConnect connector, whose `request` routes to its last session. */
|
|
1003
|
+
walletConnect?: X402Eip1193Provider | null;
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
* The provider that belongs to `session`, chosen by the session's wallet
|
|
1007
|
+
* type (never by connector identity): the injected wallet the session was
|
|
1008
|
+
* made with, or the WalletConnect connector. Null for anything else.
|
|
1009
|
+
*/
|
|
1010
|
+
declare function findX402Provider(session: UniversalWalletSession | null | undefined, sources: X402ProviderSources): X402Eip1193Provider | null;
|
|
1011
|
+
interface X402SignerResolution {
|
|
1012
|
+
signer: X402TypedDataSigner | null;
|
|
1013
|
+
reason: X402SignerUnavailableReason | null;
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Resolve the connected EVM payer without coupling appkit-core to a connector.
|
|
1017
|
+
*
|
|
1018
|
+
* Framework bindings supply the EIP-1193 request facade owned by the active
|
|
1019
|
+
* session. Classification remains session-based: connector identity is never
|
|
1020
|
+
* used as a routing input.
|
|
1021
|
+
*/
|
|
1022
|
+
declare function resolveX402Wallet(session: UniversalWalletSession | null | undefined, provider: X402Eip1193Provider | null | undefined): X402WalletResolution;
|
|
1023
|
+
/** Build the signer after applying the shared session-routing policy. */
|
|
1024
|
+
declare function createX402WalletSigner(session: UniversalWalletSession | null | undefined, provider: X402Eip1193Provider | null | undefined, switchChain: (chainId: string) => Promise<void>): X402SignerResolution;
|
|
1025
|
+
|
|
975
1026
|
/** Request options accepted by a caller-built MPP session fetch. */
|
|
976
1027
|
interface MppSessionRequestInit extends RequestInit {
|
|
977
1028
|
units?: bigint;
|
|
@@ -1152,4 +1203,4 @@ declare function siwxResultToSession<M extends SiwxMessageLike>(result: SiwxResu
|
|
|
1152
1203
|
refreshedAt: null;
|
|
1153
1204
|
};
|
|
1154
1205
|
|
|
1155
|
-
export { type AddressValidationLevel, type AssetId, type AtomicSupport, type AuthorizationAmountView, type AuthorizationAssetMetadata, type AuthorizationDescription, type AuthorizationExpiryView, type AuthorizationGrantView, type AuthorizationRecipientView, type ChainCapabilities, type ChainInfo, type CompareCosts, type CompareCostsInput, type ConnectionStatus, type CostComparison, type CostComparisonOperation, type CostComparisonOptions, DEFAULT_NOTIFICATION_SETTINGS, DEFAULT_VERIFY_RETRY, type DecimalsCache, type DelegationFrameworkAdapterOptions, type DelegationPolicyDeps, type DelegationPolicyFlow, type DelegationPolicyPreview, type DelegationTypedData, type DescribeAuthorizationOptions, type DestinationIssue, type DestinationValidation, type ExecutableQuote, type ExecuteRoute, type ExecuteRouteError, type ExecuteRouteOptions, type ExecuteRouteResult, type GetRouteQuotes, InvalidUserOperationReceiptError, type MppSessionChannel, type MppSessionFetch, type MppSessionFetchResult, type MppSessionForceCloseResult, type MppSessionMeter, type MppSessionReceipt, type MppSessionRequest, type MppSessionRequestInit, NOTIFICATION_SETTINGS_KEY, type NotificationSettingsStorage, type NotificationSettingsUpdate, type PaymentFetch, type PaymentFetchResult, type PaymentRecord, type PaymentVerification, type PaymentVerificationStatus, type PolicyExecutionAdapter, type PolicyExecutionCheck, type PolicyExecutionPreview, type PolicyExecutionRoute, type PolicyExecutionSubmission, type PolicySignatureVerifier, type PreparedPolicyExecution, type RedemptionCodec, type RedemptionRpc, type RedemptionTransaction, type RetryOptions, type RouteQuote, type RouteQuoteInput, type RouteQuoteOptions, type SimulationCallClient, type SimulationTransaction, type SiwxLocation, type SiwxMessageLike, type SiwxResultLike, type SmartAccountOptionsLike, type SmartAccountType, type SolanaIdentity, type SolanaOwnerSigner, type SolanaPayer, type SolanaRoles, type SolanaRolesAbsence, type SolanaRolesSource, type SolanaRolesState, type SolanaSessionKeyFlow, type SolanaSessionKeyFlowDeps, type SolanaSigner, type SolanaWalletFeatures, type SpendExplanation, type TokenIdentity, type TransactionSimulationContext, type VerifyRetryOptions, type ViemChainShape, type WalletChain, type Web3Action, type Web3State, __resetResolverForTests, addInAppNotification, applySettlementVerification, assertHexSignature, atomicSupportFor, bareEvmAddress, buildDelegationPolicyMessage, buildSmartAccountConfig, chainNamespace, chainNumber, chainsForNamespace, channelsUpdate, clearOneInAppNotification, compareCostsKey, createDecimalsCache, createDelegationFrameworkAdapter, createDelegationPolicyFlow, createNotification, createNotificationSettingsStorage, createSolanaSessionKeyFlow, decodeRevertReason, defaultSiwxDomain, defaultSiwxUri, describeAuthorization, describeChain, describePayment, eip155ChainIdToNumber, encodeErc20Approve, encodeErc20Transfer, encodeErc20TransferFrom, explainSpend, fetchUserOperationReceipt, formatAuthorizationAmount, getResolver, getSharedSessionKeyManager, initialWeb3State, isBurnDestination, isEvmChainId, isPositiveIntegerAmount, isQuotableInput, isSiwxExpired, isSiwxNotBeforeValid, isVerifiablePolicy, loadNotificationSettings, mutedChainSettings, normalizeCapabilities, normalizeEip155ChainId, parseUserOperationReceipt, readCurrentMppSessionChannel, readDecimals, readMppRecoveryChannelId, readMppSessionChannel, readMppSessionReceipt, readSolanaRoles, replayNotificationSettings, resetSharedSessionKeyManager, resolveChain, resolveContextSimulationEndpoint, resolveEvmChainId, resolveRevertReason, resolveSimulationEndpoint, resolveUserOpChain, sameExecutionIntent, saveNotificationSettings, selectChainCapabilities, sessionKeyConfigFingerprint, simulateTransactionPreview, siwxResultToSession, toChainSwitchError, toEip155Accounts, toExecuteRouteError, toViemChain, tokenChainMismatch, tokenKey, updateNotificationSettings, validateDestination, validateRouteRecipient, web3Reducer, withRetry, withTimeout, writeDecimals };
|
|
1206
|
+
export { type AddressValidationLevel, type AssetId, type AtomicSupport, type AuthorizationAmountView, type AuthorizationAssetMetadata, type AuthorizationDescription, type AuthorizationExpiryView, type AuthorizationGrantView, type AuthorizationRecipientView, type ChainCapabilities, type ChainInfo, type CompareCosts, type CompareCostsInput, type ConnectionStatus, type CostComparison, type CostComparisonOperation, type CostComparisonOptions, DEFAULT_NOTIFICATION_SETTINGS, DEFAULT_VERIFY_RETRY, type DecimalsCache, type DelegationFrameworkAdapterOptions, type DelegationPolicyDeps, type DelegationPolicyFlow, type DelegationPolicyPreview, type DelegationTypedData, type DescribeAuthorizationOptions, type DestinationIssue, type DestinationValidation, type ExecutableQuote, type ExecuteRoute, type ExecuteRouteError, type ExecuteRouteOptions, type ExecuteRouteResult, type GetRouteQuotes, InvalidUserOperationReceiptError, type MppSessionChannel, type MppSessionFetch, type MppSessionFetchResult, type MppSessionForceCloseResult, type MppSessionMeter, type MppSessionReceipt, type MppSessionRequest, type MppSessionRequestInit, NOTIFICATION_SETTINGS_KEY, type NotificationSettingsStorage, type NotificationSettingsUpdate, type PaymentFetch, type PaymentFetchResult, type PaymentRecord, type PaymentVerification, type PaymentVerificationStatus, type PolicyExecutionAdapter, type PolicyExecutionCheck, type PolicyExecutionPreview, type PolicyExecutionRoute, type PolicyExecutionSubmission, type PolicySignatureVerifier, type PreparedPolicyExecution, type RedemptionCodec, type RedemptionRpc, type RedemptionTransaction, type RetryOptions, type RouteQuote, type RouteQuoteInput, type RouteQuoteOptions, type SimulationCallClient, type SimulationTransaction, type SiwxLocation, type SiwxMessageLike, type SiwxResultLike, type SmartAccountOptionsLike, type SmartAccountType, type SolanaIdentity, type SolanaOwnerSigner, type SolanaPayer, type SolanaRoles, type SolanaRolesAbsence, type SolanaRolesSource, type SolanaRolesState, type SolanaSessionKeyFlow, type SolanaSessionKeyFlowDeps, type SolanaSigner, type SolanaWalletFeatures, type SpendExplanation, type TokenIdentity, type TransactionSimulationContext, type VerifyRetryOptions, type ViemChainShape, type WalletChain, type Web3Action, type Web3State, type X402Eip1193Provider, type X402ProviderSources, type X402SignerResolution, type X402SignerUnavailableReason, type X402WalletResolution, __resetResolverForTests, addInAppNotification, applySettlementVerification, assertHexSignature, atomicSupportFor, bareEvmAddress, buildDelegationPolicyMessage, buildSmartAccountConfig, chainNamespace, chainNumber, chainsForNamespace, channelsUpdate, clearOneInAppNotification, compareCostsKey, createDecimalsCache, createDelegationFrameworkAdapter, createDelegationPolicyFlow, createNotification, createNotificationSettingsStorage, createSolanaSessionKeyFlow, createX402WalletSigner, decodeRevertReason, defaultSiwxDomain, defaultSiwxUri, describeAuthorization, describeChain, describePayment, eip155ChainIdToNumber, encodeErc20Approve, encodeErc20Transfer, encodeErc20TransferFrom, explainSpend, fetchUserOperationReceipt, findX402Provider, formatAuthorizationAmount, getResolver, getSharedSessionKeyManager, initialWeb3State, isBurnDestination, isEvmChainId, isPositiveIntegerAmount, isQuotableInput, isSiwxExpired, isSiwxNotBeforeValid, isVerifiablePolicy, loadNotificationSettings, mutedChainSettings, normalizeCapabilities, normalizeEip155ChainId, parseUserOperationReceipt, readCurrentMppSessionChannel, readDecimals, readMppRecoveryChannelId, readMppSessionChannel, readMppSessionReceipt, readSolanaRoles, replayNotificationSettings, resetSharedSessionKeyManager, resolveChain, resolveContextSimulationEndpoint, resolveEvmChainId, resolveRevertReason, resolveSimulationEndpoint, resolveUserOpChain, resolveX402Wallet, sameExecutionIntent, saveNotificationSettings, selectChainCapabilities, sessionKeyConfigFingerprint, simulateTransactionPreview, siwxResultToSession, toChainSwitchError, toEip155Accounts, toExecuteRouteError, toViemChain, tokenChainMismatch, tokenKey, updateNotificationSettings, validateDestination, validateRouteRecipient, web3Reducer, withRetry, withTimeout, writeDecimals };
|
package/dist/index.js
CHANGED
|
@@ -1300,35 +1300,51 @@ function createDelegationPolicyFlow(deps) {
|
|
|
1300
1300
|
import {
|
|
1301
1301
|
evaluateSpend
|
|
1302
1302
|
} from "@naculus/connect-core";
|
|
1303
|
-
function assetAddress(asset) {
|
|
1304
|
-
return asset.split(/[:/]/).at(-1);
|
|
1305
|
-
}
|
|
1306
1303
|
function groupDigits(value) {
|
|
1307
|
-
|
|
1304
|
+
let out = "";
|
|
1305
|
+
for (let i = 0; i < value.length; i++)
|
|
1306
|
+
out += (i && (value.length - i) % 3 === 0 ? "," : "") + value[i];
|
|
1307
|
+
return out;
|
|
1308
|
+
}
|
|
1309
|
+
function trustedMetadata(asset, options) {
|
|
1310
|
+
const trust = !options.trustedAssets ? "unchecked" : options.trustedAssets.some(
|
|
1311
|
+
(t) => canonicalAssetId(t) === canonicalAssetId(asset)
|
|
1312
|
+
) ? "trusted" : "unverified";
|
|
1313
|
+
return [trust, trust === "unverified" ? void 0 : options.assets?.[asset]];
|
|
1314
|
+
}
|
|
1315
|
+
function canonicalAssetId(asset) {
|
|
1316
|
+
return asset.replace(
|
|
1317
|
+
/^(eip155:[^/]+\/erc20:)(.+)$/,
|
|
1318
|
+
(_, prefix, reference) => prefix + reference.toLowerCase()
|
|
1319
|
+
);
|
|
1308
1320
|
}
|
|
1309
1321
|
function formatAuthorizationAmount(amount, metadata) {
|
|
1310
1322
|
const baseUnits = amount.toString();
|
|
1311
|
-
if (!metadata
|
|
1323
|
+
if (!metadata?.symbol || !Number.isSafeInteger(metadata.decimals) || metadata.decimals < 0 || metadata.decimals > 255) {
|
|
1312
1324
|
return {
|
|
1313
1325
|
formatted: `${groupDigits(baseUnits)} base units`
|
|
1314
1326
|
};
|
|
1315
1327
|
}
|
|
1316
1328
|
const decimals = metadata.decimals;
|
|
1317
1329
|
const padded = baseUnits.padStart(decimals + 1, "0");
|
|
1318
|
-
const integer =
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
return {
|
|
1330
|
+
const integer = padded.slice(0, decimals ? -decimals : void 0);
|
|
1331
|
+
let fraction = decimals ? padded.slice(-decimals) : "";
|
|
1332
|
+
while (fraction.endsWith("0")) fraction = fraction.slice(0, -1);
|
|
1333
|
+
return {
|
|
1334
|
+
formatted: `${groupDigits(integer)}${fraction ? `.${fraction}` : ""} ${metadata.symbol}`
|
|
1335
|
+
};
|
|
1322
1336
|
}
|
|
1323
1337
|
function relativeExpiry(expiresAt, now, locale) {
|
|
1324
1338
|
const seconds = expiresAt - now;
|
|
1325
1339
|
const absolute = Math.abs(seconds);
|
|
1326
|
-
const divisor = absolute >= 31536e3 ? 31536e3 : absolute >= 2592e3 ? 2592e3 : absolute >= 86400 ? 86400 : absolute >= 3600 ? 3600 : absolute >= 60 ? 60 : 1;
|
|
1327
|
-
const
|
|
1328
|
-
|
|
1329
|
-
Math.
|
|
1330
|
-
unit
|
|
1331
|
-
|
|
1340
|
+
const [divisor, unit] = absolute >= 31536e3 ? [31536e3, "year"] : absolute >= 2592e3 ? [2592e3, "month"] : absolute >= 86400 ? [86400, "day"] : absolute >= 3600 ? [3600, "hour"] : absolute >= 60 ? [60, "minute"] : [1, "second"];
|
|
1341
|
+
const value = Math.round(seconds / divisor);
|
|
1342
|
+
if (typeof Intl.RelativeTimeFormat !== "function") {
|
|
1343
|
+
const count = Math.abs(value);
|
|
1344
|
+
const phrase = `${count} ${unit}${count === 1 ? "" : "s"}`;
|
|
1345
|
+
return value < 0 || Object.is(value, -0) ? `${phrase} ago` : `in ${phrase}`;
|
|
1346
|
+
}
|
|
1347
|
+
return new Intl.RelativeTimeFormat(locale).format(value, unit);
|
|
1332
1348
|
}
|
|
1333
1349
|
function describeAuthorization(input, options = {}) {
|
|
1334
1350
|
const now = options.now ?? Math.floor(Date.now() / 1e3);
|
|
@@ -1339,10 +1355,11 @@ function describeAuthorization(input, options = {}) {
|
|
|
1339
1355
|
label,
|
|
1340
1356
|
principal: input.principal ?? null,
|
|
1341
1357
|
grants: input.grants.map((grant) => {
|
|
1342
|
-
const metadata =
|
|
1358
|
+
const [assetTrust, metadata] = trustedMetadata(grant.asset, options);
|
|
1343
1359
|
return {
|
|
1344
1360
|
asset: grant.asset,
|
|
1345
|
-
|
|
1361
|
+
assetTrust,
|
|
1362
|
+
assetLabel: metadata?.symbol || grant.asset.split(":").at(-1),
|
|
1346
1363
|
recipients: grant.recipients.map((full) => ({
|
|
1347
1364
|
shortened: full.length <= 14 ? full : `${full.slice(0, 6)}\u2026${full.slice(-6)}`,
|
|
1348
1365
|
full
|
|
@@ -1395,7 +1412,7 @@ function explainSpend(authorization, request, options = {}) {
|
|
|
1395
1412
|
const remainingTotal = authorization.grants[verdict.grant].maxTotal - request.spentSoFar - request.amount;
|
|
1396
1413
|
const remainingTotalFormatted = formatAuthorizationAmount(
|
|
1397
1414
|
remainingTotal,
|
|
1398
|
-
|
|
1415
|
+
trustedMetadata(authorization.grants[verdict.grant].asset, options)[1]
|
|
1399
1416
|
);
|
|
1400
1417
|
return {
|
|
1401
1418
|
allowed: true,
|
|
@@ -1477,6 +1494,62 @@ function describePayment(input, result) {
|
|
|
1477
1494
|
};
|
|
1478
1495
|
}
|
|
1479
1496
|
|
|
1497
|
+
// src/x402-wallet.ts
|
|
1498
|
+
import {
|
|
1499
|
+
isEvmAddress as isEvmAddress2,
|
|
1500
|
+
parseCaip10
|
|
1501
|
+
} from "@naculus/connect-core";
|
|
1502
|
+
import {
|
|
1503
|
+
walletX402Signer
|
|
1504
|
+
} from "@naculus/payments-x402";
|
|
1505
|
+
function findX402Provider(session, sources) {
|
|
1506
|
+
if (!session) return null;
|
|
1507
|
+
if (session.walletType === "eip6963" || session.id.startsWith("eip6963-")) {
|
|
1508
|
+
return sources.injected?.find((wallet) => wallet.id === session.walletId)?.provider ?? null;
|
|
1509
|
+
}
|
|
1510
|
+
if (session.walletType === "walletconnect") {
|
|
1511
|
+
return sources.walletConnect ?? null;
|
|
1512
|
+
}
|
|
1513
|
+
return null;
|
|
1514
|
+
}
|
|
1515
|
+
function unavailable(reason) {
|
|
1516
|
+
return { provider: null, address: null, reason };
|
|
1517
|
+
}
|
|
1518
|
+
function resolveX402Wallet(session, provider) {
|
|
1519
|
+
if (!session) return unavailable("no-session");
|
|
1520
|
+
const namespace = session.namespaces.eip155;
|
|
1521
|
+
if (!namespace) return unavailable("not-evm");
|
|
1522
|
+
const isInjected = session.walletType === "eip6963" || session.id.startsWith("eip6963-");
|
|
1523
|
+
const isWalletConnect = session.walletType === "walletconnect";
|
|
1524
|
+
if (!isInjected && !isWalletConnect || !provider?.request) {
|
|
1525
|
+
return unavailable("unsupported-wallet-type");
|
|
1526
|
+
}
|
|
1527
|
+
for (const account of namespace.accounts) {
|
|
1528
|
+
const parsed = parseCaip10(account);
|
|
1529
|
+
const address = parsed?.namespace === "eip155" ? parsed.address : account;
|
|
1530
|
+
if (isEvmAddress2(address)) {
|
|
1531
|
+
return {
|
|
1532
|
+
provider,
|
|
1533
|
+
address,
|
|
1534
|
+
reason: null
|
|
1535
|
+
};
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
return unavailable("not-evm");
|
|
1539
|
+
}
|
|
1540
|
+
function createX402WalletSigner(session, provider, switchChain) {
|
|
1541
|
+
const resolved = resolveX402Wallet(session, provider);
|
|
1542
|
+
if (resolved.reason) return { signer: null, reason: resolved.reason };
|
|
1543
|
+
return {
|
|
1544
|
+
signer: walletX402Signer({
|
|
1545
|
+
provider: resolved.provider,
|
|
1546
|
+
address: resolved.address,
|
|
1547
|
+
switchChain
|
|
1548
|
+
}),
|
|
1549
|
+
reason: null
|
|
1550
|
+
};
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1480
1553
|
// src/mpp-session.ts
|
|
1481
1554
|
function record2(value) {
|
|
1482
1555
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
@@ -1750,6 +1823,7 @@ export {
|
|
|
1750
1823
|
createNotification,
|
|
1751
1824
|
createNotificationSettingsStorage,
|
|
1752
1825
|
createSolanaSessionKeyFlow,
|
|
1826
|
+
createX402WalletSigner,
|
|
1753
1827
|
decodeRevertReason,
|
|
1754
1828
|
defaultSiwxDomain,
|
|
1755
1829
|
defaultSiwxUri,
|
|
@@ -1762,6 +1836,7 @@ export {
|
|
|
1762
1836
|
encodeErc20TransferFrom,
|
|
1763
1837
|
explainSpend,
|
|
1764
1838
|
fetchUserOperationReceipt,
|
|
1839
|
+
findX402Provider,
|
|
1765
1840
|
formatAuthorizationAmount,
|
|
1766
1841
|
getResolver,
|
|
1767
1842
|
getSharedSessionKeyManager,
|
|
@@ -1792,6 +1867,7 @@ export {
|
|
|
1792
1867
|
resolveRevertReason,
|
|
1793
1868
|
resolveSimulationEndpoint,
|
|
1794
1869
|
resolveUserOpChain,
|
|
1870
|
+
resolveX402Wallet,
|
|
1795
1871
|
sameExecutionIntent,
|
|
1796
1872
|
saveNotificationSettings,
|
|
1797
1873
|
selectChainCapabilities,
|