@naculus/connect-appkit-core 0.9.0 → 0.11.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 +117 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +61 -1
- package/dist/index.d.ts +61 -1
- package/dist/index.js +112 -27
- 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,9 +863,12 @@ 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;
|
|
870
|
+
/** Enforcement reported by a successful authorization compile result. */
|
|
871
|
+
enforcement?: "on-chain" | "device";
|
|
867
872
|
}
|
|
868
873
|
interface AuthorizationRecipientView {
|
|
869
874
|
shortened: string;
|
|
@@ -874,11 +879,17 @@ interface AuthorizationAmountView {
|
|
|
874
879
|
}
|
|
875
880
|
interface AuthorizationGrantView {
|
|
876
881
|
asset: AssetId;
|
|
882
|
+
assetTrust: "trusted" | "unverified" | "unchecked";
|
|
877
883
|
assetLabel: string;
|
|
878
884
|
recipients: AuthorizationRecipientView[];
|
|
879
885
|
perPayment: AuthorizationAmountView;
|
|
880
886
|
total: AuthorizationAmountView;
|
|
881
887
|
count: number | null;
|
|
888
|
+
period: {
|
|
889
|
+
amount: AuthorizationAmountView;
|
|
890
|
+
every: string;
|
|
891
|
+
startsAt: string;
|
|
892
|
+
} | null;
|
|
882
893
|
rails: string[];
|
|
883
894
|
}
|
|
884
895
|
interface AuthorizationExpiryView {
|
|
@@ -891,6 +902,8 @@ interface AuthorizationDescription {
|
|
|
891
902
|
principal: string | null;
|
|
892
903
|
grants: AuthorizationGrantView[];
|
|
893
904
|
expiry: AuthorizationExpiryView;
|
|
905
|
+
enforcement: "on-chain" | "device" | null;
|
|
906
|
+
enforcementLabel: string | null;
|
|
894
907
|
warnings: string[];
|
|
895
908
|
}
|
|
896
909
|
declare function formatAuthorizationAmount(amount: bigint, metadata: AuthorizationAssetMetadata | undefined): AuthorizationAmountView;
|
|
@@ -972,6 +985,53 @@ declare function applySettlementVerification(payment: PaymentRecord, result: Set
|
|
|
972
985
|
*/
|
|
973
986
|
declare function describePayment(input: RequestInfo | URL, result: PaymentFetchResult): PaymentRecord | null;
|
|
974
987
|
|
|
988
|
+
type X402SignerUnavailableReason = "no-session" | "not-evm" | "unsupported-wallet-type";
|
|
989
|
+
interface X402Eip1193Provider {
|
|
990
|
+
request(args: {
|
|
991
|
+
method: string;
|
|
992
|
+
params?: unknown[];
|
|
993
|
+
}): Promise<unknown>;
|
|
994
|
+
}
|
|
995
|
+
type X402WalletResolution = {
|
|
996
|
+
provider: X402Eip1193Provider;
|
|
997
|
+
address: `0x${string}`;
|
|
998
|
+
reason: null;
|
|
999
|
+
} | {
|
|
1000
|
+
provider: null;
|
|
1001
|
+
address: null;
|
|
1002
|
+
reason: X402SignerUnavailableReason;
|
|
1003
|
+
};
|
|
1004
|
+
/** Where a session's EIP-1193 provider can come from; each framework supplies its own. */
|
|
1005
|
+
interface X402ProviderSources {
|
|
1006
|
+
/** EIP-6963 wallets discovered on the page (`eip6963Connector.getDiscoveredWallets()`). */
|
|
1007
|
+
injected?: readonly {
|
|
1008
|
+
id: string;
|
|
1009
|
+
provider: X402Eip1193Provider;
|
|
1010
|
+
}[];
|
|
1011
|
+
/** The WalletConnect connector, whose `request` routes to its last session. */
|
|
1012
|
+
walletConnect?: X402Eip1193Provider | null;
|
|
1013
|
+
}
|
|
1014
|
+
/**
|
|
1015
|
+
* The provider that belongs to `session`, chosen by the session's wallet
|
|
1016
|
+
* type (never by connector identity): the injected wallet the session was
|
|
1017
|
+
* made with, or the WalletConnect connector. Null for anything else.
|
|
1018
|
+
*/
|
|
1019
|
+
declare function findX402Provider(session: UniversalWalletSession | null | undefined, sources: X402ProviderSources): X402Eip1193Provider | null;
|
|
1020
|
+
interface X402SignerResolution {
|
|
1021
|
+
signer: X402TypedDataSigner | null;
|
|
1022
|
+
reason: X402SignerUnavailableReason | null;
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* Resolve the connected EVM payer without coupling appkit-core to a connector.
|
|
1026
|
+
*
|
|
1027
|
+
* Framework bindings supply the EIP-1193 request facade owned by the active
|
|
1028
|
+
* session. Classification remains session-based: connector identity is never
|
|
1029
|
+
* used as a routing input.
|
|
1030
|
+
*/
|
|
1031
|
+
declare function resolveX402Wallet(session: UniversalWalletSession | null | undefined, provider: X402Eip1193Provider | null | undefined): X402WalletResolution;
|
|
1032
|
+
/** Build the signer after applying the shared session-routing policy. */
|
|
1033
|
+
declare function createX402WalletSigner(session: UniversalWalletSession | null | undefined, provider: X402Eip1193Provider | null | undefined, switchChain: (chainId: string) => Promise<void>): X402SignerResolution;
|
|
1034
|
+
|
|
975
1035
|
/** Request options accepted by a caller-built MPP session fetch. */
|
|
976
1036
|
interface MppSessionRequestInit extends RequestInit {
|
|
977
1037
|
units?: bigint;
|
|
@@ -1152,4 +1212,4 @@ declare function siwxResultToSession<M extends SiwxMessageLike>(result: SiwxResu
|
|
|
1152
1212
|
refreshedAt: null;
|
|
1153
1213
|
};
|
|
1154
1214
|
|
|
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 };
|
|
1215
|
+
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,9 +863,12 @@ 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;
|
|
870
|
+
/** Enforcement reported by a successful authorization compile result. */
|
|
871
|
+
enforcement?: "on-chain" | "device";
|
|
867
872
|
}
|
|
868
873
|
interface AuthorizationRecipientView {
|
|
869
874
|
shortened: string;
|
|
@@ -874,11 +879,17 @@ interface AuthorizationAmountView {
|
|
|
874
879
|
}
|
|
875
880
|
interface AuthorizationGrantView {
|
|
876
881
|
asset: AssetId;
|
|
882
|
+
assetTrust: "trusted" | "unverified" | "unchecked";
|
|
877
883
|
assetLabel: string;
|
|
878
884
|
recipients: AuthorizationRecipientView[];
|
|
879
885
|
perPayment: AuthorizationAmountView;
|
|
880
886
|
total: AuthorizationAmountView;
|
|
881
887
|
count: number | null;
|
|
888
|
+
period: {
|
|
889
|
+
amount: AuthorizationAmountView;
|
|
890
|
+
every: string;
|
|
891
|
+
startsAt: string;
|
|
892
|
+
} | null;
|
|
882
893
|
rails: string[];
|
|
883
894
|
}
|
|
884
895
|
interface AuthorizationExpiryView {
|
|
@@ -891,6 +902,8 @@ interface AuthorizationDescription {
|
|
|
891
902
|
principal: string | null;
|
|
892
903
|
grants: AuthorizationGrantView[];
|
|
893
904
|
expiry: AuthorizationExpiryView;
|
|
905
|
+
enforcement: "on-chain" | "device" | null;
|
|
906
|
+
enforcementLabel: string | null;
|
|
894
907
|
warnings: string[];
|
|
895
908
|
}
|
|
896
909
|
declare function formatAuthorizationAmount(amount: bigint, metadata: AuthorizationAssetMetadata | undefined): AuthorizationAmountView;
|
|
@@ -972,6 +985,53 @@ declare function applySettlementVerification(payment: PaymentRecord, result: Set
|
|
|
972
985
|
*/
|
|
973
986
|
declare function describePayment(input: RequestInfo | URL, result: PaymentFetchResult): PaymentRecord | null;
|
|
974
987
|
|
|
988
|
+
type X402SignerUnavailableReason = "no-session" | "not-evm" | "unsupported-wallet-type";
|
|
989
|
+
interface X402Eip1193Provider {
|
|
990
|
+
request(args: {
|
|
991
|
+
method: string;
|
|
992
|
+
params?: unknown[];
|
|
993
|
+
}): Promise<unknown>;
|
|
994
|
+
}
|
|
995
|
+
type X402WalletResolution = {
|
|
996
|
+
provider: X402Eip1193Provider;
|
|
997
|
+
address: `0x${string}`;
|
|
998
|
+
reason: null;
|
|
999
|
+
} | {
|
|
1000
|
+
provider: null;
|
|
1001
|
+
address: null;
|
|
1002
|
+
reason: X402SignerUnavailableReason;
|
|
1003
|
+
};
|
|
1004
|
+
/** Where a session's EIP-1193 provider can come from; each framework supplies its own. */
|
|
1005
|
+
interface X402ProviderSources {
|
|
1006
|
+
/** EIP-6963 wallets discovered on the page (`eip6963Connector.getDiscoveredWallets()`). */
|
|
1007
|
+
injected?: readonly {
|
|
1008
|
+
id: string;
|
|
1009
|
+
provider: X402Eip1193Provider;
|
|
1010
|
+
}[];
|
|
1011
|
+
/** The WalletConnect connector, whose `request` routes to its last session. */
|
|
1012
|
+
walletConnect?: X402Eip1193Provider | null;
|
|
1013
|
+
}
|
|
1014
|
+
/**
|
|
1015
|
+
* The provider that belongs to `session`, chosen by the session's wallet
|
|
1016
|
+
* type (never by connector identity): the injected wallet the session was
|
|
1017
|
+
* made with, or the WalletConnect connector. Null for anything else.
|
|
1018
|
+
*/
|
|
1019
|
+
declare function findX402Provider(session: UniversalWalletSession | null | undefined, sources: X402ProviderSources): X402Eip1193Provider | null;
|
|
1020
|
+
interface X402SignerResolution {
|
|
1021
|
+
signer: X402TypedDataSigner | null;
|
|
1022
|
+
reason: X402SignerUnavailableReason | null;
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* Resolve the connected EVM payer without coupling appkit-core to a connector.
|
|
1026
|
+
*
|
|
1027
|
+
* Framework bindings supply the EIP-1193 request facade owned by the active
|
|
1028
|
+
* session. Classification remains session-based: connector identity is never
|
|
1029
|
+
* used as a routing input.
|
|
1030
|
+
*/
|
|
1031
|
+
declare function resolveX402Wallet(session: UniversalWalletSession | null | undefined, provider: X402Eip1193Provider | null | undefined): X402WalletResolution;
|
|
1032
|
+
/** Build the signer after applying the shared session-routing policy. */
|
|
1033
|
+
declare function createX402WalletSigner(session: UniversalWalletSession | null | undefined, provider: X402Eip1193Provider | null | undefined, switchChain: (chainId: string) => Promise<void>): X402SignerResolution;
|
|
1034
|
+
|
|
975
1035
|
/** Request options accepted by a caller-built MPP session fetch. */
|
|
976
1036
|
interface MppSessionRequestInit extends RequestInit {
|
|
977
1037
|
units?: bigint;
|
|
@@ -1152,4 +1212,4 @@ declare function siwxResultToSession<M extends SiwxMessageLike>(result: SiwxResu
|
|
|
1152
1212
|
refreshedAt: null;
|
|
1153
1213
|
};
|
|
1154
1214
|
|
|
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 };
|
|
1215
|
+
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,39 +1300,44 @@ 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 = "";
|
|
1308
1305
|
for (let i = 0; i < value.length; i++)
|
|
1309
1306
|
out += (i && (value.length - i) % 3 === 0 ? "," : "") + value[i];
|
|
1310
1307
|
return out;
|
|
1311
1308
|
}
|
|
1312
|
-
function
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
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
|
+
);
|
|
1316
1320
|
}
|
|
1317
1321
|
function formatAuthorizationAmount(amount, metadata) {
|
|
1318
1322
|
const baseUnits = amount.toString();
|
|
1319
|
-
if (!metadata
|
|
1323
|
+
if (!metadata?.symbol || !Number.isSafeInteger(metadata.decimals) || metadata.decimals < 0 || metadata.decimals > 255) {
|
|
1320
1324
|
return {
|
|
1321
1325
|
formatted: `${groupDigits(baseUnits)} base units`
|
|
1322
1326
|
};
|
|
1323
1327
|
}
|
|
1324
1328
|
const decimals = metadata.decimals;
|
|
1325
1329
|
const padded = baseUnits.padStart(decimals + 1, "0");
|
|
1326
|
-
const integer =
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
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
|
+
};
|
|
1330
1336
|
}
|
|
1331
1337
|
function relativeExpiry(expiresAt, now, locale) {
|
|
1332
1338
|
const seconds = expiresAt - now;
|
|
1333
1339
|
const absolute = Math.abs(seconds);
|
|
1334
|
-
const divisor = absolute >= 31536e3 ? 31536e3 : absolute >= 2592e3 ? 2592e3 : absolute >= 86400 ? 86400 : absolute >= 3600 ? 3600 : absolute >= 60 ? 60 : 1;
|
|
1335
|
-
const unit = divisor === 31536e3 ? "year" : divisor === 2592e3 ? "month" : divisor === 86400 ? "day" : divisor === 3600 ? "hour" : divisor === 60 ? "minute" : "second";
|
|
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"];
|
|
1336
1341
|
const value = Math.round(seconds / divisor);
|
|
1337
1342
|
if (typeof Intl.RelativeTimeFormat !== "function") {
|
|
1338
1343
|
const count = Math.abs(value);
|
|
@@ -1341,6 +1346,25 @@ function relativeExpiry(expiresAt, now, locale) {
|
|
|
1341
1346
|
}
|
|
1342
1347
|
return new Intl.RelativeTimeFormat(locale).format(value, unit);
|
|
1343
1348
|
}
|
|
1349
|
+
function absoluteUtc(timestamp, locale) {
|
|
1350
|
+
return new Intl.DateTimeFormat(locale, {
|
|
1351
|
+
year: "numeric",
|
|
1352
|
+
month: "short",
|
|
1353
|
+
day: "numeric",
|
|
1354
|
+
hour: "2-digit",
|
|
1355
|
+
minute: "2-digit",
|
|
1356
|
+
hourCycle: "h23",
|
|
1357
|
+
timeZone: "UTC",
|
|
1358
|
+
timeZoneName: "short"
|
|
1359
|
+
}).format(timestamp * 1e3);
|
|
1360
|
+
}
|
|
1361
|
+
function formatPeriodLength(seconds) {
|
|
1362
|
+
const [amount, unit] = seconds % 604800 === 0 ? [seconds / 604800, "week"] : seconds % 86400 === 0 ? [seconds / 86400, "day"] : seconds % 3600 === 0 ? [seconds / 3600, "hour"] : seconds % 60 === 0 ? [seconds / 60, "minute"] : [seconds, "second"];
|
|
1363
|
+
return `${amount} ${unit}${amount === 1 ? "" : "s"}`;
|
|
1364
|
+
}
|
|
1365
|
+
function formatAuthorizationEnforcement(enforcement) {
|
|
1366
|
+
return enforcement === "on-chain" ? "Limits enforced by the blockchain" : enforcement === "device" ? "Limits enforced by this device" : null;
|
|
1367
|
+
}
|
|
1344
1368
|
function describeAuthorization(input, options = {}) {
|
|
1345
1369
|
const now = options.now ?? Math.floor(Date.now() / 1e3);
|
|
1346
1370
|
const locale = options.locale ?? "en";
|
|
@@ -1350,10 +1374,11 @@ function describeAuthorization(input, options = {}) {
|
|
|
1350
1374
|
label,
|
|
1351
1375
|
principal: input.principal ?? null,
|
|
1352
1376
|
grants: input.grants.map((grant) => {
|
|
1353
|
-
const metadata =
|
|
1377
|
+
const [assetTrust, metadata] = trustedMetadata(grant.asset, options);
|
|
1354
1378
|
return {
|
|
1355
1379
|
asset: grant.asset,
|
|
1356
|
-
|
|
1380
|
+
assetTrust,
|
|
1381
|
+
assetLabel: metadata?.symbol || grant.asset.split(":").at(-1),
|
|
1357
1382
|
recipients: grant.recipients.map((full) => ({
|
|
1358
1383
|
shortened: full.length <= 14 ? full : `${full.slice(0, 6)}\u2026${full.slice(-6)}`,
|
|
1359
1384
|
full
|
|
@@ -1361,23 +1386,23 @@ function describeAuthorization(input, options = {}) {
|
|
|
1361
1386
|
perPayment: formatAuthorizationAmount(grant.maxPerPayment, metadata),
|
|
1362
1387
|
total: formatAuthorizationAmount(grant.maxTotal, metadata),
|
|
1363
1388
|
count: grant.maxCount ?? null,
|
|
1389
|
+
period: grant.period ? {
|
|
1390
|
+
amount: formatAuthorizationAmount(grant.period.amount, metadata),
|
|
1391
|
+
every: formatPeriodLength(grant.period.seconds),
|
|
1392
|
+
startsAt: absoluteUtc(grant.period.start, locale)
|
|
1393
|
+
} : null,
|
|
1364
1394
|
rails: grant.rails.map((r) => r.replace("-", " "))
|
|
1365
1395
|
};
|
|
1366
1396
|
}),
|
|
1367
1397
|
expiry: {
|
|
1368
1398
|
timestamp: input.expiresAt,
|
|
1369
|
-
absolute:
|
|
1370
|
-
year: "numeric",
|
|
1371
|
-
month: "short",
|
|
1372
|
-
day: "numeric",
|
|
1373
|
-
hour: "2-digit",
|
|
1374
|
-
minute: "2-digit",
|
|
1375
|
-
hourCycle: "h23",
|
|
1376
|
-
timeZone: "UTC",
|
|
1377
|
-
timeZoneName: "short"
|
|
1378
|
-
}).format(input.expiresAt * 1e3),
|
|
1399
|
+
absolute: absoluteUtc(input.expiresAt, locale),
|
|
1379
1400
|
relative: relativeExpiry(input.expiresAt, now, locale)
|
|
1380
1401
|
},
|
|
1402
|
+
enforcement: options.enforcement ?? null,
|
|
1403
|
+
enforcementLabel: formatAuthorizationEnforcement(
|
|
1404
|
+
options.enforcement ?? null
|
|
1405
|
+
),
|
|
1381
1406
|
warnings: flags.map(
|
|
1382
1407
|
(flag) => flag === "unrestricted-recipient-legacy" ? "This key can pay any recipient." : "This key can do more than shown here."
|
|
1383
1408
|
)
|
|
@@ -1391,6 +1416,7 @@ var REFUSAL_SENTENCES = {
|
|
|
1391
1416
|
"over-per-payment": "This amount exceeds the per-payment limit.",
|
|
1392
1417
|
"over-total": "This amount exceeds the remaining total limit.",
|
|
1393
1418
|
"over-count": "This authorization has reached its payment count limit.",
|
|
1419
|
+
"period-limit-exceeded": "This amount exceeds the limit for the current period.",
|
|
1394
1420
|
"rail-not-allowed": "This payment rail is not allowed.",
|
|
1395
1421
|
"invalid-authorization": "The authorization or spend request is invalid."
|
|
1396
1422
|
};
|
|
@@ -1406,7 +1432,7 @@ function explainSpend(authorization, request, options = {}) {
|
|
|
1406
1432
|
const remainingTotal = authorization.grants[verdict.grant].maxTotal - request.spentSoFar - request.amount;
|
|
1407
1433
|
const remainingTotalFormatted = formatAuthorizationAmount(
|
|
1408
1434
|
remainingTotal,
|
|
1409
|
-
|
|
1435
|
+
trustedMetadata(authorization.grants[verdict.grant].asset, options)[1]
|
|
1410
1436
|
);
|
|
1411
1437
|
return {
|
|
1412
1438
|
allowed: true,
|
|
@@ -1488,6 +1514,62 @@ function describePayment(input, result) {
|
|
|
1488
1514
|
};
|
|
1489
1515
|
}
|
|
1490
1516
|
|
|
1517
|
+
// src/x402-wallet.ts
|
|
1518
|
+
import {
|
|
1519
|
+
isEvmAddress as isEvmAddress2,
|
|
1520
|
+
parseCaip10
|
|
1521
|
+
} from "@naculus/connect-core";
|
|
1522
|
+
import {
|
|
1523
|
+
walletX402Signer
|
|
1524
|
+
} from "@naculus/payments-x402";
|
|
1525
|
+
function findX402Provider(session, sources) {
|
|
1526
|
+
if (!session) return null;
|
|
1527
|
+
if (session.walletType === "eip6963" || session.id.startsWith("eip6963-")) {
|
|
1528
|
+
return sources.injected?.find((wallet) => wallet.id === session.walletId)?.provider ?? null;
|
|
1529
|
+
}
|
|
1530
|
+
if (session.walletType === "walletconnect") {
|
|
1531
|
+
return sources.walletConnect ?? null;
|
|
1532
|
+
}
|
|
1533
|
+
return null;
|
|
1534
|
+
}
|
|
1535
|
+
function unavailable(reason) {
|
|
1536
|
+
return { provider: null, address: null, reason };
|
|
1537
|
+
}
|
|
1538
|
+
function resolveX402Wallet(session, provider) {
|
|
1539
|
+
if (!session) return unavailable("no-session");
|
|
1540
|
+
const namespace = session.namespaces.eip155;
|
|
1541
|
+
if (!namespace) return unavailable("not-evm");
|
|
1542
|
+
const isInjected = session.walletType === "eip6963" || session.id.startsWith("eip6963-");
|
|
1543
|
+
const isWalletConnect = session.walletType === "walletconnect";
|
|
1544
|
+
if (!isInjected && !isWalletConnect || !provider?.request) {
|
|
1545
|
+
return unavailable("unsupported-wallet-type");
|
|
1546
|
+
}
|
|
1547
|
+
for (const account of namespace.accounts) {
|
|
1548
|
+
const parsed = parseCaip10(account);
|
|
1549
|
+
const address = parsed?.namespace === "eip155" ? parsed.address : account;
|
|
1550
|
+
if (isEvmAddress2(address)) {
|
|
1551
|
+
return {
|
|
1552
|
+
provider,
|
|
1553
|
+
address,
|
|
1554
|
+
reason: null
|
|
1555
|
+
};
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
return unavailable("not-evm");
|
|
1559
|
+
}
|
|
1560
|
+
function createX402WalletSigner(session, provider, switchChain) {
|
|
1561
|
+
const resolved = resolveX402Wallet(session, provider);
|
|
1562
|
+
if (resolved.reason) return { signer: null, reason: resolved.reason };
|
|
1563
|
+
return {
|
|
1564
|
+
signer: walletX402Signer({
|
|
1565
|
+
provider: resolved.provider,
|
|
1566
|
+
address: resolved.address,
|
|
1567
|
+
switchChain
|
|
1568
|
+
}),
|
|
1569
|
+
reason: null
|
|
1570
|
+
};
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1491
1573
|
// src/mpp-session.ts
|
|
1492
1574
|
function record2(value) {
|
|
1493
1575
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
@@ -1761,6 +1843,7 @@ export {
|
|
|
1761
1843
|
createNotification,
|
|
1762
1844
|
createNotificationSettingsStorage,
|
|
1763
1845
|
createSolanaSessionKeyFlow,
|
|
1846
|
+
createX402WalletSigner,
|
|
1764
1847
|
decodeRevertReason,
|
|
1765
1848
|
defaultSiwxDomain,
|
|
1766
1849
|
defaultSiwxUri,
|
|
@@ -1773,6 +1856,7 @@ export {
|
|
|
1773
1856
|
encodeErc20TransferFrom,
|
|
1774
1857
|
explainSpend,
|
|
1775
1858
|
fetchUserOperationReceipt,
|
|
1859
|
+
findX402Provider,
|
|
1776
1860
|
formatAuthorizationAmount,
|
|
1777
1861
|
getResolver,
|
|
1778
1862
|
getSharedSessionKeyManager,
|
|
@@ -1803,6 +1887,7 @@ export {
|
|
|
1803
1887
|
resolveRevertReason,
|
|
1804
1888
|
resolveSimulationEndpoint,
|
|
1805
1889
|
resolveUserOpChain,
|
|
1890
|
+
resolveX402Wallet,
|
|
1806
1891
|
sameExecutionIntent,
|
|
1807
1892
|
saveNotificationSettings,
|
|
1808
1893
|
selectChainCapabilities,
|