@naculus/connect-appkit-core 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts 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 } 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, 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.
@@ -890,6 +890,55 @@ interface PaymentRecord {
890
890
  */
891
891
  declare function describePayment(input: RequestInfo | URL, result: PaymentFetchResult): PaymentRecord | null;
892
892
 
893
+ /**
894
+ * Solana session keys for the appkit shells (connect-lib STATE thread 18).
895
+ *
896
+ * The app builds the `SolanaSessionKeyManager` (its storage and password) and
897
+ * the RPC; the owner is the connected wallet's Solana signer role. Creating a
898
+ * key asks the wallet once to sign an SPL `ApproveChecked` (the key becomes
899
+ * the delegate of the owner's token account for that mint, up to the budget)
900
+ * and broadcasts it; revoking asks it to sign `Revoke`. Payments then go
901
+ * through `createX402Fetch` / `createMppFetch` with
902
+ * `solana: { sessionKey: { manager, id }, rpc }` — no prompt.
903
+ */
904
+ interface SolanaOwnerSigner {
905
+ address: string;
906
+ signTransaction(transaction: Uint8Array): Promise<Uint8Array>;
907
+ }
908
+ interface SolanaSessionKeyFlowDeps {
909
+ manager: SolanaSessionKeyManager;
910
+ /** Must implement `sendTransaction` (e.g. `solanaPaymentRpc(url)`). */
911
+ rpc: SolanaPaymentRpc;
912
+ owner: SolanaOwnerSigner;
913
+ }
914
+ interface SolanaSessionKeyFlow {
915
+ /** The owner's keys, newest first. */
916
+ list(): Promise<SolanaSessionKeyInfo[]>;
917
+ /**
918
+ * Create a key, have the owner approve it, broadcast the approval.
919
+ * Approving replaces any delegate the owner's token account already had.
920
+ *
921
+ * On any failure the new key is revoked here, so it never signs. A failed
922
+ * broadcast does not prove the approval did not land (a timeout after
923
+ * submission): the error then says so, and `revoke(id)` sends the owner's
924
+ * on-chain `Revoke` to be sure.
925
+ */
926
+ create(scope: SolanaSessionKeyScope): Promise<{
927
+ key: SolanaSessionKeyInfo;
928
+ signature: string;
929
+ }>;
930
+ /**
931
+ * Stop the key here at once (before anything else can fail), then have the
932
+ * owner sign `Revoke` and broadcast it. If that fails, the key stays
933
+ * revoked locally; the on-chain delegate stays until a later revoke lands.
934
+ * Also works on a key already revoked locally.
935
+ */
936
+ revoke(id: string): Promise<{
937
+ signature: string;
938
+ }>;
939
+ }
940
+ declare function createSolanaSessionKeyFlow(deps: SolanaSessionKeyFlowDeps): SolanaSessionKeyFlow;
941
+
893
942
  declare function withTimeout<T>(promise: Promise<T>, ms: number, label?: string): Promise<T>;
894
943
  interface RetryOptions {
895
944
  maxRetries: number;
@@ -897,7 +946,12 @@ interface RetryOptions {
897
946
  label?: string;
898
947
  }
899
948
  declare function withRetry<T>(fn: () => Promise<T>, options: RetryOptions): Promise<T>;
900
- /** Convert EIP-1193 chainChanged values into the CAIP-2 form used by sessions. */
949
+ /**
950
+ * Convert EIP-1193 chainChanged values into the CAIP-2 form used by sessions.
951
+ * Refuses chain 0 and anything above `Number.MAX_SAFE_INTEGER`, as
952
+ * connect-core's `normalizeEip155ChainId` does; switch to that export once
953
+ * the connect-lib release that adds it is the minimum supported version.
954
+ */
901
955
  declare function normalizeEip155ChainId(value: unknown): string | undefined;
902
956
  declare function toEip155Accounts(accounts: unknown[], chainId: string): string[];
903
957
  /**
@@ -962,4 +1016,4 @@ declare function siwxResultToSession<M extends SiwxMessageLike>(result: SiwxResu
962
1016
  refreshedAt: null;
963
1017
  };
964
1018
 
965
- 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, NOTIFICATION_SETTINGS_KEY, type NotificationSettingsStorage, 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 SolanaPayer, type SolanaRoles, type SolanaRolesAbsence, type SolanaRolesSource, type SolanaRolesState, 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, 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, readDecimals, readSolanaRoles, 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 };
1019
+ 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, NOTIFICATION_SETTINGS_KEY, type NotificationSettingsStorage, 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, readDecimals, readSolanaRoles, 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 } 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, 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.
@@ -890,6 +890,55 @@ interface PaymentRecord {
890
890
  */
891
891
  declare function describePayment(input: RequestInfo | URL, result: PaymentFetchResult): PaymentRecord | null;
892
892
 
893
+ /**
894
+ * Solana session keys for the appkit shells (connect-lib STATE thread 18).
895
+ *
896
+ * The app builds the `SolanaSessionKeyManager` (its storage and password) and
897
+ * the RPC; the owner is the connected wallet's Solana signer role. Creating a
898
+ * key asks the wallet once to sign an SPL `ApproveChecked` (the key becomes
899
+ * the delegate of the owner's token account for that mint, up to the budget)
900
+ * and broadcasts it; revoking asks it to sign `Revoke`. Payments then go
901
+ * through `createX402Fetch` / `createMppFetch` with
902
+ * `solana: { sessionKey: { manager, id }, rpc }` — no prompt.
903
+ */
904
+ interface SolanaOwnerSigner {
905
+ address: string;
906
+ signTransaction(transaction: Uint8Array): Promise<Uint8Array>;
907
+ }
908
+ interface SolanaSessionKeyFlowDeps {
909
+ manager: SolanaSessionKeyManager;
910
+ /** Must implement `sendTransaction` (e.g. `solanaPaymentRpc(url)`). */
911
+ rpc: SolanaPaymentRpc;
912
+ owner: SolanaOwnerSigner;
913
+ }
914
+ interface SolanaSessionKeyFlow {
915
+ /** The owner's keys, newest first. */
916
+ list(): Promise<SolanaSessionKeyInfo[]>;
917
+ /**
918
+ * Create a key, have the owner approve it, broadcast the approval.
919
+ * Approving replaces any delegate the owner's token account already had.
920
+ *
921
+ * On any failure the new key is revoked here, so it never signs. A failed
922
+ * broadcast does not prove the approval did not land (a timeout after
923
+ * submission): the error then says so, and `revoke(id)` sends the owner's
924
+ * on-chain `Revoke` to be sure.
925
+ */
926
+ create(scope: SolanaSessionKeyScope): Promise<{
927
+ key: SolanaSessionKeyInfo;
928
+ signature: string;
929
+ }>;
930
+ /**
931
+ * Stop the key here at once (before anything else can fail), then have the
932
+ * owner sign `Revoke` and broadcast it. If that fails, the key stays
933
+ * revoked locally; the on-chain delegate stays until a later revoke lands.
934
+ * Also works on a key already revoked locally.
935
+ */
936
+ revoke(id: string): Promise<{
937
+ signature: string;
938
+ }>;
939
+ }
940
+ declare function createSolanaSessionKeyFlow(deps: SolanaSessionKeyFlowDeps): SolanaSessionKeyFlow;
941
+
893
942
  declare function withTimeout<T>(promise: Promise<T>, ms: number, label?: string): Promise<T>;
894
943
  interface RetryOptions {
895
944
  maxRetries: number;
@@ -897,7 +946,12 @@ interface RetryOptions {
897
946
  label?: string;
898
947
  }
899
948
  declare function withRetry<T>(fn: () => Promise<T>, options: RetryOptions): Promise<T>;
900
- /** Convert EIP-1193 chainChanged values into the CAIP-2 form used by sessions. */
949
+ /**
950
+ * Convert EIP-1193 chainChanged values into the CAIP-2 form used by sessions.
951
+ * Refuses chain 0 and anything above `Number.MAX_SAFE_INTEGER`, as
952
+ * connect-core's `normalizeEip155ChainId` does; switch to that export once
953
+ * the connect-lib release that adds it is the minimum supported version.
954
+ */
901
955
  declare function normalizeEip155ChainId(value: unknown): string | undefined;
902
956
  declare function toEip155Accounts(accounts: unknown[], chainId: string): string[];
903
957
  /**
@@ -962,4 +1016,4 @@ declare function siwxResultToSession<M extends SiwxMessageLike>(result: SiwxResu
962
1016
  refreshedAt: null;
963
1017
  };
964
1018
 
965
- 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, NOTIFICATION_SETTINGS_KEY, type NotificationSettingsStorage, 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 SolanaPayer, type SolanaRoles, type SolanaRolesAbsence, type SolanaRolesSource, type SolanaRolesState, 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, 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, readDecimals, readSolanaRoles, 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 };
1019
+ 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, NOTIFICATION_SETTINGS_KEY, type NotificationSettingsStorage, 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, readDecimals, readSolanaRoles, 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
@@ -1347,6 +1347,89 @@ function describePayment(input, result) {
1347
1347
  };
1348
1348
  }
1349
1349
 
1350
+ // src/solana-session-key.ts
1351
+ import {
1352
+ verifySignedOwnerTransaction,
1353
+ WalletError as WalletError9
1354
+ } from "@naculus/connect-core";
1355
+ function send(rpc) {
1356
+ const sendTransaction = rpc.sendTransaction;
1357
+ if (!sendTransaction) {
1358
+ throw new WalletError9(
1359
+ "invalid_input",
1360
+ "The Solana RPC must implement sendTransaction to approve or revoke."
1361
+ );
1362
+ }
1363
+ return (tx) => sendTransaction.call(rpc, tx);
1364
+ }
1365
+ function createSolanaSessionKeyFlow(deps) {
1366
+ const { manager, rpc, owner } = deps;
1367
+ const list = async () => (await manager.listSessions()).filter((key) => key.owner === owner.address).sort((a, b) => b.createdAt - a.createdAt);
1368
+ return {
1369
+ list,
1370
+ async create(scope) {
1371
+ const broadcast = send(rpc);
1372
+ const draft = await manager.createSessionKey(scope, owner.address, rpc);
1373
+ let approval;
1374
+ try {
1375
+ const { transaction, recentBlockhash } = await manager.prepareApproval(
1376
+ draft.id,
1377
+ rpc
1378
+ );
1379
+ const signed = await owner.signTransaction(transaction);
1380
+ approval = await manager.attachApproval(
1381
+ draft.id,
1382
+ signed,
1383
+ recentBlockhash
1384
+ );
1385
+ } catch (cause) {
1386
+ await manager.revoke(draft.id).catch(() => {
1387
+ });
1388
+ throw cause;
1389
+ }
1390
+ let signature;
1391
+ try {
1392
+ signature = await broadcast(approval);
1393
+ } catch (cause) {
1394
+ await manager.revoke(draft.id).catch(() => {
1395
+ });
1396
+ throw new WalletError9(
1397
+ "rpc_error",
1398
+ `The approval could not be confirmed as sent (${cause instanceof Error ? cause.message : String(cause)}); the key is revoked here. Call revoke("${draft.id}") to send the on-chain Revoke in case it landed.`
1399
+ );
1400
+ }
1401
+ const key = (await list().catch(() => [])).find((k) => k.id === draft.id);
1402
+ return { key: key ?? { ...draft, status: "active" }, signature };
1403
+ },
1404
+ async revoke(id) {
1405
+ const key = (await list()).find((k) => k.id === id);
1406
+ if (!key) {
1407
+ throw new WalletError9(
1408
+ "invalid_input",
1409
+ `No Solana session key ${id} for this owner.`
1410
+ );
1411
+ }
1412
+ await manager.revoke(id);
1413
+ const broadcast = send(rpc);
1414
+ const { transaction, recentBlockhash } = await manager.prepareRevocation(
1415
+ id,
1416
+ rpc
1417
+ );
1418
+ const signed = await owner.signTransaction(transaction);
1419
+ const revocation = verifySignedOwnerTransaction(signed, {
1420
+ kind: "revoke",
1421
+ revocation: {
1422
+ owner: key.owner,
1423
+ mint: key.scope.mint,
1424
+ tokenProgram: key.tokenProgram,
1425
+ recentBlockhash
1426
+ }
1427
+ });
1428
+ return { signature: await broadcast(revocation) };
1429
+ }
1430
+ };
1431
+ }
1432
+
1350
1433
  // src/web3-store.ts
1351
1434
  import { logger } from "@naculus/connect-core";
1352
1435
  function withTimeout(promise, ms, label = "Operation") {
@@ -1382,18 +1465,25 @@ async function withRetry(fn, options) {
1382
1465
  }
1383
1466
  function normalizeEip155ChainId(value) {
1384
1467
  if (typeof value !== "string") return void 0;
1468
+ let raw;
1469
+ if (value.startsWith("eip155:")) {
1470
+ raw = value.slice("eip155:".length);
1471
+ if (!/^\d+$/.test(raw)) return void 0;
1472
+ } else if (/^0x[0-9a-f]+$/i.test(value) || /^\d+$/.test(value)) {
1473
+ raw = value;
1474
+ } else {
1475
+ return void 0;
1476
+ }
1477
+ let numeric;
1385
1478
  try {
1386
- if (value.startsWith("eip155:")) {
1387
- const reference = value.slice("eip155:".length);
1388
- if (!/^\d+$/.test(reference)) return void 0;
1389
- return `eip155:${BigInt(reference).toString(10)}`;
1390
- }
1391
- if (/^0x[0-9a-f]+$/i.test(value) || /^\d+$/.test(value)) {
1392
- return `eip155:${BigInt(value).toString(10)}`;
1393
- }
1479
+ numeric = BigInt(raw);
1394
1480
  } catch {
1481
+ return void 0;
1395
1482
  }
1396
- return void 0;
1483
+ if (numeric <= 0n || numeric > BigInt(Number.MAX_SAFE_INTEGER)) {
1484
+ return void 0;
1485
+ }
1486
+ return `eip155:${numeric.toString(10)}`;
1397
1487
  }
1398
1488
  function toEip155Accounts(accounts, chainId) {
1399
1489
  const reference = chainId.split(":")[1];
@@ -1497,6 +1587,7 @@ export {
1497
1587
  createDelegationPolicyFlow,
1498
1588
  createNotification,
1499
1589
  createNotificationSettingsStorage,
1590
+ createSolanaSessionKeyFlow,
1500
1591
  decodeRevertReason,
1501
1592
  defaultSiwxDomain,
1502
1593
  defaultSiwxUri,