@solana/connector 0.0.0 → 0.1.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.
Files changed (47) hide show
  1. package/README.md +1460 -0
  2. package/dist/chunk-52WUWW5R.mjs +2533 -0
  3. package/dist/chunk-52WUWW5R.mjs.map +1 -0
  4. package/dist/chunk-5NSUFMCB.js +393 -0
  5. package/dist/chunk-5NSUFMCB.js.map +1 -0
  6. package/dist/chunk-5ZUVZZWU.mjs +180 -0
  7. package/dist/chunk-5ZUVZZWU.mjs.map +1 -0
  8. package/dist/chunk-7TADXRFD.mjs +298 -0
  9. package/dist/chunk-7TADXRFD.mjs.map +1 -0
  10. package/dist/chunk-ACFSCMUI.mjs +359 -0
  11. package/dist/chunk-ACFSCMUI.mjs.map +1 -0
  12. package/dist/chunk-SGAIPK7Q.js +314 -0
  13. package/dist/chunk-SGAIPK7Q.js.map +1 -0
  14. package/dist/chunk-SMUUAKC3.js +186 -0
  15. package/dist/chunk-SMUUAKC3.js.map +1 -0
  16. package/dist/chunk-ZLPQUOFK.js +2594 -0
  17. package/dist/chunk-ZLPQUOFK.js.map +1 -0
  18. package/dist/compat.d.mts +106 -0
  19. package/dist/compat.d.ts +106 -0
  20. package/dist/compat.js +98 -0
  21. package/dist/compat.js.map +1 -0
  22. package/dist/compat.mjs +94 -0
  23. package/dist/compat.mjs.map +1 -0
  24. package/dist/headless.d.mts +400 -0
  25. package/dist/headless.d.ts +400 -0
  26. package/dist/headless.js +325 -0
  27. package/dist/headless.js.map +1 -0
  28. package/dist/headless.mjs +4 -0
  29. package/dist/headless.mjs.map +1 -0
  30. package/dist/index.d.mts +10 -0
  31. package/dist/index.d.ts +10 -0
  32. package/dist/index.js +382 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/index.mjs +5 -0
  35. package/dist/index.mjs.map +1 -0
  36. package/dist/react.d.mts +645 -0
  37. package/dist/react.d.ts +645 -0
  38. package/dist/react.js +65 -0
  39. package/dist/react.js.map +1 -0
  40. package/dist/react.mjs +4 -0
  41. package/dist/react.mjs.map +1 -0
  42. package/dist/transaction-signer-BtJPGXIg.d.mts +373 -0
  43. package/dist/transaction-signer-BtJPGXIg.d.ts +373 -0
  44. package/dist/wallet-standard-shim-Af7ejSld.d.mts +1090 -0
  45. package/dist/wallet-standard-shim-BGlvGRbB.d.ts +1090 -0
  46. package/package.json +87 -10
  47. package/index.js +0 -1
