@naculus/connect-appkit-core 0.7.0 → 0.8.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/README.md +13 -0
- package/dist/index.cjs +141 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +79 -6
- package/dist/index.d.ts +79 -6
- package/dist/index.js +131 -3
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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, SolanaSessionKeyInfo, SolanaSessionKeyScope, SolanaSessionKeyManager, SolanaPaymentRpc } from '@naculus/connect-core';
|
|
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
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The types the framework-neutral half of appkit is built on.
|
|
@@ -43,7 +43,7 @@ interface Web3State {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
* EIP-5792 capability answers,
|
|
46
|
+
* EIP-5792 capability answers, normalized once.
|
|
47
47
|
*
|
|
48
48
|
* Deciding how to execute before sending is the whole point of
|
|
49
49
|
* `wallet_getCapabilities`, and the reasoning that turns a raw answer into
|
|
@@ -82,7 +82,7 @@ declare function normalizeCapabilities(raw: Record<string, unknown> | null | und
|
|
|
82
82
|
/**
|
|
83
83
|
* Find the entry for a chain, by CAIP-2 or by the hex form.
|
|
84
84
|
*
|
|
85
|
-
* Connectors
|
|
85
|
+
* Connectors normalize keys to CAIP-2, but a wallet answering in raw hex
|
|
86
86
|
* through a custom connector should still be found rather than reported as
|
|
87
87
|
* "unknown" next to an entry that is sitting right there.
|
|
88
88
|
*/
|
|
@@ -618,7 +618,7 @@ type ExecuteRoute = (quote: ExecutableQuote, recipient: string, options?: Execut
|
|
|
618
618
|
* a valid non-EVM address on a guess.
|
|
619
619
|
*/
|
|
620
620
|
declare function validateRouteRecipient(quote: ExecutableQuote | null | undefined, recipient: string): ExecuteRouteError | null;
|
|
621
|
-
/**
|
|
621
|
+
/** Normalize whatever an executor threw into the hook's error shape. */
|
|
622
622
|
declare function toExecuteRouteError(cause: unknown): ExecuteRouteError;
|
|
623
623
|
|
|
624
624
|
/** The subset of the config that changes what a key may spend or how it is sealed. */
|
|
@@ -854,6 +854,62 @@ interface DelegationFrameworkAdapterOptions {
|
|
|
854
854
|
}
|
|
855
855
|
declare function createDelegationFrameworkAdapter(options: DelegationFrameworkAdapterOptions): PolicyExecutionAdapter;
|
|
856
856
|
|
|
857
|
+
type AssetId = string;
|
|
858
|
+
interface AuthorizationAssetMetadata {
|
|
859
|
+
symbol: string;
|
|
860
|
+
decimals: number;
|
|
861
|
+
}
|
|
862
|
+
interface DescribeAuthorizationOptions {
|
|
863
|
+
assets?: Record<AssetId, AuthorizationAssetMetadata>;
|
|
864
|
+
locale?: string;
|
|
865
|
+
/** Unix timestamp in seconds. */
|
|
866
|
+
now?: number;
|
|
867
|
+
}
|
|
868
|
+
interface AuthorizationRecipientView {
|
|
869
|
+
shortened: string;
|
|
870
|
+
full: string;
|
|
871
|
+
}
|
|
872
|
+
interface AuthorizationAmountView {
|
|
873
|
+
formatted: string;
|
|
874
|
+
}
|
|
875
|
+
interface AuthorizationGrantView {
|
|
876
|
+
asset: AssetId;
|
|
877
|
+
assetLabel: string;
|
|
878
|
+
recipients: AuthorizationRecipientView[];
|
|
879
|
+
perPayment: AuthorizationAmountView;
|
|
880
|
+
total: AuthorizationAmountView;
|
|
881
|
+
count: number | null;
|
|
882
|
+
rails: string[];
|
|
883
|
+
}
|
|
884
|
+
interface AuthorizationExpiryView {
|
|
885
|
+
timestamp: number;
|
|
886
|
+
absolute: string;
|
|
887
|
+
relative: string;
|
|
888
|
+
}
|
|
889
|
+
interface AuthorizationDescription {
|
|
890
|
+
label: string | null;
|
|
891
|
+
principal: string | null;
|
|
892
|
+
grants: AuthorizationGrantView[];
|
|
893
|
+
expiry: AuthorizationExpiryView;
|
|
894
|
+
warnings: string[];
|
|
895
|
+
}
|
|
896
|
+
declare function formatAuthorizationAmount(amount: bigint, metadata: AuthorizationAssetMetadata | undefined): AuthorizationAmountView;
|
|
897
|
+
/** Build a network-free consent/listing view of an authorization. */
|
|
898
|
+
declare function describeAuthorization(input: Authorization | ListedAuthorization, options?: DescribeAuthorizationOptions): AuthorizationDescription;
|
|
899
|
+
type SpendExplanation = {
|
|
900
|
+
allowed: true;
|
|
901
|
+
grant: number;
|
|
902
|
+
remainingTotal: bigint;
|
|
903
|
+
remainingTotalFormatted: AuthorizationAmountView;
|
|
904
|
+
sentence: string;
|
|
905
|
+
} | {
|
|
906
|
+
allowed: false;
|
|
907
|
+
reason: SpendRefusal;
|
|
908
|
+
sentence: string;
|
|
909
|
+
};
|
|
910
|
+
/** Explain the shared evaluator's exact allow/refuse result for a UI. */
|
|
911
|
+
declare function explainSpend(authorization: Authorization, request: SpendRequest, options?: DescribeAuthorizationOptions): SpendExplanation;
|
|
912
|
+
|
|
857
913
|
/**
|
|
858
914
|
* Agentic payments (x402 / MPP) for the appkit shells.
|
|
859
915
|
*
|
|
@@ -861,7 +917,7 @@ declare function createDelegationFrameworkAdapter(options: DelegationFrameworkAd
|
|
|
861
917
|
* `@naculus/payments-x402` or `createMppFetch` from `@naculus/payments-mpp`,
|
|
862
918
|
* with the session key and limits it chooses — and the hooks only track its
|
|
863
919
|
* state. So appkit takes no dependency on either package: their results are
|
|
864
|
-
* read here by shape, and a shape this does not
|
|
920
|
+
* read here by shape, and a shape this does not recognize is reported as
|
|
865
921
|
* `protocol: "unknown"` rather than guessed at.
|
|
866
922
|
*/
|
|
867
923
|
/** What `createX402Fetch` and `createMppFetch` return, structurally. */
|
|
@@ -875,6 +931,11 @@ interface PaymentFetchResult {
|
|
|
875
931
|
receipt?: unknown;
|
|
876
932
|
}
|
|
877
933
|
type PaymentFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<PaymentFetchResult>;
|
|
934
|
+
type PaymentVerificationStatus = "unverified" | "pending" | "verified" | "mismatch" | "failed" | "unavailable";
|
|
935
|
+
interface PaymentVerification {
|
|
936
|
+
status: PaymentVerificationStatus;
|
|
937
|
+
reason?: string;
|
|
938
|
+
}
|
|
878
939
|
/** One payment, in the terms a UI shows. Amounts are token base units. */
|
|
879
940
|
interface PaymentRecord {
|
|
880
941
|
protocol: "x402" | "mpp" | "unknown";
|
|
@@ -891,7 +952,19 @@ interface PaymentRecord {
|
|
|
891
952
|
* other fields are what the client signed.
|
|
892
953
|
*/
|
|
893
954
|
reference: string | null;
|
|
955
|
+
/** A server-reported reference remains unverified until this is verified. */
|
|
956
|
+
verification: PaymentVerification;
|
|
957
|
+
}
|
|
958
|
+
declare const DEFAULT_VERIFY_RETRY: {
|
|
959
|
+
readonly attempts: 5;
|
|
960
|
+
readonly delayMs: 4000;
|
|
961
|
+
};
|
|
962
|
+
interface VerifyRetryOptions {
|
|
963
|
+
attempts: number;
|
|
964
|
+
delayMs: number;
|
|
894
965
|
}
|
|
966
|
+
/** Apply a verifier result without mutating the payment record. */
|
|
967
|
+
declare function applySettlementVerification(payment: PaymentRecord, result: SettlementVerification): PaymentRecord;
|
|
895
968
|
/**
|
|
896
969
|
* The payment a paying fetch made, or null when it paid nothing. Reads the
|
|
897
970
|
* x402 requirement / settlement (EVM or Solana) or the MPP `evm` / `solana`
|
|
@@ -1079,4 +1152,4 @@ declare function siwxResultToSession<M extends SiwxMessageLike>(result: SiwxResu
|
|
|
1079
1152
|
refreshedAt: null;
|
|
1080
1153
|
};
|
|
1081
1154
|
|
|
1082
|
-
export { type AddressValidationLevel, type AtomicSupport, type ChainCapabilities, type ChainInfo, type CompareCosts, type CompareCostsInput, type ConnectionStatus, type CostComparison, type CostComparisonOperation, type CostComparisonOptions, DEFAULT_NOTIFICATION_SETTINGS, type DecimalsCache, type DelegationFrameworkAdapterOptions, type DelegationPolicyDeps, type DelegationPolicyFlow, type DelegationPolicyPreview, type DelegationTypedData, 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 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 TokenIdentity, type TransactionSimulationContext, type ViemChainShape, type WalletChain, type Web3Action, type Web3State, __resetResolverForTests, addInAppNotification, assertHexSignature, atomicSupportFor, bareEvmAddress, buildDelegationPolicyMessage, buildSmartAccountConfig, chainNamespace, chainNumber, chainsForNamespace, channelsUpdate, clearOneInAppNotification, compareCostsKey, createDecimalsCache, createDelegationFrameworkAdapter, createDelegationPolicyFlow, createNotification, createNotificationSettingsStorage, createSolanaSessionKeyFlow, decodeRevertReason, defaultSiwxDomain, defaultSiwxUri, describeChain, describePayment, eip155ChainIdToNumber, encodeErc20Approve, encodeErc20Transfer, encodeErc20TransferFrom, fetchUserOperationReceipt, 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 };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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, SolanaSessionKeyInfo, SolanaSessionKeyScope, SolanaSessionKeyManager, SolanaPaymentRpc } from '@naculus/connect-core';
|
|
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
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The types the framework-neutral half of appkit is built on.
|
|
@@ -43,7 +43,7 @@ interface Web3State {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
* EIP-5792 capability answers,
|
|
46
|
+
* EIP-5792 capability answers, normalized once.
|
|
47
47
|
*
|
|
48
48
|
* Deciding how to execute before sending is the whole point of
|
|
49
49
|
* `wallet_getCapabilities`, and the reasoning that turns a raw answer into
|
|
@@ -82,7 +82,7 @@ declare function normalizeCapabilities(raw: Record<string, unknown> | null | und
|
|
|
82
82
|
/**
|
|
83
83
|
* Find the entry for a chain, by CAIP-2 or by the hex form.
|
|
84
84
|
*
|
|
85
|
-
* Connectors
|
|
85
|
+
* Connectors normalize keys to CAIP-2, but a wallet answering in raw hex
|
|
86
86
|
* through a custom connector should still be found rather than reported as
|
|
87
87
|
* "unknown" next to an entry that is sitting right there.
|
|
88
88
|
*/
|
|
@@ -618,7 +618,7 @@ type ExecuteRoute = (quote: ExecutableQuote, recipient: string, options?: Execut
|
|
|
618
618
|
* a valid non-EVM address on a guess.
|
|
619
619
|
*/
|
|
620
620
|
declare function validateRouteRecipient(quote: ExecutableQuote | null | undefined, recipient: string): ExecuteRouteError | null;
|
|
621
|
-
/**
|
|
621
|
+
/** Normalize whatever an executor threw into the hook's error shape. */
|
|
622
622
|
declare function toExecuteRouteError(cause: unknown): ExecuteRouteError;
|
|
623
623
|
|
|
624
624
|
/** The subset of the config that changes what a key may spend or how it is sealed. */
|
|
@@ -854,6 +854,62 @@ interface DelegationFrameworkAdapterOptions {
|
|
|
854
854
|
}
|
|
855
855
|
declare function createDelegationFrameworkAdapter(options: DelegationFrameworkAdapterOptions): PolicyExecutionAdapter;
|
|
856
856
|
|
|
857
|
+
type AssetId = string;
|
|
858
|
+
interface AuthorizationAssetMetadata {
|
|
859
|
+
symbol: string;
|
|
860
|
+
decimals: number;
|
|
861
|
+
}
|
|
862
|
+
interface DescribeAuthorizationOptions {
|
|
863
|
+
assets?: Record<AssetId, AuthorizationAssetMetadata>;
|
|
864
|
+
locale?: string;
|
|
865
|
+
/** Unix timestamp in seconds. */
|
|
866
|
+
now?: number;
|
|
867
|
+
}
|
|
868
|
+
interface AuthorizationRecipientView {
|
|
869
|
+
shortened: string;
|
|
870
|
+
full: string;
|
|
871
|
+
}
|
|
872
|
+
interface AuthorizationAmountView {
|
|
873
|
+
formatted: string;
|
|
874
|
+
}
|
|
875
|
+
interface AuthorizationGrantView {
|
|
876
|
+
asset: AssetId;
|
|
877
|
+
assetLabel: string;
|
|
878
|
+
recipients: AuthorizationRecipientView[];
|
|
879
|
+
perPayment: AuthorizationAmountView;
|
|
880
|
+
total: AuthorizationAmountView;
|
|
881
|
+
count: number | null;
|
|
882
|
+
rails: string[];
|
|
883
|
+
}
|
|
884
|
+
interface AuthorizationExpiryView {
|
|
885
|
+
timestamp: number;
|
|
886
|
+
absolute: string;
|
|
887
|
+
relative: string;
|
|
888
|
+
}
|
|
889
|
+
interface AuthorizationDescription {
|
|
890
|
+
label: string | null;
|
|
891
|
+
principal: string | null;
|
|
892
|
+
grants: AuthorizationGrantView[];
|
|
893
|
+
expiry: AuthorizationExpiryView;
|
|
894
|
+
warnings: string[];
|
|
895
|
+
}
|
|
896
|
+
declare function formatAuthorizationAmount(amount: bigint, metadata: AuthorizationAssetMetadata | undefined): AuthorizationAmountView;
|
|
897
|
+
/** Build a network-free consent/listing view of an authorization. */
|
|
898
|
+
declare function describeAuthorization(input: Authorization | ListedAuthorization, options?: DescribeAuthorizationOptions): AuthorizationDescription;
|
|
899
|
+
type SpendExplanation = {
|
|
900
|
+
allowed: true;
|
|
901
|
+
grant: number;
|
|
902
|
+
remainingTotal: bigint;
|
|
903
|
+
remainingTotalFormatted: AuthorizationAmountView;
|
|
904
|
+
sentence: string;
|
|
905
|
+
} | {
|
|
906
|
+
allowed: false;
|
|
907
|
+
reason: SpendRefusal;
|
|
908
|
+
sentence: string;
|
|
909
|
+
};
|
|
910
|
+
/** Explain the shared evaluator's exact allow/refuse result for a UI. */
|
|
911
|
+
declare function explainSpend(authorization: Authorization, request: SpendRequest, options?: DescribeAuthorizationOptions): SpendExplanation;
|
|
912
|
+
|
|
857
913
|
/**
|
|
858
914
|
* Agentic payments (x402 / MPP) for the appkit shells.
|
|
859
915
|
*
|
|
@@ -861,7 +917,7 @@ declare function createDelegationFrameworkAdapter(options: DelegationFrameworkAd
|
|
|
861
917
|
* `@naculus/payments-x402` or `createMppFetch` from `@naculus/payments-mpp`,
|
|
862
918
|
* with the session key and limits it chooses — and the hooks only track its
|
|
863
919
|
* state. So appkit takes no dependency on either package: their results are
|
|
864
|
-
* read here by shape, and a shape this does not
|
|
920
|
+
* read here by shape, and a shape this does not recognize is reported as
|
|
865
921
|
* `protocol: "unknown"` rather than guessed at.
|
|
866
922
|
*/
|
|
867
923
|
/** What `createX402Fetch` and `createMppFetch` return, structurally. */
|
|
@@ -875,6 +931,11 @@ interface PaymentFetchResult {
|
|
|
875
931
|
receipt?: unknown;
|
|
876
932
|
}
|
|
877
933
|
type PaymentFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<PaymentFetchResult>;
|
|
934
|
+
type PaymentVerificationStatus = "unverified" | "pending" | "verified" | "mismatch" | "failed" | "unavailable";
|
|
935
|
+
interface PaymentVerification {
|
|
936
|
+
status: PaymentVerificationStatus;
|
|
937
|
+
reason?: string;
|
|
938
|
+
}
|
|
878
939
|
/** One payment, in the terms a UI shows. Amounts are token base units. */
|
|
879
940
|
interface PaymentRecord {
|
|
880
941
|
protocol: "x402" | "mpp" | "unknown";
|
|
@@ -891,7 +952,19 @@ interface PaymentRecord {
|
|
|
891
952
|
* other fields are what the client signed.
|
|
892
953
|
*/
|
|
893
954
|
reference: string | null;
|
|
955
|
+
/** A server-reported reference remains unverified until this is verified. */
|
|
956
|
+
verification: PaymentVerification;
|
|
957
|
+
}
|
|
958
|
+
declare const DEFAULT_VERIFY_RETRY: {
|
|
959
|
+
readonly attempts: 5;
|
|
960
|
+
readonly delayMs: 4000;
|
|
961
|
+
};
|
|
962
|
+
interface VerifyRetryOptions {
|
|
963
|
+
attempts: number;
|
|
964
|
+
delayMs: number;
|
|
894
965
|
}
|
|
966
|
+
/** Apply a verifier result without mutating the payment record. */
|
|
967
|
+
declare function applySettlementVerification(payment: PaymentRecord, result: SettlementVerification): PaymentRecord;
|
|
895
968
|
/**
|
|
896
969
|
* The payment a paying fetch made, or null when it paid nothing. Reads the
|
|
897
970
|
* x402 requirement / settlement (EVM or Solana) or the MPP `evm` / `solana`
|
|
@@ -1079,4 +1152,4 @@ declare function siwxResultToSession<M extends SiwxMessageLike>(result: SiwxResu
|
|
|
1079
1152
|
refreshedAt: null;
|
|
1080
1153
|
};
|
|
1081
1154
|
|
|
1082
|
-
export { type AddressValidationLevel, type AtomicSupport, type ChainCapabilities, type ChainInfo, type CompareCosts, type CompareCostsInput, type ConnectionStatus, type CostComparison, type CostComparisonOperation, type CostComparisonOptions, DEFAULT_NOTIFICATION_SETTINGS, type DecimalsCache, type DelegationFrameworkAdapterOptions, type DelegationPolicyDeps, type DelegationPolicyFlow, type DelegationPolicyPreview, type DelegationTypedData, 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 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 TokenIdentity, type TransactionSimulationContext, type ViemChainShape, type WalletChain, type Web3Action, type Web3State, __resetResolverForTests, addInAppNotification, assertHexSignature, atomicSupportFor, bareEvmAddress, buildDelegationPolicyMessage, buildSmartAccountConfig, chainNamespace, chainNumber, chainsForNamespace, channelsUpdate, clearOneInAppNotification, compareCostsKey, createDecimalsCache, createDelegationFrameworkAdapter, createDelegationPolicyFlow, createNotification, createNotificationSettingsStorage, createSolanaSessionKeyFlow, decodeRevertReason, defaultSiwxDomain, defaultSiwxUri, describeChain, describePayment, eip155ChainIdToNumber, encodeErc20Approve, encodeErc20Transfer, encodeErc20TransferFrom, fetchUserOperationReceipt, 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 };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1296,7 +1296,127 @@ function createDelegationPolicyFlow(deps) {
|
|
|
1296
1296
|
};
|
|
1297
1297
|
}
|
|
1298
1298
|
|
|
1299
|
+
// src/authorization.ts
|
|
1300
|
+
import {
|
|
1301
|
+
evaluateSpend
|
|
1302
|
+
} from "@naculus/connect-core";
|
|
1303
|
+
function assetAddress(asset) {
|
|
1304
|
+
return asset.split(/[:/]/).at(-1);
|
|
1305
|
+
}
|
|
1306
|
+
function groupDigits(value) {
|
|
1307
|
+
return value.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
1308
|
+
}
|
|
1309
|
+
function formatAuthorizationAmount(amount, metadata) {
|
|
1310
|
+
const baseUnits = amount.toString();
|
|
1311
|
+
if (!metadata || !metadata.symbol || !Number.isSafeInteger(metadata.decimals) || metadata.decimals < 0) {
|
|
1312
|
+
return {
|
|
1313
|
+
formatted: `${groupDigits(baseUnits)} base units`
|
|
1314
|
+
};
|
|
1315
|
+
}
|
|
1316
|
+
const decimals = metadata.decimals;
|
|
1317
|
+
const padded = baseUnits.padStart(decimals + 1, "0");
|
|
1318
|
+
const integer = decimals === 0 ? padded : padded.slice(0, -decimals);
|
|
1319
|
+
const fraction = decimals === 0 ? "" : padded.slice(-decimals).replace(/0+$/, "");
|
|
1320
|
+
const value = `${groupDigits(integer)}${fraction ? `.${fraction}` : ""}`;
|
|
1321
|
+
return { formatted: `${value} ${metadata.symbol}` };
|
|
1322
|
+
}
|
|
1323
|
+
function relativeExpiry(expiresAt, now, locale) {
|
|
1324
|
+
const seconds = expiresAt - now;
|
|
1325
|
+
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 unit = divisor === 31536e3 ? "year" : divisor === 2592e3 ? "month" : divisor === 86400 ? "day" : divisor === 3600 ? "hour" : divisor === 60 ? "minute" : "second";
|
|
1328
|
+
return new Intl.RelativeTimeFormat(locale).format(
|
|
1329
|
+
Math.round(seconds / divisor),
|
|
1330
|
+
unit
|
|
1331
|
+
);
|
|
1332
|
+
}
|
|
1333
|
+
function describeAuthorization(input, options = {}) {
|
|
1334
|
+
const now = options.now ?? Math.floor(Date.now() / 1e3);
|
|
1335
|
+
const locale = options.locale ?? "en";
|
|
1336
|
+
const flags = "flags" in input ? input.flags : [];
|
|
1337
|
+
const label = "label" in input ? input.label ?? null : null;
|
|
1338
|
+
return {
|
|
1339
|
+
label,
|
|
1340
|
+
principal: input.principal ?? null,
|
|
1341
|
+
grants: input.grants.map((grant) => {
|
|
1342
|
+
const metadata = options.assets?.[grant.asset];
|
|
1343
|
+
return {
|
|
1344
|
+
asset: grant.asset,
|
|
1345
|
+
assetLabel: metadata?.symbol || assetAddress(grant.asset),
|
|
1346
|
+
recipients: grant.recipients.map((full) => ({
|
|
1347
|
+
shortened: full.length <= 14 ? full : `${full.slice(0, 6)}\u2026${full.slice(-6)}`,
|
|
1348
|
+
full
|
|
1349
|
+
})),
|
|
1350
|
+
perPayment: formatAuthorizationAmount(grant.maxPerPayment, metadata),
|
|
1351
|
+
total: formatAuthorizationAmount(grant.maxTotal, metadata),
|
|
1352
|
+
count: grant.maxCount ?? null,
|
|
1353
|
+
rails: grant.rails.map((r) => r.replace("-", " "))
|
|
1354
|
+
};
|
|
1355
|
+
}),
|
|
1356
|
+
expiry: {
|
|
1357
|
+
timestamp: input.expiresAt,
|
|
1358
|
+
absolute: new Intl.DateTimeFormat(locale, {
|
|
1359
|
+
year: "numeric",
|
|
1360
|
+
month: "short",
|
|
1361
|
+
day: "numeric",
|
|
1362
|
+
hour: "2-digit",
|
|
1363
|
+
minute: "2-digit",
|
|
1364
|
+
hourCycle: "h23",
|
|
1365
|
+
timeZone: "UTC",
|
|
1366
|
+
timeZoneName: "short"
|
|
1367
|
+
}).format(input.expiresAt * 1e3),
|
|
1368
|
+
relative: relativeExpiry(input.expiresAt, now, locale)
|
|
1369
|
+
},
|
|
1370
|
+
warnings: flags.map(
|
|
1371
|
+
(flag) => flag === "unrestricted-recipient-legacy" ? "This key can pay any recipient." : "This key can do more than shown here."
|
|
1372
|
+
)
|
|
1373
|
+
};
|
|
1374
|
+
}
|
|
1375
|
+
var REFUSAL_SENTENCES = {
|
|
1376
|
+
expired: "This authorization has expired.",
|
|
1377
|
+
"not-yet-valid": "This authorization is not valid yet.",
|
|
1378
|
+
"no-matching-grant": "No grant covers this asset.",
|
|
1379
|
+
"recipient-not-allowed": "This recipient is not allowed.",
|
|
1380
|
+
"over-per-payment": "This amount exceeds the per-payment limit.",
|
|
1381
|
+
"over-total": "This amount exceeds the remaining total limit.",
|
|
1382
|
+
"over-count": "This authorization has reached its payment count limit.",
|
|
1383
|
+
"rail-not-allowed": "This payment rail is not allowed.",
|
|
1384
|
+
"invalid-authorization": "The authorization or spend request is invalid."
|
|
1385
|
+
};
|
|
1386
|
+
function explainSpend(authorization, request, options = {}) {
|
|
1387
|
+
const verdict = evaluateSpend(authorization, request);
|
|
1388
|
+
if (!verdict.allow) {
|
|
1389
|
+
return {
|
|
1390
|
+
allowed: false,
|
|
1391
|
+
reason: verdict.reason,
|
|
1392
|
+
sentence: REFUSAL_SENTENCES[verdict.reason]
|
|
1393
|
+
};
|
|
1394
|
+
}
|
|
1395
|
+
const remainingTotal = authorization.grants[verdict.grant].maxTotal - request.spentSoFar - request.amount;
|
|
1396
|
+
const remainingTotalFormatted = formatAuthorizationAmount(
|
|
1397
|
+
remainingTotal,
|
|
1398
|
+
options.assets?.[authorization.grants[verdict.grant].asset]
|
|
1399
|
+
);
|
|
1400
|
+
return {
|
|
1401
|
+
allowed: true,
|
|
1402
|
+
grant: verdict.grant,
|
|
1403
|
+
remainingTotal,
|
|
1404
|
+
remainingTotalFormatted,
|
|
1405
|
+
sentence: `Allowed by grant ${verdict.grant + 1}; ${remainingTotalFormatted.formatted} remain.`
|
|
1406
|
+
};
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1299
1409
|
// src/payment-fetch.ts
|
|
1410
|
+
var DEFAULT_VERIFY_RETRY = { attempts: 5, delayMs: 4e3 };
|
|
1411
|
+
function applySettlementVerification(payment, result) {
|
|
1412
|
+
return {
|
|
1413
|
+
...payment,
|
|
1414
|
+
verification: {
|
|
1415
|
+
status: result.status,
|
|
1416
|
+
..."reason" in result && result.reason !== void 0 ? { reason: result.reason } : {}
|
|
1417
|
+
}
|
|
1418
|
+
};
|
|
1419
|
+
}
|
|
1300
1420
|
function record(value) {
|
|
1301
1421
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
1302
1422
|
}
|
|
@@ -1326,7 +1446,8 @@ function describePayment(input, result) {
|
|
|
1326
1446
|
payTo: text(paid.payTo),
|
|
1327
1447
|
amount: text(paid.amount),
|
|
1328
1448
|
// A hash reported for another chain is not this payment's.
|
|
1329
|
-
reference: settlement?.success === true && settlement.network === paid.network ? text(settlement.transaction) : null
|
|
1449
|
+
reference: settlement?.success === true && settlement.network === paid.network ? text(settlement.transaction) : null,
|
|
1450
|
+
verification: { status: "unverified" }
|
|
1330
1451
|
};
|
|
1331
1452
|
}
|
|
1332
1453
|
const challenge = record(record(paid.challenge)?.params);
|
|
@@ -1340,7 +1461,8 @@ function describePayment(input, result) {
|
|
|
1340
1461
|
asset: text(request.currency),
|
|
1341
1462
|
payTo: text(request.recipient),
|
|
1342
1463
|
amount: text(request.amount),
|
|
1343
|
-
reference: text(record(result.receipt)?.reference)
|
|
1464
|
+
reference: text(record(result.receipt)?.reference),
|
|
1465
|
+
verification: { status: "unverified" }
|
|
1344
1466
|
};
|
|
1345
1467
|
}
|
|
1346
1468
|
return {
|
|
@@ -1350,7 +1472,8 @@ function describePayment(input, result) {
|
|
|
1350
1472
|
asset: null,
|
|
1351
1473
|
payTo: null,
|
|
1352
1474
|
amount: null,
|
|
1353
|
-
reference: null
|
|
1475
|
+
reference: null,
|
|
1476
|
+
verification: { status: "unverified" }
|
|
1354
1477
|
};
|
|
1355
1478
|
}
|
|
1356
1479
|
|
|
@@ -1604,10 +1727,12 @@ function siwxResultToSession(result, now = /* @__PURE__ */ new Date()) {
|
|
|
1604
1727
|
}
|
|
1605
1728
|
export {
|
|
1606
1729
|
DEFAULT_NOTIFICATION_SETTINGS,
|
|
1730
|
+
DEFAULT_VERIFY_RETRY,
|
|
1607
1731
|
InvalidUserOperationReceiptError,
|
|
1608
1732
|
NOTIFICATION_SETTINGS_KEY,
|
|
1609
1733
|
__resetResolverForTests,
|
|
1610
1734
|
addInAppNotification,
|
|
1735
|
+
applySettlementVerification,
|
|
1611
1736
|
assertHexSignature,
|
|
1612
1737
|
atomicSupportFor,
|
|
1613
1738
|
bareEvmAddress,
|
|
@@ -1628,13 +1753,16 @@ export {
|
|
|
1628
1753
|
decodeRevertReason,
|
|
1629
1754
|
defaultSiwxDomain,
|
|
1630
1755
|
defaultSiwxUri,
|
|
1756
|
+
describeAuthorization,
|
|
1631
1757
|
describeChain,
|
|
1632
1758
|
describePayment,
|
|
1633
1759
|
eip155ChainIdToNumber,
|
|
1634
1760
|
encodeErc20Approve,
|
|
1635
1761
|
encodeErc20Transfer,
|
|
1636
1762
|
encodeErc20TransferFrom,
|
|
1763
|
+
explainSpend,
|
|
1637
1764
|
fetchUserOperationReceipt,
|
|
1765
|
+
formatAuthorizationAmount,
|
|
1638
1766
|
getResolver,
|
|
1639
1767
|
getSharedSessionKeyManager,
|
|
1640
1768
|
initialWeb3State,
|