@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.
- package/README.md +1460 -0
- package/dist/chunk-52WUWW5R.mjs +2533 -0
- package/dist/chunk-52WUWW5R.mjs.map +1 -0
- package/dist/chunk-5NSUFMCB.js +393 -0
- package/dist/chunk-5NSUFMCB.js.map +1 -0
- package/dist/chunk-5ZUVZZWU.mjs +180 -0
- package/dist/chunk-5ZUVZZWU.mjs.map +1 -0
- package/dist/chunk-7TADXRFD.mjs +298 -0
- package/dist/chunk-7TADXRFD.mjs.map +1 -0
- package/dist/chunk-ACFSCMUI.mjs +359 -0
- package/dist/chunk-ACFSCMUI.mjs.map +1 -0
- package/dist/chunk-SGAIPK7Q.js +314 -0
- package/dist/chunk-SGAIPK7Q.js.map +1 -0
- package/dist/chunk-SMUUAKC3.js +186 -0
- package/dist/chunk-SMUUAKC3.js.map +1 -0
- package/dist/chunk-ZLPQUOFK.js +2594 -0
- package/dist/chunk-ZLPQUOFK.js.map +1 -0
- package/dist/compat.d.mts +106 -0
- package/dist/compat.d.ts +106 -0
- package/dist/compat.js +98 -0
- package/dist/compat.js.map +1 -0
- package/dist/compat.mjs +94 -0
- package/dist/compat.mjs.map +1 -0
- package/dist/headless.d.mts +400 -0
- package/dist/headless.d.ts +400 -0
- package/dist/headless.js +325 -0
- package/dist/headless.js.map +1 -0
- package/dist/headless.mjs +4 -0
- package/dist/headless.mjs.map +1 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +382 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +5 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react.d.mts +645 -0
- package/dist/react.d.ts +645 -0
- package/dist/react.js +65 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +4 -0
- package/dist/react.mjs.map +1 -0
- package/dist/transaction-signer-BtJPGXIg.d.mts +373 -0
- package/dist/transaction-signer-BtJPGXIg.d.ts +373 -0
- package/dist/wallet-standard-shim-Af7ejSld.d.mts +1090 -0
- package/dist/wallet-standard-shim-BGlvGRbB.d.ts +1090 -0
- package/package.json +87 -10
- package/index.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/utils/secure-logger.ts","../src/utils/transaction-format.ts"],"names":["gillDebug"],"mappings":";;;;;AAuCA,IAAM,cAAA,GAAiB;AAAA,EACnB,SAAA;AAAA,EACA,WAAA;AAAA,EACA,WAAA;AAAA,EACA,SAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA,QAAA;AAAA,EACA,SAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACA,MAAA;AAAA,EACA;AACJ,CAAA,CAAA,CAKM,UAAA,GAAuC;AAAA,EACzC,KAAA,EAAO,CAAA;AAAA,EACP,IAAA,EAAM,CAAA;AAAA,EACN,IAAA,EAAM,CAAA;AAAA,EACN,KAAA,EAAO;AACX,CAAA,CAAA,CA4Ba,eAAN,MAAmB;AAAA,EAGtB,WAAA,CAAY,MAAA,GAA6B,EAAC,EAAG;AAF7C,IAAA,aAAA,CAAA,IAAA,EAAQ,QAAA,CAAA;AAGJ,IAAA,IAAM,gBAAgB,OAAO,OAAA,GAAY,GAAA,IAAe,OAAA,CAAQ,KAAK,QAAA,KAAa,aAAA;AAElF,IAAA,IAAA,CAAK,MAAA,GAAS;AAAA,MACV,OAAA,EAAS,OAAO,OAAA,IAAW,aAAA;AAAA,MAC3B,KAAA,EAAO,OAAO,KAAA,IAAS,OAAA;AAAA,MACvB,eAAA,EAAiB,MAAA,CAAO,eAAA,IAAmB,CAAC,aAAA;AAAA,MAC5C,MAAA,EAAQ,OAAO,MAAA,IAAU,WAAA;AAAA,MACzB,YAAA,EAAc,OAAO,YAAA,IAAgB;AAAA;AAAA,KACzC;AAAA,EACJ;AAAA;AAAA;AAAA;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CAAA,EAAG;AAE5B,IAAA,IAAM,EAAE,WAAA,EAAY,GAAI,MAAM,OAAO,iBAAiB,CAAA;AACtD,IAAA,OAAO,WAAA,CAAY,KAAK,KAAK,CAAA;AAAA,EACjC,CAAA,MAAO;AAEH,IAAA,IAAM,EAAE,oBAAA,EAAqB,GAAI,MAAM,OAAO,iBAAiB,CAAA;AAC/D,IAAA,OAAO,oBAAA,CAAqB,YAAY,KAAK,CAAA;AAAA,EACjD;AACJ;AASO,SAAS,4BAA4B,EAAA,EAAuE;AAC/G,EAAA,IAAM,SAAA,GAAY,oBAAoB,EAAE,CAAA;AAExC,EAAA,OAAO,EAAE,UAAA,EADU,oBAAA,CAAqB,EAAE,GACrB,SAAA,EAAU;AACnC;AAUA,eAAsB,wBAAA,CAClB,aACA,SAAA,EACwD;AACxD,EAAA,OAAI,SAAA,GACO,MAAM,8BAAA,CAA+B,WAAW,CAAA,GAEpD,WAAA;AACX","file":"chunk-5ZUVZZWU.mjs","sourcesContent":["/**\n * @solana/connector - Secure Logger\n *\n * Production-safe logger that redacts sensitive information\n * Prevents accidental exposure of addresses, keys, and other PII in logs\n *\n * Integrates with gill's debug system:\n * - Respects `__GILL_DEBUG__` flag (enable/disable logging globally)\n * - Respects `__GILL_DEBUG_LEVEL__` (set minimum log level)\n * - Extends gill's debug with sensitive data redaction\n * - Provides unified logging API across connector and gill\n *\n * Enable gill debug:\n * ```ts\n * window.__GILL_DEBUG__ = true\n * window.__GILL_DEBUG_LEVEL__ = 'debug' // or 'info', 'warn', 'error'\n * ```\n */\n\nimport { isDebugEnabled, debug as gillDebug } from 'gill';\n\nexport type LogLevel = 'debug' | 'info' | 'warn' | 'error';\n\nexport interface SecureLoggerConfig {\n /** Enable logging (defaults to true in development, false in production) */\n enabled?: boolean;\n /** Minimum log level to output */\n level?: LogLevel;\n /** Redact sensitive information in logs (defaults to true in production) */\n redactSensitive?: boolean;\n /** Custom prefix for all log messages */\n prefix?: string;\n /** Use gill's debug system for logging (respects __GILL_DEBUG__ flags) */\n useGillDebug?: boolean;\n}\n\n/**\n * Keys that contain sensitive information that should be redacted\n */\nconst SENSITIVE_KEYS = [\n 'address',\n 'publickey',\n 'signature',\n 'account',\n 'rpcurl',\n 'url',\n 'apikey',\n 'api_key',\n 'token',\n 'secret',\n 'password',\n 'private',\n 'seed',\n 'mnemonic',\n];\n\n/**\n * Log levels in order of severity\n */\nconst LOG_LEVELS: Record<LogLevel, number> = {\n debug: 0,\n info: 1,\n warn: 2,\n error: 3,\n};\n\n/**\n * SecureLogger - Production-safe logging with automatic redaction\n *\n * Features:\n * - Integrates with gill's debug system (respects __GILL_DEBUG__ flags)\n * - Automatic redaction of sensitive data (addresses, keys, URLs)\n * - Configurable log levels (respects __GILL_DEBUG_LEVEL__)\n * - Environment-aware defaults\n * - Deep object traversal for nested sensitive data\n *\n * @example\n * ```ts\n * // Enable gill debug (affects all logging across connector + gill)\n * window.__GILL_DEBUG__ = true\n * window.__GILL_DEBUG_LEVEL__ = 'info' // Optional: filter by level\n *\n * const logger = new SecureLogger({ prefix: 'Connector' });\n *\n * logger.debug('User connected', {\n * address: '7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU', // Auto-redacted in prod\n * wallet: 'Phantom'\n * });\n * // Development: \"User connected { address: '7xKX...gAsU', wallet: 'Phantom' }\"\n * // Production: \"User connected { address: '***', wallet: 'Phantom' }\"\n * ```\n */\nexport class SecureLogger {\n private config: Required<SecureLoggerConfig>;\n\n constructor(config: SecureLoggerConfig = {}) {\n const isDevelopment = typeof process !== 'undefined' && process.env?.NODE_ENV === 'development';\n\n this.config = {\n enabled: config.enabled ?? isDevelopment,\n level: config.level ?? 'debug',\n redactSensitive: config.redactSensitive ?? !isDevelopment,\n prefix: config.prefix ?? 'Connector',\n useGillDebug: config.useGillDebug ?? true, // Default to using gill's debug system\n };\n }\n\n /**\n * Log debug information (lowest priority)\n */\n debug(message: string, data?: unknown): void {\n this.log('debug', message, data);\n }\n\n /**\n * Log general information\n */\n info(message: string, data?: unknown): void {\n this.log('info', message, data);\n }\n\n /**\n * Log warnings\n */\n warn(message: string, data?: unknown): void {\n this.log('warn', message, data);\n }\n\n /**\n * Log errors (highest priority)\n */\n error(message: string, data?: unknown): void {\n this.log('error', message, data);\n }\n\n /**\n * Internal log method that handles level filtering and redaction\n * Integrates with gill's debug system when enabled\n */\n private log(level: LogLevel, message: string, data?: unknown): void {\n // Check if logging is enabled (either via config or gill's debug system)\n const gillDebugEnabled = this.config.useGillDebug ? isDebugEnabled() : false;\n if (!this.config.enabled && !gillDebugEnabled) return;\n\n // Get effective log level (prefer gill's debug level if set)\n let effectiveLevel = this.config.level;\n if (this.config.useGillDebug && typeof globalThis !== 'undefined') {\n const gillLevel = (globalThis as { __GILL_DEBUG_LEVEL__?: string }).__GILL_DEBUG_LEVEL__;\n if (gillLevel && ['debug', 'info', 'warn', 'error'].includes(gillLevel)) {\n effectiveLevel = gillLevel as LogLevel;\n }\n }\n\n // Check if this log level should be output\n if (LOG_LEVELS[level] < LOG_LEVELS[effectiveLevel]) {\n return;\n }\n\n // Process data (redact if enabled)\n const processedData = this.config.redactSensitive ? this.redact(data) : data;\n\n // Format message with data\n const fullMessage =\n processedData !== undefined\n ? `${message} ${typeof processedData === 'object' ? JSON.stringify(processedData, null, 2) : processedData}`\n : message;\n\n // Use gill's debug system if enabled, otherwise fall back to console.*\n if (this.config.useGillDebug && gillDebugEnabled) {\n gillDebug(fullMessage, level as any, this.config.prefix);\n } else {\n const prefix = `[${this.config.prefix}]`;\n switch (level) {\n case 'debug':\n console.debug(prefix, message, processedData !== undefined ? processedData : '');\n break;\n case 'info':\n console.info(prefix, message, processedData !== undefined ? processedData : '');\n break;\n case 'warn':\n console.warn(prefix, message, processedData !== undefined ? processedData : '');\n break;\n case 'error':\n console.error(prefix, message, processedData !== undefined ? processedData : '');\n break;\n }\n }\n }\n\n /**\n * Recursively redact sensitive information from data\n */\n private redact(data: unknown): unknown {\n if (data === null || data === undefined) {\n return data;\n }\n\n // Handle primitives\n if (typeof data !== 'object') {\n return data;\n }\n\n // Handle arrays\n if (Array.isArray(data)) {\n return data.map(item => this.redact(item));\n }\n\n // Handle objects\n const redacted: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(data)) {\n const keyLower = key.toLowerCase();\n\n // Check if this key contains sensitive information\n const isSensitive = SENSITIVE_KEYS.some(sensitiveKey => keyLower.includes(sensitiveKey));\n\n if (isSensitive) {\n redacted[key] = this.maskValue(value);\n } else if (typeof value === 'object' && value !== null) {\n redacted[key] = this.redact(value);\n } else {\n redacted[key] = value;\n }\n }\n\n return redacted;\n }\n\n /**\n * Mask a sensitive value for logging\n * Shows first 4 and last 4 characters for strings longer than 8 chars\n */\n private maskValue(value: unknown): string {\n if (value === null || value === undefined) {\n return '***';\n }\n\n const str = String(value);\n\n // For very short strings, just mask completely\n if (str.length <= 8) {\n return '***';\n }\n\n // For longer strings, show first and last 4 characters\n return `${str.slice(0, 4)}...${str.slice(-4)}`;\n }\n\n /**\n * Update logger configuration at runtime\n */\n updateConfig(config: Partial<SecureLoggerConfig>): void {\n this.config = { ...this.config, ...config };\n }\n\n /**\n * Get current configuration\n */\n getConfig(): Required<SecureLoggerConfig> {\n return { ...this.config };\n }\n}\n\n/**\n * Default logger instance for the connector\n * Automatically configured based on NODE_ENV\n */\nexport const logger = new SecureLogger({\n prefix: 'Connector',\n});\n\n/**\n * Create a logger with a custom prefix\n *\n * @example\n * ```ts\n * const walletLogger = createLogger('WalletDetector');\n * walletLogger.debug('Scanning for wallets...');\n * // Output: [WalletDetector] Scanning for wallets...\n * ```\n */\nexport function createLogger(prefix: string, config?: Omit<SecureLoggerConfig, 'prefix'>): SecureLogger {\n return new SecureLogger({ ...config, prefix });\n}\n","/**\n * Transaction Format Utilities\n *\n * Utilities for detecting and converting between different transaction formats:\n * - web3.js Transaction/VersionedTransaction objects\n * - Serialized Uint8Array (Wallet Standard format)\n * - Other TypedArray formats\n *\n * Note: Uses dynamic imports for @solana/web3.js to avoid bundling it\n * since it's only needed for the compat layer.\n */\n\nimport type { Transaction, VersionedTransaction } from '@solana/web3.js';\nimport type { SolanaTransaction } from '../types/transactions';\n\n/**\n * Check if a value is a web3.js Transaction or VersionedTransaction object\n *\n * @param tx - Value to check\n * @returns True if it's a web3.js transaction object\n */\nexport function isWeb3jsTransaction(tx: unknown): tx is Transaction | VersionedTransaction {\n // Duck-typing: if it has a serialize method, it's likely a web3.js transaction\n return tx !== null && typeof tx === 'object' && 'serialize' in tx && typeof tx.serialize === 'function';\n}\n\n/**\n * Serialize a transaction to Uint8Array format (required for Wallet Standard)\n *\n * @param tx - Transaction to serialize (web3.js object, Uint8Array, or TypedArray)\n * @returns Serialized transaction bytes\n * @throws Error if transaction format is unsupported\n */\nexport function serializeTransaction(tx: SolanaTransaction): Uint8Array {\n // web3.js Transaction/VersionedTransaction object\n if (isWeb3jsTransaction(tx)) {\n return tx.serialize({\n requireAllSignatures: false,\n verifySignatures: false,\n });\n }\n\n // Already serialized as Uint8Array\n if (tx instanceof Uint8Array) {\n return tx;\n }\n\n // Other TypedArray format\n if (ArrayBuffer.isView(tx)) {\n return new Uint8Array(tx.buffer, tx.byteOffset, tx.byteLength);\n }\n\n throw new Error('Unsupported transaction format - must be Transaction, VersionedTransaction, or Uint8Array');\n}\n\n/**\n * Check if transaction bytes represent a legacy transaction\n * Legacy transactions have high bit = 0, versioned have high bit = 1\n *\n * @param bytes - Serialized transaction bytes\n * @returns True if legacy transaction\n */\nfunction isLegacyTransaction(bytes: Uint8Array): boolean {\n if (bytes.length === 0) return false;\n // High bit of first byte: 0 = legacy, 1 = versioned\n return (bytes[0] & 0x80) === 0;\n}\n\n/**\n * Deserialize bytes to a web3.js Transaction or VersionedTransaction object\n * Uses dynamic import to avoid bundling @solana/web3.js\n * Automatically detects legacy vs versioned format\n *\n * @param bytes - Serialized transaction bytes\n * @returns Transaction or VersionedTransaction object\n */\nexport async function deserializeToWeb3jsTransaction(bytes: Uint8Array): Promise<Transaction | VersionedTransaction> {\n if (isLegacyTransaction(bytes)) {\n // Legacy transaction - use Transaction.deserialize to preserve legacy-only fields\n const { Transaction } = await import('@solana/web3.js');\n return Transaction.from(bytes);\n } else {\n // Versioned transaction\n const { VersionedTransaction } = await import('@solana/web3.js');\n return VersionedTransaction.deserialize(bytes);\n }\n}\n\n/**\n * Smart converter that preserves the original format\n * Converts to Wallet Standard format (Uint8Array) and tracks original type\n *\n * @param tx - Transaction in any supported format\n * @returns Object with serialized bytes and format flag\n */\nexport function prepareTransactionForWallet(tx: SolanaTransaction): { serialized: Uint8Array; wasWeb3js: boolean } {\n const wasWeb3js = isWeb3jsTransaction(tx);\n const serialized = serializeTransaction(tx);\n return { serialized, wasWeb3js };\n}\n\n/**\n * Convert signed transaction bytes back to original format if needed\n *\n * @param signedBytes - Signed transaction as Uint8Array\n * @param wasWeb3js - Whether the original was a web3.js object\n * @returns Transaction in appropriate format (async if conversion needed)\n * Returns Transaction for legacy, VersionedTransaction for versioned, or Uint8Array if not web3js\n */\nexport async function convertSignedTransaction(\n signedBytes: Uint8Array,\n wasWeb3js: boolean,\n): Promise<Transaction | VersionedTransaction | Uint8Array> {\n if (wasWeb3js) {\n return await deserializeToWeb3jsTransaction(signedBytes);\n }\n return signedBytes;\n}\n"]}
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { installPolyfills, ConnectorErrorBoundary, isMainnetCluster, isDevnetCluster, isTestnetCluster, isLocalCluster, getClusterExplorerUrl, getClusterType, formatAddress, copyAddressToClipboard, createTransactionSigner, createGillTransactionSigner, NetworkError, ConnectorClient } from './chunk-52WUWW5R.mjs';
|
|
2
|
+
import { createLogger } from './chunk-5ZUVZZWU.mjs';
|
|
3
|
+
import React, { createContext, useContext, useSyncExternalStore, useMemo, useState, useCallback, useRef } from 'react';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
import { createSolanaClient, prepareTransaction } from 'gill';
|
|
6
|
+
|
|
7
|
+
var logger = createLogger("ConnectorProvider");
|
|
8
|
+
installPolyfills();
|
|
9
|
+
var ConnectorContext = createContext(null);
|
|
10
|
+
ConnectorContext.displayName = "ConnectorContext";
|
|
11
|
+
function ConnectorProviderInternal({
|
|
12
|
+
children,
|
|
13
|
+
config,
|
|
14
|
+
mobile
|
|
15
|
+
}) {
|
|
16
|
+
let clientRef = useRef(null), client = React.useCallback(() => {
|
|
17
|
+
if (!clientRef.current)
|
|
18
|
+
try {
|
|
19
|
+
clientRef.current = new ConnectorClient(config), typeof window < "u" && (window.__connectorClient = clientRef.current), config?.debug && logger.info("Client initialized successfully");
|
|
20
|
+
} catch (error) {
|
|
21
|
+
let err = error;
|
|
22
|
+
logger.error("Failed to initialize client", { error: err });
|
|
23
|
+
let extendedConfig = config;
|
|
24
|
+
return extendedConfig?.errorBoundary?.onError && extendedConfig.errorBoundary.onError(err, {
|
|
25
|
+
componentStack: "client-initialization",
|
|
26
|
+
digest: `constructor-${(/* @__PURE__ */ new Date()).toISOString()}`
|
|
27
|
+
}), null;
|
|
28
|
+
}
|
|
29
|
+
return clientRef.current;
|
|
30
|
+
}, [config])();
|
|
31
|
+
return React.useEffect(() => {
|
|
32
|
+
let currentClient = clientRef.current;
|
|
33
|
+
if (currentClient) {
|
|
34
|
+
let privateClient = currentClient;
|
|
35
|
+
privateClient.initialize && typeof privateClient.initialize == "function" && privateClient.initialize();
|
|
36
|
+
}
|
|
37
|
+
return () => {
|
|
38
|
+
typeof window < "u" && (window.__connectorClient = void 0), currentClient && typeof currentClient.destroy == "function" && currentClient.destroy();
|
|
39
|
+
};
|
|
40
|
+
}, []), React.useEffect(() => {
|
|
41
|
+
if (!mobile) return;
|
|
42
|
+
let cancelled = false;
|
|
43
|
+
return (async () => {
|
|
44
|
+
try {
|
|
45
|
+
let mod = await import('@solana-mobile/wallet-standard-mobile');
|
|
46
|
+
if (cancelled) return;
|
|
47
|
+
let {
|
|
48
|
+
registerMwa,
|
|
49
|
+
createDefaultAuthorizationCache,
|
|
50
|
+
createDefaultChainSelector,
|
|
51
|
+
createDefaultWalletNotFoundHandler
|
|
52
|
+
} = mod, defaultChains = [
|
|
53
|
+
"solana:mainnet",
|
|
54
|
+
"solana:devnet",
|
|
55
|
+
"solana:testnet"
|
|
56
|
+
];
|
|
57
|
+
registerMwa({
|
|
58
|
+
appIdentity: mobile.appIdentity,
|
|
59
|
+
authorizationCache: mobile.authorizationCache ?? createDefaultAuthorizationCache(),
|
|
60
|
+
chains: mobile.chains ?? defaultChains,
|
|
61
|
+
chainSelector: mobile.chainSelector ?? createDefaultChainSelector(),
|
|
62
|
+
remoteHostAuthority: mobile.remoteHostAuthority,
|
|
63
|
+
onWalletNotFound: mobile.onWalletNotFound ?? createDefaultWalletNotFoundHandler()
|
|
64
|
+
});
|
|
65
|
+
} catch {
|
|
66
|
+
}
|
|
67
|
+
})(), () => {
|
|
68
|
+
cancelled = true;
|
|
69
|
+
};
|
|
70
|
+
}, [mobile]), /* @__PURE__ */ jsx(ConnectorContext.Provider, { value: client, children });
|
|
71
|
+
}
|
|
72
|
+
function ConnectorProvider({
|
|
73
|
+
children,
|
|
74
|
+
config,
|
|
75
|
+
mobile
|
|
76
|
+
}) {
|
|
77
|
+
let errorBoundaryConfig = config?.errorBoundary;
|
|
78
|
+
return errorBoundaryConfig?.enabled ? /* @__PURE__ */ jsx(
|
|
79
|
+
ConnectorErrorBoundary,
|
|
80
|
+
{
|
|
81
|
+
maxRetries: errorBoundaryConfig.maxRetries ?? 3,
|
|
82
|
+
onError: errorBoundaryConfig.onError,
|
|
83
|
+
fallback: errorBoundaryConfig.fallback,
|
|
84
|
+
children: /* @__PURE__ */ jsx(ConnectorProviderInternal, { config, mobile, children })
|
|
85
|
+
}
|
|
86
|
+
) : /* @__PURE__ */ jsx(ConnectorProviderInternal, { config, mobile, children });
|
|
87
|
+
}
|
|
88
|
+
function useConnector() {
|
|
89
|
+
let client = useContext(ConnectorContext);
|
|
90
|
+
if (!client)
|
|
91
|
+
throw new Error(
|
|
92
|
+
"useConnector must be used within ConnectorProvider. Wrap your app with <ConnectorProvider> or <UnifiedProvider> to use connector hooks."
|
|
93
|
+
);
|
|
94
|
+
let state = useSyncExternalStore(
|
|
95
|
+
React.useCallback((cb) => client.subscribe(cb), [client]),
|
|
96
|
+
React.useCallback(() => client.getSnapshot(), [client]),
|
|
97
|
+
React.useCallback(() => client.getSnapshot(), [client])
|
|
98
|
+
), methods = useMemo(
|
|
99
|
+
() => ({
|
|
100
|
+
select: client.select.bind(client),
|
|
101
|
+
disconnect: client.disconnect.bind(client),
|
|
102
|
+
selectAccount: client.selectAccount.bind(client)
|
|
103
|
+
}),
|
|
104
|
+
[client]
|
|
105
|
+
);
|
|
106
|
+
return useMemo(
|
|
107
|
+
() => ({
|
|
108
|
+
...state,
|
|
109
|
+
...methods
|
|
110
|
+
}),
|
|
111
|
+
[state, methods]
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
function useConnectorClient() {
|
|
115
|
+
return useContext(ConnectorContext);
|
|
116
|
+
}
|
|
117
|
+
function UnifiedProvider({ children, config, connectorConfig, mobile, providers = [] }) {
|
|
118
|
+
let actualConnectorConfig = config?.connectorConfig ?? connectorConfig, actualMobile = config?.mobile ?? mobile, content = /* @__PURE__ */ jsx(ConnectorProvider, { config: actualConnectorConfig, mobile: actualMobile, children });
|
|
119
|
+
for (let i = providers.length - 1; i >= 0; i--) {
|
|
120
|
+
let { component: Provider, props = {} } = providers[i];
|
|
121
|
+
content = /* @__PURE__ */ jsx(Provider, { ...props, children: content });
|
|
122
|
+
}
|
|
123
|
+
return content;
|
|
124
|
+
}
|
|
125
|
+
function useCluster() {
|
|
126
|
+
let { cluster, clusters } = useConnector(), client = useConnectorClient();
|
|
127
|
+
if (!client)
|
|
128
|
+
throw new Error("useCluster must be used within ConnectorProvider");
|
|
129
|
+
let setCluster = useMemo(
|
|
130
|
+
() => async (id) => {
|
|
131
|
+
await client.setCluster(id);
|
|
132
|
+
},
|
|
133
|
+
[client]
|
|
134
|
+
);
|
|
135
|
+
return useMemo(() => {
|
|
136
|
+
let isMainnet = cluster ? isMainnetCluster(cluster) : false, isDevnet = cluster ? isDevnetCluster(cluster) : false, isTestnet = cluster ? isTestnetCluster(cluster) : false, isLocal = cluster ? isLocalCluster(cluster) : false, explorerUrl = cluster ? getClusterExplorerUrl(cluster) : "", type = cluster ? getClusterType(cluster) : null;
|
|
137
|
+
return {
|
|
138
|
+
cluster,
|
|
139
|
+
clusters,
|
|
140
|
+
setCluster,
|
|
141
|
+
isMainnet,
|
|
142
|
+
isDevnet,
|
|
143
|
+
isTestnet,
|
|
144
|
+
isLocal,
|
|
145
|
+
explorerUrl,
|
|
146
|
+
type
|
|
147
|
+
};
|
|
148
|
+
}, [cluster, clusters, setCluster]);
|
|
149
|
+
}
|
|
150
|
+
function useAccount() {
|
|
151
|
+
let { selectedAccount, accounts, connected, selectAccount } = useConnector(), [copied, setCopied] = useState(false), copyTimeoutRef = React.useRef(void 0), account = useMemo(
|
|
152
|
+
() => accounts.find((a) => a.address === selectedAccount) ?? null,
|
|
153
|
+
[accounts, selectedAccount]
|
|
154
|
+
), formatted = useMemo(() => selectedAccount ? formatAddress(selectedAccount) : "", [selectedAccount]), copy = useCallback(async () => selectedAccount ? (copyTimeoutRef.current && clearTimeout(copyTimeoutRef.current), await copyAddressToClipboard(selectedAccount, {
|
|
155
|
+
onSuccess: () => {
|
|
156
|
+
setCopied(true), copyTimeoutRef.current = setTimeout(() => setCopied(false), 2e3);
|
|
157
|
+
}
|
|
158
|
+
})) : {
|
|
159
|
+
success: false,
|
|
160
|
+
error: "empty_value" /* EMPTY_VALUE */,
|
|
161
|
+
errorMessage: "No account selected"
|
|
162
|
+
}, [selectedAccount]);
|
|
163
|
+
return React.useEffect(() => () => {
|
|
164
|
+
copyTimeoutRef.current && clearTimeout(copyTimeoutRef.current);
|
|
165
|
+
}, []), useMemo(
|
|
166
|
+
() => ({
|
|
167
|
+
address: selectedAccount,
|
|
168
|
+
account,
|
|
169
|
+
connected,
|
|
170
|
+
formatted,
|
|
171
|
+
copy,
|
|
172
|
+
copied,
|
|
173
|
+
accounts,
|
|
174
|
+
selectAccount
|
|
175
|
+
}),
|
|
176
|
+
[selectedAccount, account, connected, formatted, copy, copied, accounts, selectAccount]
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
function useWalletInfo() {
|
|
180
|
+
let { selectedWallet, wallets, connected, connecting } = useConnector(), mappedWallets = useMemo(
|
|
181
|
+
() => wallets.map(
|
|
182
|
+
(walletInfo) => ({
|
|
183
|
+
name: walletInfo.wallet.name,
|
|
184
|
+
icon: walletInfo.wallet.icon,
|
|
185
|
+
installed: walletInfo.installed,
|
|
186
|
+
connectable: walletInfo.connectable
|
|
187
|
+
})
|
|
188
|
+
),
|
|
189
|
+
[wallets]
|
|
190
|
+
), selectedWalletInfo = useMemo(() => {
|
|
191
|
+
if (!selectedWallet)
|
|
192
|
+
return {
|
|
193
|
+
name: null,
|
|
194
|
+
icon: null,
|
|
195
|
+
installed: false,
|
|
196
|
+
connectable: false
|
|
197
|
+
};
|
|
198
|
+
let walletInfo = wallets.find((w) => w.wallet.name === selectedWallet.name);
|
|
199
|
+
return {
|
|
200
|
+
name: selectedWallet.name,
|
|
201
|
+
icon: selectedWallet.icon ?? null,
|
|
202
|
+
installed: walletInfo?.installed ?? false,
|
|
203
|
+
connectable: walletInfo?.connectable ?? false
|
|
204
|
+
};
|
|
205
|
+
}, [selectedWallet, wallets]);
|
|
206
|
+
return useMemo(
|
|
207
|
+
() => ({
|
|
208
|
+
...selectedWalletInfo,
|
|
209
|
+
connected,
|
|
210
|
+
connecting,
|
|
211
|
+
wallets: mappedWallets
|
|
212
|
+
}),
|
|
213
|
+
[selectedWalletInfo, connected, connecting, mappedWallets]
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
function useTransactionSigner() {
|
|
217
|
+
let { selectedWallet, selectedAccount, accounts, cluster, connected } = useConnector(), client = useConnectorClient(), account = useMemo(
|
|
218
|
+
() => accounts.find((a) => a.address === selectedAccount)?.raw ?? null,
|
|
219
|
+
[accounts, selectedAccount]
|
|
220
|
+
), signer = useMemo(() => !connected || !selectedWallet || !account ? null : createTransactionSigner({
|
|
221
|
+
wallet: selectedWallet,
|
|
222
|
+
account,
|
|
223
|
+
cluster: cluster ?? void 0,
|
|
224
|
+
eventEmitter: client ? {
|
|
225
|
+
emit: (event) => {
|
|
226
|
+
client.emitEvent(event);
|
|
227
|
+
}
|
|
228
|
+
} : void 0
|
|
229
|
+
}), [connected, selectedWallet, account, cluster, client]), capabilities = useMemo(
|
|
230
|
+
() => signer?.getCapabilities() ?? {
|
|
231
|
+
canSign: false,
|
|
232
|
+
canSend: false,
|
|
233
|
+
canSignMessage: false,
|
|
234
|
+
supportsBatchSigning: false
|
|
235
|
+
},
|
|
236
|
+
[signer]
|
|
237
|
+
);
|
|
238
|
+
return {
|
|
239
|
+
signer,
|
|
240
|
+
ready: !!signer,
|
|
241
|
+
address: selectedAccount,
|
|
242
|
+
capabilities
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
function useGillTransactionSigner() {
|
|
246
|
+
let { signer: connectorSigner, ready } = useTransactionSigner();
|
|
247
|
+
return {
|
|
248
|
+
signer: useMemo(() => connectorSigner ? createGillTransactionSigner(connectorSigner) : null, [connectorSigner]),
|
|
249
|
+
ready
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
var logger2 = createLogger("useGillSolanaClient");
|
|
253
|
+
function useGillSolanaClient() {
|
|
254
|
+
let { type } = useCluster(), connectorClient = useConnectorClient(), client = useMemo(() => {
|
|
255
|
+
if (!type || !connectorClient) return null;
|
|
256
|
+
try {
|
|
257
|
+
if (type !== "custom")
|
|
258
|
+
return createSolanaClient({
|
|
259
|
+
urlOrMoniker: type
|
|
260
|
+
});
|
|
261
|
+
let rpcUrl = connectorClient.getRpcUrl();
|
|
262
|
+
return rpcUrl ? createSolanaClient({
|
|
263
|
+
urlOrMoniker: rpcUrl
|
|
264
|
+
}) : null;
|
|
265
|
+
} catch (error) {
|
|
266
|
+
return logger2.error("Failed to create Gill Solana client", { error }), null;
|
|
267
|
+
}
|
|
268
|
+
}, [type, connectorClient]);
|
|
269
|
+
return {
|
|
270
|
+
client,
|
|
271
|
+
ready: !!client,
|
|
272
|
+
clusterType: type
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
function useTransactionPreparer() {
|
|
276
|
+
let { client, ready } = useGillSolanaClient();
|
|
277
|
+
return {
|
|
278
|
+
prepare: useCallback(
|
|
279
|
+
async (transaction, options = {}) => {
|
|
280
|
+
if (!client)
|
|
281
|
+
throw new NetworkError("RPC_ERROR", "Solana client not available. Cannot prepare transaction.");
|
|
282
|
+
return prepareTransaction({
|
|
283
|
+
transaction,
|
|
284
|
+
rpc: client.rpc,
|
|
285
|
+
computeUnitLimitMultiplier: options.computeUnitLimitMultiplier,
|
|
286
|
+
computeUnitLimitReset: options.computeUnitLimitReset,
|
|
287
|
+
blockhashReset: options.blockhashReset
|
|
288
|
+
});
|
|
289
|
+
},
|
|
290
|
+
[client]
|
|
291
|
+
),
|
|
292
|
+
ready
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export { ConnectorProvider, UnifiedProvider, useAccount, useCluster, useConnector, useConnectorClient, useGillSolanaClient, useGillTransactionSigner, useTransactionPreparer, useTransactionSigner, useWalletInfo };
|
|
297
|
+
//# sourceMappingURL=chunk-7TADXRFD.mjs.map
|
|
298
|
+
//# sourceMappingURL=chunk-7TADXRFD.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ui/connector-provider.tsx","../src/ui/unified-provider.tsx","../src/hooks/use-cluster.ts","../src/hooks/use-account.ts","../src/hooks/use-wallet-info.ts","../src/hooks/use-transaction-signer.ts","../src/hooks/use-gill-transaction-signer.ts","../src/hooks/use-gill-solana-client.ts","../src/hooks/use-transaction-preparer.ts"],"names":["jsx","useMemo","React","logger","useCallback"],"mappings":";;;;;;AAWA,IAAM,M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,0DAA0D,CAAA;AAGlG,QAAA,OAAO,kBAAA,CAAmB;AAAA,UACtB,WAAA;AAAA,UACA,KAAK,MAAA,CAAO,GAAA;AAAA,UACZ,4BAA4B,OAAA,CAAQ,0BAAA;AAAA,UACpC,uBAAuB,OAAA,CAAQ,qBAAA;AAAA,UAC/B,gBAAgB,OAAA,CAAQ;AAAA,SAC3B,CAAA;AAAA,MACL,CAAA;AAAA,MACA,CAAC,MAAM;AAAA,KACX;AAAA,IAII;AAAA,GACJ;AACJ","file":"chunk-7TADXRFD.mjs","sourcesContent":["'use client';\n\nimport React, { createContext, useContext, useMemo, useRef, useSyncExternalStore } from 'react';\nimport type { ReactNode } from 'react';\nimport { ConnectorClient } from '../lib/core/connector-client';\nimport type { ConnectorConfig } from '../types/connector';\nimport type { ExtendedConnectorConfig } from '../config/default-config';\nimport { ConnectorErrorBoundary } from './error-boundary';\nimport { installPolyfills } from '../lib/utils/polyfills';\nimport { createLogger } from '../lib/utils/secure-logger';\n\nconst logger = createLogger('ConnectorProvider');\n\n// Install browser compatibility polyfills immediately when module loads\n// This ensures crypto operations work across all browser environments\ninstallPolyfills();\n\n// Global connector client declaration for auto-detection\ndeclare global {\n interface Window {\n __connectorClient?: ConnectorClient;\n }\n}\n\nexport type ConnectorSnapshot = ReturnType<ConnectorClient['getSnapshot']> & {\n select: (walletName: string) => Promise<void>;\n disconnect: () => Promise<void>;\n selectAccount: (address: string) => Promise<void>;\n};\n\nexport const ConnectorContext = createContext<ConnectorClient | null>(null);\nConnectorContext.displayName = 'ConnectorContext';\n\nexport interface MobileWalletAdapterConfig {\n appIdentity: {\n name: string;\n uri?: string;\n icon?: string;\n };\n remoteHostAuthority?: string;\n chains?: readonly string[];\n authorizationCache?: unknown;\n chainSelector?: unknown;\n onWalletNotFound?: (wallet: unknown) => Promise<void>;\n}\n\n// Internal provider without error boundary\nfunction ConnectorProviderInternal({\n children,\n config,\n mobile,\n}: {\n children: ReactNode;\n config?: ConnectorConfig;\n mobile?: MobileWalletAdapterConfig;\n}) {\n const clientRef = useRef<ConnectorClient | null>(null);\n\n // Lazy initialization - only create client once on first render\n // This prevents double-initialization in React 19 strict mode\n const getClient = React.useCallback(() => {\n if (!clientRef.current) {\n try {\n clientRef.current = new ConnectorClient(config);\n\n // ✅ Set window.__connectorClient IMMEDIATELY for auto-detection\n if (typeof window !== 'undefined') {\n window.__connectorClient = clientRef.current;\n }\n\n // Log successful initialization in debug mode\n if (config?.debug) {\n logger.info('Client initialized successfully');\n }\n } catch (error) {\n const err = error as Error;\n logger.error('Failed to initialize client', { error: err });\n\n // Call config error handler if provided\n const extendedConfig = config as ExtendedConnectorConfig;\n if (extendedConfig?.errorBoundary?.onError) {\n extendedConfig.errorBoundary.onError(err, {\n componentStack: 'client-initialization',\n digest: `constructor-${new Date().toISOString()}`,\n });\n }\n\n // Return null to allow graceful degradation\n // Components can check for null client and show fallback UI\n return null;\n }\n }\n return clientRef.current;\n }, [config]);\n\n // Get client reference (memoized)\n const client = getClient();\n\n // On client mount, ensure wallet detection runs (run only once)\n React.useEffect(() => {\n const currentClient = clientRef.current;\n\n if (currentClient) {\n // Force re-initialization if client was created during SSR\n // This ensures wallets are detected even if client was created before window existed\n const privateClient = currentClient as unknown as { initialize?: () => void };\n if (privateClient.initialize && typeof privateClient.initialize === 'function') {\n privateClient.initialize();\n }\n }\n\n return () => {\n // Cleanup global reference and client on unmount\n if (typeof window !== 'undefined') {\n window.__connectorClient = undefined;\n }\n if (currentClient && typeof currentClient.destroy === 'function') {\n currentClient.destroy();\n }\n };\n }, []); // Empty dependency array - run only once\n\n // Optionally register Mobile Wallet Adapter on the client\n React.useEffect(() => {\n if (!mobile) return;\n let cancelled = false;\n (async () => {\n try {\n const mod = (await import(\n '@solana-mobile/wallet-standard-mobile'\n )) as typeof import('@solana-mobile/wallet-standard-mobile');\n if (cancelled) return;\n const {\n registerMwa,\n createDefaultAuthorizationCache,\n createDefaultChainSelector,\n createDefaultWalletNotFoundHandler,\n } = mod;\n const defaultChains: readonly `${string}:${string}`[] = [\n 'solana:mainnet',\n 'solana:devnet',\n 'solana:testnet',\n ];\n registerMwa({\n appIdentity: mobile.appIdentity,\n authorizationCache: mobile.authorizationCache ?? (createDefaultAuthorizationCache() as any),\n chains: (mobile.chains ?? defaultChains) as `${string}:${string}`[],\n chainSelector: mobile.chainSelector ?? (createDefaultChainSelector() as any),\n remoteHostAuthority: mobile.remoteHostAuthority,\n onWalletNotFound: mobile.onWalletNotFound ?? createDefaultWalletNotFoundHandler(),\n });\n } catch (e) {\n // Failed to register Mobile Wallet Adapter\n }\n })();\n return () => {\n cancelled = true;\n };\n }, [mobile]);\n\n return <ConnectorContext.Provider value={client}>{children}</ConnectorContext.Provider>;\n}\n\n// Enhanced provider with optional error boundary\nexport function ConnectorProvider({\n children,\n config,\n mobile,\n}: {\n children: ReactNode;\n config?: ExtendedConnectorConfig;\n mobile?: MobileWalletAdapterConfig;\n}) {\n const extendedConfig = config as ExtendedConnectorConfig;\n const errorBoundaryConfig = extendedConfig?.errorBoundary;\n\n // If error boundary is disabled, use internal provider directly\n if (!errorBoundaryConfig?.enabled) {\n return (\n <ConnectorProviderInternal config={config} mobile={mobile}>\n {children}\n </ConnectorProviderInternal>\n );\n }\n\n // Wrap with error boundary for enhanced error handling\n return (\n <ConnectorErrorBoundary\n maxRetries={errorBoundaryConfig.maxRetries ?? 3}\n onError={errorBoundaryConfig.onError}\n fallback={errorBoundaryConfig.fallback}\n >\n <ConnectorProviderInternal config={config} mobile={mobile}>\n {children}\n </ConnectorProviderInternal>\n </ConnectorErrorBoundary>\n );\n}\n\nexport function useConnector(): ConnectorSnapshot {\n const client = useContext(ConnectorContext);\n if (!client) {\n throw new Error(\n 'useConnector must be used within ConnectorProvider. ' +\n 'Wrap your app with <ConnectorProvider> or <UnifiedProvider> to use connector hooks.',\n );\n }\n\n // Subscribe to state changes\n const state = useSyncExternalStore(\n React.useCallback(cb => client.subscribe(cb), [client]),\n React.useCallback(() => client.getSnapshot(), [client]),\n React.useCallback(() => client.getSnapshot(), [client]),\n );\n\n // Stable method references that don't change when state changes\n // These are bound once and reused across renders\n const methods = useMemo(\n () => ({\n select: client.select.bind(client),\n disconnect: client.disconnect.bind(client),\n selectAccount: client.selectAccount.bind(client),\n }),\n [client],\n );\n\n // Optimized: Only create new object when state actually changes\n return useMemo(\n () => ({\n ...state,\n ...methods,\n }),\n [state, methods],\n );\n}\n\n/**\n * Get the connector client instance\n * Returns null if not within ConnectorProvider or if initialization failed\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const client = useConnectorClient()\n *\n * if (!client) {\n * return <div>Connector not available</div>\n * }\n *\n * // Use client methods directly\n * const health = client.getHealth()\n * }\n * ```\n */\nexport function useConnectorClient(): ConnectorClient | null {\n return useContext(ConnectorContext);\n}\n","'use client';\n\nimport type { ReactNode, ComponentType, PropsWithChildren } from 'react';\nimport { ConnectorProvider } from './connector-provider';\nimport type { MobileWalletAdapterConfig } from './connector-provider';\nimport type { ConnectorConfig } from '../types/connector';\nimport type { UnifiedConfig } from '../config/unified-config';\n\nexport interface UnifiedProviderProps {\n children: ReactNode;\n\n // NEW: Option 1 - Pass UnifiedConfig directly (recommended)\n config?: UnifiedConfig;\n\n // OLD: Option 2 - Pass configs separately (backward compatible)\n connectorConfig?: ConnectorConfig;\n mobile?: MobileWalletAdapterConfig;\n\n // Optional additional providers to wrap around children\n providers?: Array<{\n component: ComponentType<PropsWithChildren>;\n props?: Record<string, unknown>;\n }>;\n}\n\nexport function UnifiedProvider({ children, config, connectorConfig, mobile, providers = [] }: UnifiedProviderProps) {\n // Handle both new and old patterns\n const actualConnectorConfig = config?.connectorConfig ?? connectorConfig;\n const actualMobile = config?.mobile ?? mobile;\n\n // Start with connector provider as the base\n let content = (\n <ConnectorProvider config={actualConnectorConfig} mobile={actualMobile}>\n {children}\n </ConnectorProvider>\n );\n\n // Wrap with additional providers in reverse order\n // so they nest properly (first provider is outermost)\n for (let i = providers.length - 1; i >= 0; i--) {\n const { component: Provider, props = {} } = providers[i];\n content = <Provider {...props}>{content}</Provider>;\n }\n\n return content;\n}\n\n// Export with practical alias\nexport { UnifiedProvider as AppProvider };\n","/**\n * @solana/connector - useCluster hook\n *\n * React hook for managing Solana cluster (network) state\n */\n\n'use client';\n\nimport { useMemo } from 'react';\nimport type { SolanaCluster, SolanaClusterId } from '@wallet-ui/core';\nimport { useConnector, useConnectorClient } from '../ui/connector-provider';\nimport {\n getClusterExplorerUrl,\n isMainnetCluster,\n isDevnetCluster,\n isTestnetCluster,\n isLocalCluster,\n getClusterType,\n type ClusterType,\n} from '../utils/cluster';\n\nexport interface UseClusterReturn {\n /** Currently active cluster */\n cluster: SolanaCluster | null;\n /** All available clusters */\n clusters: SolanaCluster[];\n /** Set the active cluster */\n setCluster: (id: SolanaClusterId) => Promise<void>;\n /** Whether the current cluster is mainnet */\n isMainnet: boolean;\n /** Whether the current cluster is devnet */\n isDevnet: boolean;\n /** Whether the current cluster is testnet */\n isTestnet: boolean;\n /** Whether the current cluster is running locally */\n isLocal: boolean;\n /** Solana Explorer base URL for the current cluster */\n explorerUrl: string;\n /** Cluster type (mainnet, devnet, testnet, localnet, custom) */\n type: ClusterType | null;\n}\n\n/**\n * Hook for managing Solana cluster (network) selection\n *\n * @example\n * ```tsx\n * function ClusterSwitcher() {\n * const { cluster, clusters, setCluster, isMainnet } = useCluster()\n *\n * return (\n * <select\n * value={cluster?.id}\n * onChange={(e) => setCluster(e.target.value as SolanaClusterId)}\n * >\n * {clusters.map(c => (\n * <option key={c.id} value={c.id}>{c.label}</option>\n * ))}\n * </select>\n * )\n * }\n * ```\n */\nexport function useCluster(): UseClusterReturn {\n const { cluster, clusters } = useConnector();\n const client = useConnectorClient();\n\n if (!client) {\n throw new Error('useCluster must be used within ConnectorProvider');\n }\n\n const setCluster = useMemo(\n () => async (id: SolanaClusterId) => {\n await client.setCluster(id);\n },\n [client],\n );\n\n return useMemo(() => {\n const isMainnet = cluster ? isMainnetCluster(cluster) : false;\n const isDevnet = cluster ? isDevnetCluster(cluster) : false;\n const isTestnet = cluster ? isTestnetCluster(cluster) : false;\n const isLocal = cluster ? isLocalCluster(cluster) : false;\n const explorerUrl = cluster ? getClusterExplorerUrl(cluster) : '';\n const type = cluster ? getClusterType(cluster) : null;\n\n return {\n cluster,\n clusters,\n setCluster,\n isMainnet,\n isDevnet,\n isTestnet,\n isLocal,\n explorerUrl,\n type,\n };\n }, [cluster, clusters, setCluster]);\n}\n","/**\n * @solana/connector - useAccount hook\n *\n * React hook for working with the connected wallet account\n */\n\n'use client';\n\nimport React, { useState, useCallback, useMemo } from 'react';\nimport { useConnector } from '../ui/connector-provider';\nimport { copyAddressToClipboard, formatAddress, ClipboardErrorType, type ClipboardResult } from '../utils';\nimport type { AccountInfo } from '../types/accounts';\nimport { COPY_FEEDBACK_DURATION_MS } from '../lib/constants';\n\nexport interface UseAccountReturn {\n /** The connected wallet address */\n address: string | null;\n /** Full account info object */\n account: AccountInfo | null;\n /** Whether a wallet is connected */\n connected: boolean;\n /** Shortened formatted address for display */\n formatted: string;\n /** Copy the address to clipboard with enhanced result */\n copy: () => Promise<ClipboardResult>;\n /** Whether the address was recently copied */\n copied: boolean;\n /** All available accounts from the connected wallet */\n accounts: AccountInfo[];\n /** Select a different account from the connected wallet */\n selectAccount: (address: string) => Promise<void>;\n}\n\n/**\n * Hook for working with the connected wallet account\n * Provides formatted address, clipboard copying, and account selection\n *\n * @example\n * ```tsx\n * function AccountDisplay() {\n * const { address, formatted, copy, copied, connected } = useAccount()\n *\n * if (!connected) return <p>Not connected</p>\n *\n * return (\n * <button onClick={copy}>\n * {formatted} {copied && '✓'}\n * </button>\n * )\n * }\n * ```\n */\nexport function useAccount(): UseAccountReturn {\n const { selectedAccount, accounts, connected, selectAccount } = useConnector();\n const [copied, setCopied] = useState(false);\n const copyTimeoutRef = React.useRef<NodeJS.Timeout | undefined>(undefined);\n\n const account = useMemo(\n () => accounts.find((a: AccountInfo) => a.address === selectedAccount) ?? null,\n [accounts, selectedAccount],\n );\n\n const formatted = useMemo(() => (selectedAccount ? formatAddress(selectedAccount) : ''), [selectedAccount]);\n\n const copy = useCallback(async (): Promise<ClipboardResult> => {\n if (!selectedAccount) {\n return {\n success: false,\n error: ClipboardErrorType.EMPTY_VALUE,\n errorMessage: 'No account selected',\n };\n }\n\n if (copyTimeoutRef.current) {\n clearTimeout(copyTimeoutRef.current);\n }\n\n const result = await copyAddressToClipboard(selectedAccount, {\n onSuccess: () => {\n setCopied(true);\n copyTimeoutRef.current = setTimeout(() => setCopied(false), COPY_FEEDBACK_DURATION_MS);\n },\n });\n\n return result;\n }, [selectedAccount]);\n\n React.useEffect(() => {\n return () => {\n if (copyTimeoutRef.current) {\n clearTimeout(copyTimeoutRef.current);\n }\n };\n }, []);\n\n return useMemo(\n () => ({\n address: selectedAccount,\n account,\n connected,\n formatted,\n copy,\n copied,\n accounts,\n selectAccount,\n }),\n [selectedAccount, account, connected, formatted, copy, copied, accounts, selectAccount],\n );\n}\n","/**\n * @solana/connector - useWalletInfo hook\n *\n * React hook for getting information about the connected wallet\n */\n\n'use client';\n\nimport { useMemo } from 'react';\nimport { useConnector } from '../ui/connector-provider';\nimport type { WalletInfo } from '../types/wallets';\n\n/**\n * Simplified wallet information for display purposes\n */\nexport interface WalletDisplayInfo {\n /** Wallet name */\n name: string;\n /** Wallet icon/logo URL if available */\n icon?: string;\n /** Whether the wallet extension is installed */\n installed: boolean;\n /** Whether the wallet supports Solana connections */\n connectable?: boolean;\n}\n\n/**\n * Return value from useWalletInfo hook\n */\nexport interface UseWalletInfoReturn {\n /** Name of the connected wallet (e.g., 'Phantom', 'Solflare') */\n name: string | null;\n /** Wallet icon/logo URL if available */\n icon: string | null;\n /** Whether the wallet extension is installed */\n installed: boolean;\n /** Whether the wallet supports Solana connections */\n connectable: boolean;\n /** Whether currently connected to the wallet */\n connected: boolean;\n /** Whether a connection attempt is in progress */\n connecting: boolean;\n /** All available wallets */\n wallets: WalletDisplayInfo[];\n}\n\n/**\n * Hook for getting information about the connected wallet\n * Provides wallet metadata, connection status, and capabilities\n *\n * @example\n * ```tsx\n * function WalletBadge() {\n * const { name, icon, connected, connecting } = useWalletInfo()\n *\n * if (connecting) return <p>Connecting...</p>\n * if (!connected) return <p>No wallet connected</p>\n *\n * return (\n * <div>\n * {icon && <img src={icon} alt={name} />}\n * <span>{name}</span>\n * </div>\n * )\n * }\n * ```\n */\nexport function useWalletInfo(): UseWalletInfoReturn {\n const { selectedWallet, wallets, connected, connecting } = useConnector();\n\n // Map WalletInfo[] to WalletDisplayInfo[] for simplified consumption\n const mappedWallets = useMemo<WalletDisplayInfo[]>(\n () =>\n wallets.map(\n (walletInfo: WalletInfo): WalletDisplayInfo => ({\n name: walletInfo.wallet.name,\n icon: walletInfo.wallet.icon,\n installed: walletInfo.installed,\n connectable: walletInfo.connectable,\n }),\n ),\n [wallets],\n );\n\n // Extract information about the currently selected wallet\n const selectedWalletInfo = useMemo(() => {\n if (!selectedWallet) {\n return {\n name: null,\n icon: null,\n installed: false,\n connectable: false,\n };\n }\n\n // Find the WalletInfo for the selected wallet\n const walletInfo = wallets.find((w: WalletInfo) => w.wallet.name === selectedWallet.name);\n\n return {\n name: selectedWallet.name,\n icon: selectedWallet.icon ?? null,\n installed: walletInfo?.installed ?? false,\n connectable: walletInfo?.connectable ?? false,\n };\n }, [selectedWallet, wallets]);\n\n return useMemo(\n () => ({\n ...selectedWalletInfo,\n connected,\n connecting,\n wallets: mappedWallets,\n }),\n [selectedWalletInfo, connected, connecting, mappedWallets],\n );\n}\n","/**\n * @solana/connector - useTransactionSigner hook\n *\n * React hook for transaction signing operations\n * Provides a clean interface for signing and sending transactions\n * with automatic signer creation and lifecycle management\n */\n\n'use client';\n\nimport { useMemo } from 'react';\nimport { useConnector } from '../ui/connector-provider';\nimport { useConnectorClient } from '../ui/connector-provider';\nimport { createTransactionSigner, type TransactionSigner } from '../lib/transaction/transaction-signer';\nimport type { TransactionSignerCapabilities } from '../types/transactions';\n\n/**\n * Return value from useTransactionSigner hook\n */\nexport interface UseTransactionSignerReturn {\n /**\n * Transaction signer instance (null if not connected)\n * Use this to sign and send transactions\n */\n signer: TransactionSigner | null;\n\n /**\n * Whether a signer is available and ready to use\n * Useful for disabling transaction buttons\n */\n ready: boolean;\n\n /**\n * Current wallet address that will sign transactions\n * Null if no wallet connected\n */\n address: string | null;\n\n /**\n * Signer capabilities (what operations are supported)\n * Always available even if signer is null (shows all false)\n */\n capabilities: TransactionSignerCapabilities;\n}\n\n/**\n * Hook for transaction signing operations\n *\n * Automatically creates a TransactionSigner when a wallet is connected,\n * and provides convenient state for building transaction UIs.\n *\n * The signer is automatically recreated when:\n * - Wallet connection state changes\n * - Selected account changes\n * - Active cluster/network changes\n *\n * @example\n * ```tsx\n * function SendTransaction() {\n * const { signer, ready, capabilities } = useTransactionSigner()\n * const [txSignature, setTxSignature] = useState<string | null>(null)\n * const [error, setError] = useState<string | null>(null)\n *\n * const handleSend = async () => {\n * if (!signer) return\n *\n * try {\n * const signature = await signer.signAndSendTransaction(transaction)\n * setTxSignature(signature)\n * setError(null)\n * } catch (err) {\n * setError(err instanceof Error ? err.message : 'Transaction failed')\n * }\n * }\n *\n * return (\n * <div>\n * <button onClick={handleSend} disabled={!ready}>\n * {ready ? 'Send Transaction' : 'Connect Wallet'}\n * </button>\n *\n * {!capabilities.canSend && ready && (\n * <p className=\"warning\">\n * Your wallet doesn't support direct sending.\n * Transaction must be signed and broadcast separately.\n * </p>\n * )}\n *\n * {txSignature && (\n * <p>Transaction sent: {txSignature}</p>\n * )}\n *\n * {error && (\n * <p className=\"error\">{error}</p>\n * )}\n * </div>\n * )\n * }\n * ```\n *\n * @example\n * ```tsx\n * // Using with multiple transactions\n * function SendBatch() {\n * const { signer, ready, capabilities } = useTransactionSigner()\n *\n * const handleSendBatch = async () => {\n * if (!signer) return\n *\n * const transactions = [tx1, tx2, tx3]\n *\n * // Check if batch signing is supported\n * if (capabilities.supportsBatchSigning) {\n * // More efficient: sign all at once\n * const signed = await signer.signAllTransactions(transactions)\n * // ... send signed transactions\n * } else {\n * // Fallback: sign and send one by one\n * const signatures = await signer.signAndSendTransactions(transactions)\n * console.log('All sent:', signatures)\n * }\n * }\n *\n * return (\n * <button onClick={handleSendBatch} disabled={!ready}>\n * Send {capabilities.supportsBatchSigning ? 'Batch' : 'Sequential'}\n * </button>\n * )\n * }\n * ```\n *\n * @example\n * ```tsx\n * // Using with message signing for authentication\n * function SignInWithWallet() {\n * const { signer, ready, capabilities } = useTransactionSigner()\n *\n * const handleSignIn = async () => {\n * if (!signer || !capabilities.canSignMessage) {\n * alert('Wallet does not support message signing')\n * return\n * }\n *\n * const message = new TextEncoder().encode('Sign in to MyApp')\n * const signature = await signer.signMessage!(message)\n *\n * // Send signature to backend for verification\n * await fetch('/api/auth/verify', {\n * method: 'POST',\n * body: JSON.stringify({\n * message: Array.from(message),\n * signature: Array.from(signature),\n * address: signer.address\n * })\n * })\n * }\n *\n * if (!capabilities.canSignMessage) {\n * return <p>Message signing not supported</p>\n * }\n *\n * return (\n * <button onClick={handleSignIn} disabled={!ready}>\n * Sign In with Wallet\n * </button>\n * )\n * }\n * ```\n */\nexport function useTransactionSigner(): UseTransactionSignerReturn {\n const { selectedWallet, selectedAccount, accounts, cluster, connected } = useConnector();\n const client = useConnectorClient();\n\n const account = useMemo(\n () => accounts.find(a => a.address === selectedAccount)?.raw ?? null,\n [accounts, selectedAccount],\n );\n\n const signer = useMemo(() => {\n if (!connected || !selectedWallet || !account) {\n return null;\n }\n\n return createTransactionSigner({\n wallet: selectedWallet,\n account,\n cluster: cluster ?? undefined,\n eventEmitter: client\n ? {\n emit: (event: unknown) => {\n // Use the public emitEvent method\n client.emitEvent(event as import('../types/events').ConnectorEvent);\n },\n }\n : undefined,\n });\n }, [connected, selectedWallet, account, cluster, client]);\n\n const capabilities = useMemo(\n () =>\n signer?.getCapabilities() ?? {\n canSign: false,\n canSend: false,\n canSignMessage: false,\n supportsBatchSigning: false,\n },\n [signer],\n );\n\n return {\n signer,\n ready: Boolean(signer),\n address: selectedAccount,\n capabilities,\n };\n}\n","/**\n * @solana/connector - useGillTransactionSigner hook\n *\n * React hook for gill-compatible transaction signing\n * Use this when working with modern Solana libraries (@solana/kit, gill)\n */\n\n'use client';\n\nimport { useMemo } from 'react';\nimport type { TransactionModifyingSigner } from 'gill';\nimport { useTransactionSigner } from './use-transaction-signer';\nimport { createGillTransactionSigner } from '../lib/transaction/gill-transaction-signer';\n\n/**\n * Return value from useGillTransactionSigner hook\n */\nexport interface UseGillTransactionSignerReturn {\n /**\n * Gill-compatible TransactionModifyingSigner instance (null if not connected)\n * Use this with modern Solana libraries (@solana/kit, gill)\n */\n signer: TransactionModifyingSigner | null;\n\n /**\n * Whether a signer is available and ready to use\n * Useful for disabling transaction buttons\n */\n ready: boolean;\n}\n\n/**\n * Hook for gill-compatible transaction signing\n *\n * Creates a TransactionPartialSigner that's compatible with @solana/kit and gill,\n * enabling seamless integration with modern Solana development patterns.\n *\n * This hook wraps the standard useTransactionSigner and adapts it to gill's\n * interface, allowing you to use modern libraries without type incompatibilities.\n *\n * @example\n * ```tsx\n * import { useGillTransactionSigner } from '@solana/connector';\n * import { getTransferSolInstruction } from 'gill/programs';\n * import { address, pipe, createTransactionMessage } from 'gill';\n *\n * function ModernTransfer() {\n * const { signer, ready } = useGillTransactionSigner();\n *\n * const handleTransfer = async (recipient: string, amount: number) => {\n * if (!signer) return;\n *\n * // Fully type-safe with gill!\n * const instruction = getTransferSolInstruction({\n * source: signer, // No type errors\n * destination: address(recipient),\n * amount\n * });\n *\n * const txMessage = pipe(\n * createTransactionMessage({ version: 0 }),\n * (tx) => setTransactionMessageFeePayerSigner(signer, tx), // Works!\n * // ...\n * );\n * };\n *\n * return (\n * <button onClick={handleTransfer} disabled={!ready}>\n * Send with Gill\n * </button>\n * );\n * }\n * ```\n *\n * @example\n * ```tsx\n * // For backward compatibility, continue using useTransactionSigner\n * import { useTransactionSigner } from '@solana/connector';\n *\n * function LegacyTransfer() {\n * const { signer } = useTransactionSigner(); // Wallet adapter compatible\n * // Works with @solana/web3.js v1 and wallet-adapter\n * }\n * ```\n */\nexport function useGillTransactionSigner(): UseGillTransactionSignerReturn {\n const { signer: connectorSigner, ready } = useTransactionSigner();\n\n const gillSigner = useMemo(() => {\n if (!connectorSigner) return null;\n return createGillTransactionSigner(connectorSigner);\n }, [connectorSigner]);\n\n return {\n signer: gillSigner,\n ready,\n };\n}\n","/**\n * @solana/connector - useGillSolanaClient hook\n *\n * React hook for Gill's SolanaClient with built-in RPC and WebSocket subscriptions\n * Provides rpc, rpcSubscriptions, sendAndConfirmTransaction, and simulateTransaction\n */\n\n'use client';\n\nimport { useMemo } from 'react';\nimport { createSolanaClient, type SolanaClient, type ModifiedClusterUrl } from 'gill';\nimport { useCluster } from './use-cluster';\nimport { useConnectorClient } from '../ui/connector-provider';\nimport type { ClusterType } from '../utils/cluster';\nimport { createLogger } from '../lib/utils/secure-logger';\n\nconst logger = createLogger('useGillSolanaClient');\n\n/**\n * Return value from useGillSolanaClient hook\n */\nexport interface UseGillSolanaClientReturn {\n /**\n * Gill SolanaClient instance with RPC and subscriptions (null if not available)\n * Includes: rpc, rpcSubscriptions, sendAndConfirmTransaction, simulateTransaction\n */\n client: SolanaClient | null;\n\n /**\n * Whether a client is available and ready to use\n */\n ready: boolean;\n\n /**\n * Cluster type (mainnet, devnet, testnet, localnet, custom)\n */\n clusterType: ClusterType | null;\n}\n\n/**\n * Hook for Gill's SolanaClient with automatic RPC and WebSocket subscription management\n *\n * Creates a fully configured SolanaClient based on the current cluster, providing:\n * - Type-safe RPC client\n * - WebSocket subscription client\n * - Built-in sendAndConfirmTransaction helper\n * - Built-in simulateTransaction helper\n *\n * The client is automatically recreated when the cluster changes.\n *\n * @example\n * ```tsx\n * import { useGillSolanaClient, useGillTransactionSigner } from '@solana/connector';\n * import { signTransactionMessageWithSigners } from 'gill';\n *\n * function SendTransaction() {\n * const { client, ready } = useGillSolanaClient();\n * const { signer } = useGillTransactionSigner();\n *\n * const handleSend = async (transaction) => {\n * if (!client || !signer) return;\n *\n * // Sign the transaction\n * const signed = await signTransactionMessageWithSigners(transaction);\n *\n * // Send and confirm using Gill's built-in helper\n * await client.sendAndConfirmTransaction(signed, {\n * commitment: 'confirmed'\n * });\n * };\n *\n * return (\n * <button onClick={handleSend} disabled={!ready}>\n * Send Transaction\n * </button>\n * );\n * }\n * ```\n *\n * @example\n * ```tsx\n * // Simulating a transaction\n * function SimulateTransaction() {\n * const { client } = useGillSolanaClient();\n *\n * const handleSimulate = async (transaction) => {\n * if (!client) return;\n *\n * const simulation = await client.simulateTransaction(transaction, {\n * sigVerify: false,\n * commitment: 'processed'\n * });\n *\n * console.log('Simulation result:', simulation);\n * };\n * }\n * ```\n *\n * @example\n * ```tsx\n * // Direct RPC access\n * function GetBalance() {\n * const { client } = useGillSolanaClient();\n *\n * const fetchBalance = async (address: Address) => {\n * if (!client) return;\n *\n * const balance = await client.rpc.getBalance(address).send();\n * console.log('Balance:', balance);\n * };\n * }\n * ```\n */\nexport function useGillSolanaClient(): UseGillSolanaClientReturn {\n const { type } = useCluster();\n const connectorClient = useConnectorClient();\n\n const client = useMemo(() => {\n if (!type || !connectorClient) return null;\n\n try {\n // For non-custom clusters, use moniker\n if (type !== 'custom') {\n return createSolanaClient({\n urlOrMoniker: type,\n });\n }\n\n // For custom clusters, get RPC URL from connector client\n const rpcUrl = connectorClient.getRpcUrl();\n if (!rpcUrl) return null;\n\n return createSolanaClient({\n urlOrMoniker: rpcUrl as ModifiedClusterUrl,\n });\n } catch (error) {\n logger.error('Failed to create Gill Solana client', { error });\n return null;\n }\n }, [type, connectorClient]);\n\n return {\n client,\n ready: Boolean(client),\n clusterType: type,\n };\n}\n","/**\n * @solana/connector - useTransactionPreparer hook\n *\n * React hook for preparing transactions with automatic optimization\n * Handles blockhash fetching, compute unit limits, and transaction simulation\n */\n\n'use client';\n\nimport { useCallback } from 'react';\nimport {\n prepareTransaction,\n type PrepareTransactionConfig,\n type CompilableTransactionMessage,\n type TransactionMessageWithBlockhashLifetime,\n} from 'gill';\nimport { useGillSolanaClient } from './use-gill-solana-client';\nimport { NetworkError } from '../lib/errors';\n\n/**\n * Options for transaction preparation\n */\nexport interface TransactionPrepareOptions {\n /**\n * Multiplier applied to the simulated compute unit value\n * @default 1.1 (10% buffer)\n */\n computeUnitLimitMultiplier?: number;\n\n /**\n * Whether to force reset the compute unit limit value (if one is already set)\n * using the simulation response and computeUnitLimitMultiplier\n * @default false\n */\n computeUnitLimitReset?: boolean;\n\n /**\n * Whether to force reset the latest blockhash (if one is already set)\n * @default true\n */\n blockhashReset?: boolean;\n}\n\n/**\n * Return value from useTransactionPreparer hook\n */\nexport interface UseTransactionPreparerReturn {\n /**\n * Prepare a transaction for sending\n * Automatically adds:\n * - Compute unit limit (via simulation with optional multiplier)\n * - Latest blockhash (if not already set)\n *\n * @param transaction - The transaction to prepare\n * @param options - Optional preparation settings\n * @returns Prepared transaction with blockhash lifetime set\n */\n prepare: <TMessage extends CompilableTransactionMessage>(\n transaction: TMessage,\n options?: TransactionPrepareOptions,\n ) => Promise<TMessage & TransactionMessageWithBlockhashLifetime>;\n\n /**\n * Whether the preparer is ready to use\n * False if Solana client is not available\n */\n ready: boolean;\n}\n\n/**\n * Hook for preparing transactions with automatic optimization\n *\n * Uses Gill's prepareTransaction utility to:\n * 1. Simulate the transaction to determine optimal compute units\n * 2. Set compute unit limit (with configurable multiplier for safety margin)\n * 3. Fetch and set the latest blockhash (if not already present)\n *\n * This significantly improves transaction landing rates by ensuring proper\n * compute budget allocation and fresh blockhashes.\n *\n * @example\n * ```tsx\n * import { useTransactionPreparer, useGillTransactionSigner } from '@solana/connector';\n * import { pipe, createTransactionMessage, appendTransactionMessageInstructions } from 'gill';\n * import { getTransferSolInstruction } from 'gill/programs';\n *\n * function SendOptimizedTransaction() {\n * const { prepare, ready } = useTransactionPreparer();\n * const { signer } = useGillTransactionSigner();\n * const { client } = useGillSolanaClient();\n *\n * const handleSend = async (recipient: string, amount: bigint) => {\n * if (!ready || !signer || !client) return;\n *\n * // Build transaction message\n * const tx = pipe(\n * createTransactionMessage({ version: 0 }),\n * tx => setTransactionMessageFeePayerSigner(signer, tx),\n * tx => appendTransactionMessageInstructions([\n * getTransferSolInstruction({\n * source: signer,\n * destination: address(recipient),\n * amount: lamports(amount),\n * })\n * ], tx)\n * );\n *\n * // Prepare: auto-adds compute units + blockhash\n * const prepared = await prepare(tx);\n *\n * // Sign\n * const signed = await signTransactionMessageWithSigners(prepared);\n *\n * // Send and confirm\n * await client.sendAndConfirmTransaction(signed);\n * };\n *\n * return (\n * <button onClick={handleSend} disabled={!ready}>\n * Send Optimized Transaction\n * </button>\n * );\n * }\n * ```\n *\n * @example\n * ```tsx\n * // With custom compute unit multiplier for high-priority transactions\n * const { prepare } = useTransactionPreparer();\n *\n * const prepared = await prepare(transaction, {\n * computeUnitLimitMultiplier: 1.3, // 30% buffer instead of default 10%\n * blockhashReset: true // Always fetch fresh blockhash\n * });\n * ```\n *\n * @example\n * ```tsx\n * // Force reset compute units even if already set\n * const { prepare } = useTransactionPreparer();\n *\n * const prepared = await prepare(transaction, {\n * computeUnitLimitReset: true, // Re-simulate and reset compute units\n * computeUnitLimitMultiplier: 1.2\n * });\n * ```\n */\nexport function useTransactionPreparer(): UseTransactionPreparerReturn {\n const { client, ready } = useGillSolanaClient();\n\n const prepare = useCallback(\n async <TMessage extends CompilableTransactionMessage>(\n transaction: TMessage,\n options: TransactionPrepareOptions = {},\n ): Promise<TMessage & TransactionMessageWithBlockhashLifetime> => {\n if (!client) {\n throw new NetworkError('RPC_ERROR', 'Solana client not available. Cannot prepare transaction.');\n }\n\n return prepareTransaction({\n transaction,\n rpc: client.rpc,\n computeUnitLimitMultiplier: options.computeUnitLimitMultiplier,\n computeUnitLimitReset: options.computeUnitLimitReset,\n blockhashReset: options.blockhashReset,\n });\n },\n [client],\n );\n\n return {\n prepare,\n ready,\n };\n}\n"]}
|