@@ -0,0 +1,373 @@
1
+ import { Wallet, WalletAccount } from '@wallet-standard/base';
2
+ import { SolanaClusterId, SolanaCluster } from '@wallet-ui/core';
3
+ import { Signature, Address, TransactionMessage } from 'gill';
4
+ import { Transaction, VersionedTransaction } from '@solana/web3.js';
5
+
6
+ /**
7
+ * Transaction and signer-related types
8
+ */
9
+
10
+ /**
11
+ * Union type for all supported Solana transaction formats
12
+ * Supports both legacy (@solana/web3.js) and modern (gill) transaction types
13
+ */
14
+ type SolanaTransaction = Transaction | VersionedTransaction | TransactionMessage | Uint8Array;
15
+ /**
16
+ * Transaction status during its lifecycle
17
+ */
18
+ type TransactionActivityStatus = 'pending' | 'confirmed' | 'failed';
19
+ /**
20
+ * Methods used to send/sign transactions
21
+ */
22
+ type TransactionMethod = 'signTransaction' | 'signAllTransactions' | 'signAndSendTransaction' | 'signAndSendTransactions' | 'sendTransaction' | 'sendRawTransaction';
23
+ /**
24
+ * Transaction metadata for additional context
25
+ */
26
+ interface TransactionMetadata {
27
+ /** Transaction size in bytes */
28
+ size?: number;
29
+ /** Compute units requested */
30
+ computeUnits?: number;
31
+ /** Priority fee in lamports */
32
+ priorityFee?: number;
33
+ /** Number of signatures required */
34
+ numSignatures?: number;
35
+ /** Whether preflight was skipped */
36
+ skipPreflight?: boolean;
37
+ /** Custom metadata fields */
38
+ [key: string]: unknown;
39
+ }
40
+ /**
41
+ * Configuration for creating a transaction signer
42
+ */
43
+ interface TransactionSignerConfig {
44
+ /** The Wallet Standard wallet instance */
45
+ wallet: Wallet;
46
+ /** The specific account to sign with */
47
+ account: WalletAccount;
48
+ /** Optional cluster/network context for chain-specific operations */
49
+ cluster?: SolanaCluster;
50
+ /** Optional event emitter for transaction lifecycle events */
51
+ eventEmitter?: {
52
+ emit: (event: unknown) => void;
53
+ };
54
+ }
55
+ /**
56
+ * Result of a signed transaction operation
57
+ */
58
+ interface SignedTransaction {
59
+ /** The transaction signature/hash */
60
+ signature: string;
61
+ /** The signed transaction data */
62
+ transaction: SolanaTransaction;
63
+ }
64
+ /**
65
+ * Capabilities that a transaction signer supports
66
+ * Useful for conditionally enabling/disabling UI features
67
+ */
68
+ interface TransactionSignerCapabilities {
69
+ /** Can sign transactions without sending */
70
+ canSign: boolean;
71
+ /** Can sign and send transactions in one operation */
72
+ canSend: boolean;
73
+ /** Can sign arbitrary messages */
74
+ canSignMessage: boolean;
75
+ /** Can sign multiple transactions at once */
76
+ supportsBatchSigning: boolean;
77
+ }
78
+ /**
79
+ * Transaction activity record for debugging and monitoring
80
+ */
81
+ interface TransactionActivity {
82
+ /** Transaction signature */
83
+ signature: Signature;
84
+ /** When the transaction was sent */
85
+ timestamp: string;
86
+ /** Transaction status */
87
+ status: TransactionActivityStatus;
88
+ /** Error message if failed */
89
+ error?: string;
90
+ /** Cluster where transaction was sent */
91
+ cluster: SolanaClusterId;
92
+ /** Fee payer address */
93
+ feePayer?: Address;
94
+ /** Method used (signAndSendTransaction, sendTransaction, etc) */
95
+ method: TransactionMethod;
96
+ /** Additional metadata */
97
+ metadata?: TransactionMetadata;
98
+ }
99
+
100
+ /**
101
+ * @solana/connector - Unified Error System
102
+ *
103
+ * Provides consistent, structured error handling across the entire library.
104
+ * All errors extend ConnectorError and include:
105
+ * - Error codes for programmatic handling
106
+ * - Optional context data
107
+ * - Original error preservation
108
+ * - Stack trace capture
109
+ */
110
+ /**
111
+ * Base error class for all Connector errors
112
+ * Provides common structure and metadata
113
+ */
114
+ declare abstract class ConnectorError extends Error {
115
+ /**
116
+ * Error code for programmatic handling
117
+ */
118
+ abstract readonly code: string;
119
+ /**
120
+ * Whether this error is recoverable (user can retry)
121
+ */
122
+ abstract readonly recoverable: boolean;
123
+ /**
124
+ * Additional context about the error
125
+ */
126
+ readonly context?: Record<string, unknown>;
127
+ /**
128
+ * The underlying error that caused this error
129
+ */
130
+ readonly originalError?: Error;
131
+ /**
132
+ * Timestamp when error occurred
133
+ */
134
+ readonly timestamp: string;
135
+ constructor(message: string, context?: Record<string, unknown>, originalError?: Error);
136
+ /**
137
+ * Get a JSON representation of the error
138
+ */
139
+ toJSON(): Record<string, unknown>;
140
+ }
141
+ /**
142
+ * Connection-related errors (wallet connection, disconnection)
143
+ */
144
+ declare class ConnectionError extends ConnectorError {
145
+ readonly code: ConnectionErrorCode;
146
+ readonly recoverable = true;
147
+ constructor(code: ConnectionErrorCode, message: string, context?: Record<string, unknown>, originalError?: Error);
148
+ }
149
+ type ConnectionErrorCode = 'WALLET_NOT_CONNECTED' | 'WALLET_NOT_FOUND' | 'CONNECTION_FAILED' | 'CONNECTION_REJECTED' | 'DISCONNECTION_FAILED' | 'ACCOUNT_NOT_AVAILABLE' | 'RECONNECTION_FAILED';
150
+ /**
151
+ * Validation errors (invalid data, unsupported formats)
152
+ */
153
+ declare class ValidationError extends ConnectorError {
154
+ readonly code: ValidationErrorCode;
155
+ readonly recoverable = false;
156
+ constructor(code: ValidationErrorCode, message: string, context?: Record<string, unknown>, originalError?: Error);
157
+ }
158
+ type ValidationErrorCode = 'INVALID_TRANSACTION' | 'INVALID_MESSAGE' | 'INVALID_ADDRESS' | 'INVALID_SIGNATURE' | 'INVALID_FORMAT' | 'UNSUPPORTED_FORMAT' | 'VALIDATION_FAILED';
159
+ /**
160
+ * Configuration errors (setup issues, missing required options)
161
+ */
162
+ declare class ConfigurationError extends ConnectorError {
163
+ readonly code: ConfigurationErrorCode;
164
+ readonly recoverable = false;
165
+ constructor(code: ConfigurationErrorCode, message: string, context?: Record<string, unknown>, originalError?: Error);
166
+ }
167
+ type ConfigurationErrorCode = 'MISSING_PROVIDER' | 'INVALID_CLUSTER' | 'CLUSTER_NOT_FOUND' | 'INVALID_CONFIG' | 'INITIALIZATION_FAILED';
168
+ /**
169
+ * Network errors (RPC failures, timeout)
170
+ */
171
+ declare class NetworkError extends ConnectorError {
172
+ readonly code: NetworkErrorCode;
173
+ readonly recoverable = true;
174
+ constructor(code: NetworkErrorCode, message: string, context?: Record<string, unknown>, originalError?: Error);
175
+ }
176
+ type NetworkErrorCode = 'RPC_ERROR' | 'NETWORK_TIMEOUT' | 'NETWORK_UNAVAILABLE' | 'TRANSACTION_SIMULATION_FAILED';
177
+ /**
178
+ * Transaction errors (signing, sending transactions)
179
+ * Extends the existing TransactionSignerError pattern
180
+ */
181
+ declare class TransactionError extends ConnectorError {
182
+ readonly code: TransactionErrorCode;
183
+ readonly recoverable: boolean;
184
+ constructor(code: TransactionErrorCode, message: string, context?: Record<string, unknown>, originalError?: Error);
185
+ }
186
+ type TransactionErrorCode = 'SIGNING_FAILED' | 'SEND_FAILED' | 'FEATURE_NOT_SUPPORTED' | 'USER_REJECTED' | 'SIMULATION_FAILED' | 'INVALID_TRANSACTION' | 'TRANSACTION_EXPIRED';
187
+ declare function isConnectorError(error: unknown): error is ConnectorError;
188
+ declare function isConnectionError(error: unknown): error is ConnectionError;
189
+ declare function isValidationError(error: unknown): error is ValidationError;
190
+ declare function isConfigurationError(error: unknown): error is ConfigurationError;
191
+ declare function isNetworkError(error: unknown): error is NetworkError;
192
+ declare function isTransactionError(error: unknown): error is TransactionError;
193
+ declare const Errors: {
194
+ readonly walletNotConnected: (context?: Record<string, unknown>) => ConnectionError;
195
+ readonly walletNotFound: (walletName?: string) => ConnectionError;
196
+ readonly connectionFailed: (originalError?: Error) => ConnectionError;
197
+ readonly accountNotAvailable: (address?: string) => ConnectionError;
198
+ readonly invalidTransaction: (reason: string, context?: Record<string, unknown>) => ValidationError;
199
+ readonly invalidFormat: (expectedFormat: string, actualFormat?: string) => ValidationError;
200
+ readonly unsupportedFormat: (format: string) => ValidationError;
201
+ readonly missingProvider: (hookName: string) => ConfigurationError;
202
+ readonly clusterNotFound: (clusterId: string, availableClusters: string[]) => ConfigurationError;
203
+ readonly rpcError: (message: string, originalError?: Error) => NetworkError;
204
+ readonly networkTimeout: () => NetworkError;
205
+ readonly signingFailed: (originalError?: Error) => TransactionError;
206
+ readonly featureNotSupported: (feature: string) => TransactionError;
207
+ readonly userRejected: (operation: string) => TransactionError;
208
+ };
209
+ /**
210
+ * Convert any error to a ConnectorError
211
+ * Useful for wrapping unknown errors in a structured format
212
+ */
213
+ declare function toConnectorError(error: unknown, defaultMessage?: string): ConnectorError;
214
+ /**
215
+ * Get user-friendly error message
216
+ * Converts technical errors into messages suitable for display
217
+ */
218
+ declare function getUserFriendlyMessage(error: unknown): string;
219
+
220
+ /**
221
+ * @solana/connector - Transaction Signing Abstraction Layer
222
+ *
223
+ * Provides a clean, unified interface for transaction operations that works
224
+ * across both Wallet Standard and legacy wallet implementations.
225
+ *
226
+ * Inspired by wallet-adapter-compat's transaction signer pattern, this
227
+ * abstraction layer makes it easy to integrate with transaction libraries
228
+ * and provides consistent error handling and capability detection.
229
+ */
230
+
231
+ /**
232
+ * Unified transaction signer interface
233
+ *
234
+ * This interface abstracts wallet-specific transaction signing methods
235
+ * into a consistent API that works across all Wallet Standard wallets.
236
+ *
237
+ * @example
238
+ * ```ts
239
+ * const signer = createTransactionSigner({
240
+ * wallet: connectedWallet,
241
+ * account: selectedAccount,
242
+ * cluster: currentCluster
243
+ * })
244
+ *
245
+ * // Check capabilities before using
246
+ * const caps = signer.getCapabilities()
247
+ * if (!caps.canSend) {
248
+ * console.warn('Wallet cannot send transactions directly')
249
+ * }
250
+ *
251
+ * // Sign and send a transaction
252
+ * const signature = await signer.signAndSendTransaction(transaction)
253
+ * console.log('Transaction sent:', signature)
254
+ * ```
255
+ */
256
+ interface TransactionSigner {
257
+ /** The wallet address that will sign transactions */
258
+ readonly address: string;
259
+ /**
260
+ * Sign a single transaction without sending it
261
+ * The wallet prompts the user to approve the transaction
262
+ *
263
+ * @param transaction - The transaction to sign
264
+ * @returns The signed transaction
265
+ * @throws {TransactionSignerError} If wallet doesn't support signing or user rejects
266
+ */
267
+ signTransaction(transaction: SolanaTransaction): Promise<SolanaTransaction>;
268
+ /**
269
+ * Sign multiple transactions at once
270
+ * More efficient than signing one-by-one for batch operations
271
+ * Falls back to sequential signing if batch not supported
272
+ *
273
+ * @param transactions - Array of transactions to sign
274
+ * @returns Array of signed transactions in the same order
275
+ * @throws {TransactionSignerError} If signing fails for any transaction
276
+ */
277
+ signAllTransactions(transactions: SolanaTransaction[]): Promise<SolanaTransaction[]>;
278
+ /**
279
+ * Sign and send a transaction in one operation
280
+ * The wallet handles both signing and broadcasting to the network
281
+ *
282
+ * @param transaction - The transaction to sign and send
283
+ * @param options - Optional send options (e.g., skipPreflight)
284
+ * @returns The transaction signature/hash
285
+ * @throws {TransactionSignerError} If sending fails or user rejects
286
+ */
287
+ signAndSendTransaction(transaction: SolanaTransaction, options?: {
288
+ skipPreflight?: boolean;
289
+ maxRetries?: number;
290
+ }): Promise<string>;
291
+ /**
292
+ * Sign and send multiple transactions sequentially
293
+ * Waits for each transaction to be sent before sending the next
294
+ *
295
+ * @param transactions - Array of transactions to sign and send
296
+ * @param options - Optional send options
297
+ * @returns Array of transaction signatures in the same order
298
+ * @throws {TransactionSignerError} If any transaction fails
299
+ */
300
+ signAndSendTransactions(transactions: SolanaTransaction[], options?: {
301
+ skipPreflight?: boolean;
302
+ maxRetries?: number;
303
+ }): Promise<string[]>;
304
+ /**
305
+ * Sign an arbitrary message (for authentication, verification, etc.)
306
+ * Optional: not all wallets support message signing
307
+ *
308
+ * @param message - The message to sign (as Uint8Array)
309
+ * @returns The signature bytes
310
+ * @throws {TransactionSignerError} If wallet doesn't support message signing
311
+ */
312
+ signMessage?(message: Uint8Array): Promise<Uint8Array>;
313
+ /**
314
+ * Get the signer's capabilities
315
+ * Use this to conditionally enable/disable features in your UI
316
+ *
317
+ * @returns Object describing what this signer can do
318
+ */
319
+ getCapabilities(): TransactionSignerCapabilities;
320
+ }
321
+ /**
322
+ * Create a transaction signer from a Wallet Standard wallet
323
+ *
324
+ * This factory function creates a TransactionSigner instance that bridges
325
+ * Wallet Standard features to a clean, consistent API.
326
+ *
327
+ * @param config - Configuration including wallet, account, and optional cluster
328
+ * @returns TransactionSigner instance, or null if wallet/account invalid
329
+ *
330
+ * @example
331
+ * ```ts
332
+ * // Basic usage
333
+ * const signer = createTransactionSigner({
334
+ * wallet: connectedWallet,
335
+ * account: selectedAccount
336
+ * })
337
+ *
338
+ * if (!signer) {
339
+ * console.error('Failed to create signer - wallet or account missing')
340
+ * return
341
+ * }
342
+ *
343
+ * // Use the signer
344
+ * try {
345
+ * const sig = await signer.signAndSendTransaction(tx)
346
+ * console.log('Success:', sig)
347
+ * } catch (error) {
348
+ * if (error instanceof TransactionSignerError) {
349
+ * console.error('Signing error:', error.code, error.message)
350
+ * }
351
+ * }
352
+ * ```
353
+ */
354
+ declare function createTransactionSigner(config: TransactionSignerConfig): TransactionSigner | null;
355
+ /**
356
+ * @deprecated Use TransactionError from '../errors' instead
357
+ * Kept for backward compatibility
358
+ *
359
+ * Custom error class for transaction signer operations
360
+ * Provides structured error information for better error handling
361
+ */
362
+ declare class TransactionSignerError extends TransactionError {
363
+ constructor(message: string, code: 'WALLET_NOT_CONNECTED' | 'FEATURE_NOT_SUPPORTED' | 'SIGNING_FAILED' | 'SEND_FAILED', originalError?: Error);
364
+ }
365
+ /**
366
+ * @deprecated Use isTransactionError from '../errors' instead
367
+ * Kept for backward compatibility
368
+ *
369
+ * Type guard to check if an error is a TransactionSignerError
370
+ */
371
+ declare function isTransactionSignerError(error: unknown): error is TransactionSignerError;
372
+
373
+ export { ConnectorError as C, Errors as E, NetworkError as N, type SolanaTransaction as S, type TransactionSignerConfig as T, ValidationError as V, type SignedTransaction as a, type TransactionSignerCapabilities as b, type TransactionActivity as c, type TransactionActivityStatus as d, type TransactionMethod as e, type TransactionMetadata as f, createTransactionSigner as g, TransactionSignerError as h, isTransactionSignerError as i, type TransactionSigner as j, ConnectionError as k, ConfigurationError as l, TransactionError as m, isConnectorError as n, isConnectionError as o, isValidationError as p, isConfigurationError as q, isNetworkError as r, isTransactionError as s, toConnectorError as t, getUserFriendlyMessage as u, type ConnectionErrorCode as v, type ValidationErrorCode as w, type ConfigurationErrorCode as x, type NetworkErrorCode as y, type TransactionErrorCode as z };