@solana/connector 0.1.2 → 0.1.4
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/LICENSE +21 -0
- package/README.md +460 -1082
- package/dist/{chunk-RIBOPAOD.js → chunk-CLXM6UEE.js} +149 -121
- package/dist/chunk-CLXM6UEE.js.map +1 -0
- package/dist/{chunk-JS4KJ2KK.js → chunk-D6PZY5G6.js} +71 -93
- package/dist/chunk-D6PZY5G6.js.map +1 -0
- package/dist/chunk-LUZWUZ5N.js +2012 -0
- package/dist/chunk-LUZWUZ5N.js.map +1 -0
- package/dist/{chunk-WXYUUCSD.mjs → chunk-N3Q2J2FG.mjs} +53 -71
- package/dist/chunk-N3Q2J2FG.mjs.map +1 -0
- package/dist/chunk-P5MWBDFG.mjs +298 -0
- package/dist/chunk-P5MWBDFG.mjs.map +1 -0
- package/dist/chunk-RIQH5W7D.js +311 -0
- package/dist/chunk-RIQH5W7D.js.map +1 -0
- package/dist/chunk-U64YZRJL.mjs +1984 -0
- package/dist/chunk-U64YZRJL.mjs.map +1 -0
- package/dist/{chunk-4K6QY4HR.mjs → chunk-YTCSTE3Q.mjs} +64 -37
- package/dist/chunk-YTCSTE3Q.mjs.map +1 -0
- package/dist/compat.d.mts +4 -2
- package/dist/compat.d.ts +4 -2
- package/dist/compat.js +3 -3
- package/dist/compat.mjs +1 -1
- package/dist/headless.d.mts +146 -18
- package/dist/headless.d.ts +146 -18
- package/dist/headless.js +144 -111
- package/dist/headless.mjs +3 -2
- package/dist/index.d.mts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +207 -126
- package/dist/index.mjs +4 -3
- package/dist/react.d.mts +707 -67
- package/dist/react.d.ts +707 -67
- package/dist/react.js +64 -16
- package/dist/react.mjs +2 -2
- package/dist/{transaction-signer-D3csM_Mf.d.ts → transaction-signer-D9d8nxwb.d.mts} +3 -1
- package/dist/{transaction-signer-D3csM_Mf.d.mts → transaction-signer-D9d8nxwb.d.ts} +3 -1
- package/dist/{wallet-standard-shim-Cg0GVGwu.d.mts → wallet-standard-shim-Cp4vF4oo.d.mts} +133 -6
- package/dist/{wallet-standard-shim-C1tisl9S.d.ts → wallet-standard-shim-DC_Z7DS-.d.ts} +133 -6
- package/package.json +16 -12
- package/dist/chunk-4K6QY4HR.mjs.map +0 -1
- package/dist/chunk-5ZUVZZWU.mjs +0 -180
- package/dist/chunk-5ZUVZZWU.mjs.map +0 -1
- package/dist/chunk-F2QJH5ED.mjs +0 -298
- package/dist/chunk-F2QJH5ED.mjs.map +0 -1
- package/dist/chunk-JS4KJ2KK.js.map +0 -1
- package/dist/chunk-RIBOPAOD.js.map +0 -1
- package/dist/chunk-SJEZHNYF.js +0 -314
- package/dist/chunk-SJEZHNYF.js.map +0 -1
- package/dist/chunk-SMUUAKC3.js +0 -186
- package/dist/chunk-SMUUAKC3.js.map +0 -1
- package/dist/chunk-WXYUUCSD.mjs.map +0 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { createLogger, __publicField, isWeb3jsTransaction, prepareTransactionForWallet, convertSignedTransaction } from './chunk-
|
|
2
|
-
import { getPublicSolanaRpcUrl, getExplorerLink, LAMPORTS_PER_SOL, address, getTransactionDecoder, getSignatureFromBytes, isAddress } from 'gill';
|
|
1
|
+
import { createLogger, __publicField, getPublicSolanaRpcUrl, getExplorerLink, isWeb3jsTransaction, prepareTransactionForWallet, convertSignedTransaction } from './chunk-P5MWBDFG.mjs';
|
|
3
2
|
import { Component, useTransition, useState, useCallback, useMemo } from 'react';
|
|
4
3
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
5
4
|
import { install } from '@solana/webcrypto-ed25519-polyfill';
|
|
5
|
+
import { address, isAddress } from '@solana/addresses';
|
|
6
|
+
import { getTransactionDecoder, assertIsTransactionWithinSizeLimit } from '@solana/transactions';
|
|
7
|
+
import { getBase58Decoder } from '@solana/codecs';
|
|
6
8
|
|
|
7
9
|
// src/lib/adapters/wallet-standard-shim.ts
|
|
8
10
|
var registry = null;
|
|
@@ -123,11 +125,16 @@ function isTransactionError(error) {
|
|
|
123
125
|
}
|
|
124
126
|
var Errors = {
|
|
125
127
|
walletNotConnected: (context) => new ConnectionError("WALLET_NOT_CONNECTED", "No wallet connected", context),
|
|
126
|
-
walletNotFound: (walletName) => new ConnectionError("WALLET_NOT_FOUND", `Wallet not found${walletName ? `: ${walletName}` : ""}`, {
|
|
128
|
+
walletNotFound: (walletName) => new ConnectionError("WALLET_NOT_FOUND", `Wallet not found${walletName ? `: ${walletName}` : ""}`, {
|
|
129
|
+
walletName
|
|
130
|
+
}),
|
|
127
131
|
connectionFailed: (originalError) => new ConnectionError("CONNECTION_FAILED", "Failed to connect to wallet", void 0, originalError),
|
|
128
132
|
accountNotAvailable: (address) => new ConnectionError("ACCOUNT_NOT_AVAILABLE", "Requested account not available", { address }),
|
|
129
133
|
invalidTransaction: (reason, context) => new ValidationError("INVALID_TRANSACTION", `Invalid transaction: ${reason}`, context),
|
|
130
|
-
invalidFormat: (expectedFormat, actualFormat) => new ValidationError("INVALID_FORMAT", `Invalid format: expected ${expectedFormat}`, {
|
|
134
|
+
invalidFormat: (expectedFormat, actualFormat) => new ValidationError("INVALID_FORMAT", `Invalid format: expected ${expectedFormat}`, {
|
|
135
|
+
expectedFormat,
|
|
136
|
+
actualFormat
|
|
137
|
+
}),
|
|
131
138
|
unsupportedFormat: (format) => new ValidationError("UNSUPPORTED_FORMAT", `Unsupported format: ${format}`, { format }),
|
|
132
139
|
missingProvider: (hookName) => new ConfigurationError(
|
|
133
140
|
"MISSING_PROVIDER",
|
|
@@ -170,6 +177,8 @@ function getUserFriendlyMessage(error) {
|
|
|
170
177
|
NETWORK_TIMEOUT: "Request timed out. Please try again."
|
|
171
178
|
}[error.code] || error.message || "An error occurred." : "An unexpected error occurred. Please try again.";
|
|
172
179
|
}
|
|
180
|
+
|
|
181
|
+
// src/utils/network.ts
|
|
173
182
|
var PUBLIC_RPC_ENDPOINTS = {
|
|
174
183
|
mainnet: "https://api.mainnet-beta.solana.com",
|
|
175
184
|
devnet: "https://api.devnet.solana.com",
|
|
@@ -217,6 +226,8 @@ function getNetworkDisplayName(network) {
|
|
|
217
226
|
let normalized = normalizeNetwork(network);
|
|
218
227
|
return normalized.charAt(0).toUpperCase() + normalized.slice(1);
|
|
219
228
|
}
|
|
229
|
+
|
|
230
|
+
// src/utils/cluster.ts
|
|
220
231
|
function getClusterRpcUrl(cluster) {
|
|
221
232
|
if (typeof cluster == "string") {
|
|
222
233
|
let presets2 = {
|
|
@@ -334,7 +345,7 @@ var StateManager = class {
|
|
|
334
345
|
* Fast array equality check for wallet/account arrays
|
|
335
346
|
*/
|
|
336
347
|
arraysEqual(a, b) {
|
|
337
|
-
return a.length !== b.length ? false : a[0] && typeof a[0] == "object" && "name" in a[0] && b[0] && typeof b[0] == "object" && "name" in b[0] ? a.every((item, i) => {
|
|
348
|
+
return a.length !== b.length ? false : a.length === 0 ? true : a[0] && typeof a[0] == "object" && "name" in a[0] && b[0] && typeof b[0] == "object" && "name" in b[0] ? a.every((item, i) => {
|
|
338
349
|
let aItem = item, bItem = b[i];
|
|
339
350
|
if (!bItem || typeof bItem != "object") return false;
|
|
340
351
|
let keysA = Object.keys(aItem), keysB = Object.keys(bItem);
|
|
@@ -1086,24 +1097,26 @@ var logger4 = createLogger("AutoConnector"), MIN_ADDRESS_LENGTH = 30, AutoConnec
|
|
|
1086
1097
|
if (this.debug && (logger4.debug("Direct wallet connect result", { result }), logger4.debug("Direct wallet publicKey property", { publicKey: directWallet.publicKey })), result && typeof result == "object" && "accounts" in result && Array.isArray(result.accounts))
|
|
1087
1098
|
return result;
|
|
1088
1099
|
let legacyResult = result;
|
|
1089
|
-
if (legacyResult?.publicKey && typeof legacyResult.publicKey.toString == "function")
|
|
1100
|
+
if (legacyResult?.publicKey && typeof legacyResult.publicKey.toString == "function") {
|
|
1101
|
+
let address = legacyResult.publicKey.toString(), publicKeyBytes = legacyResult.publicKey.toBytes ? legacyResult.publicKey.toBytes() : new Uint8Array();
|
|
1090
1102
|
return {
|
|
1091
1103
|
accounts: [
|
|
1092
1104
|
{
|
|
1093
|
-
address
|
|
1094
|
-
publicKey:
|
|
1105
|
+
address,
|
|
1106
|
+
publicKey: publicKeyBytes,
|
|
1095
1107
|
chains: ["solana:mainnet", "solana:devnet", "solana:testnet"],
|
|
1096
1108
|
features: []
|
|
1097
1109
|
}
|
|
1098
1110
|
]
|
|
1099
1111
|
};
|
|
1112
|
+
}
|
|
1100
1113
|
if (directWallet.publicKey && typeof directWallet.publicKey.toString == "function") {
|
|
1101
|
-
let address = directWallet.publicKey.toString();
|
|
1114
|
+
let address = directWallet.publicKey.toString(), publicKeyBytes = directWallet.publicKey.toBytes ? directWallet.publicKey.toBytes() : new Uint8Array();
|
|
1102
1115
|
return this.debug && logger4.debug("Using legacy wallet pattern - publicKey from wallet object"), {
|
|
1103
1116
|
accounts: [
|
|
1104
1117
|
{
|
|
1105
1118
|
address,
|
|
1106
|
-
publicKey:
|
|
1119
|
+
publicKey: publicKeyBytes,
|
|
1107
1120
|
chains: ["solana:mainnet", "solana:devnet", "solana:testnet"],
|
|
1108
1121
|
features: []
|
|
1109
1122
|
}
|
|
@@ -1111,16 +1124,20 @@ var logger4 = createLogger("AutoConnector"), MIN_ADDRESS_LENGTH = 30, AutoConnec
|
|
|
1111
1124
|
};
|
|
1112
1125
|
}
|
|
1113
1126
|
let publicKeyResult = result;
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1127
|
+
if (publicKeyResult && typeof publicKeyResult.toString == "function" && publicKeyResult.toString().length > MIN_ADDRESS_LENGTH) {
|
|
1128
|
+
let address = publicKeyResult.toString(), publicKeyBytes = publicKeyResult.toBytes ? publicKeyResult.toBytes() : new Uint8Array();
|
|
1129
|
+
return {
|
|
1130
|
+
accounts: [
|
|
1131
|
+
{
|
|
1132
|
+
address,
|
|
1133
|
+
publicKey: publicKeyBytes,
|
|
1134
|
+
chains: ["solana:mainnet", "solana:devnet", "solana:testnet"],
|
|
1135
|
+
features: []
|
|
1136
|
+
}
|
|
1137
|
+
]
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
return this.debug && logger4.error("Legacy wallet: No valid publicKey found in any expected location"), { accounts: [] };
|
|
1124
1141
|
}
|
|
1125
1142
|
}), directWallet.disconnect) {
|
|
1126
1143
|
let disconnectFn = directWallet.disconnect;
|
|
@@ -1156,7 +1173,7 @@ var logger4 = createLogger("AutoConnector"), MIN_ADDRESS_LENGTH = 30, AutoConnec
|
|
|
1156
1173
|
features,
|
|
1157
1174
|
accounts: []
|
|
1158
1175
|
};
|
|
1159
|
-
|
|
1176
|
+
this.stateManager.updateState(
|
|
1160
1177
|
{
|
|
1161
1178
|
wallets: [
|
|
1162
1179
|
{
|
|
@@ -1167,8 +1184,13 @@ var logger4 = createLogger("AutoConnector"), MIN_ADDRESS_LENGTH = 30, AutoConnec
|
|
|
1167
1184
|
]
|
|
1168
1185
|
},
|
|
1169
1186
|
true
|
|
1170
|
-
)
|
|
1171
|
-
|
|
1187
|
+
);
|
|
1188
|
+
let walletsApi = getWalletsRegistry(), registryWallet = walletsApi.get().find((w) => w.name === storedWalletName), walletToUse = registryWallet || wallet;
|
|
1189
|
+
return this.debug && logger4.info("Attempting to connect via instant auto-connect", {
|
|
1190
|
+
walletName: storedWalletName,
|
|
1191
|
+
usingRegistry: !!registryWallet
|
|
1192
|
+
}), await this.connectionManager.connect(walletToUse, storedWalletName), this.debug && logger4.info("Instant auto-connect successful", { walletName: storedWalletName }), setTimeout(() => {
|
|
1193
|
+
let ws = walletsApi.get();
|
|
1172
1194
|
this.debug && logger4.debug("Checking for wallet standard update", {
|
|
1173
1195
|
wsLength: ws.length,
|
|
1174
1196
|
currentWalletsLength: this.stateManager.getSnapshot().wallets.length,
|
|
@@ -1822,6 +1844,8 @@ function getPolyfillStatus() {
|
|
|
1822
1844
|
environment: typeof window < "u" ? "browser" : "server"
|
|
1823
1845
|
};
|
|
1824
1846
|
}
|
|
1847
|
+
|
|
1848
|
+
// src/utils/formatting.ts
|
|
1825
1849
|
function formatAddress(address, options = {}) {
|
|
1826
1850
|
let { length = 4, separator = "..." } = options;
|
|
1827
1851
|
return !address || address.length <= length * 2 + separator.length ? address : `${address.slice(0, length)}${separator}${address.slice(-length)}`;
|
|
@@ -1829,10 +1853,10 @@ function formatAddress(address, options = {}) {
|
|
|
1829
1853
|
function formatSOL(lamports, options = {}) {
|
|
1830
1854
|
let { decimals = 4, suffix = true, fast = false } = options;
|
|
1831
1855
|
if (fast && typeof lamports == "number") {
|
|
1832
|
-
let formatted2 = (lamports /
|
|
1856
|
+
let formatted2 = (lamports / 1e9).toFixed(decimals);
|
|
1833
1857
|
return suffix ? `${formatted2} SOL` : formatted2;
|
|
1834
1858
|
}
|
|
1835
|
-
let lamportsBigInt = typeof lamports == "bigint" ? lamports : BigInt(lamports), formatted = (Number(lamportsBigInt) /
|
|
1859
|
+
let lamportsBigInt = typeof lamports == "bigint" ? lamports : BigInt(lamports), formatted = (Number(lamportsBigInt) / 1e9).toFixed(decimals);
|
|
1836
1860
|
return suffix ? `${formatted} SOL` : formatted;
|
|
1837
1861
|
}
|
|
1838
1862
|
function formatNumber(value, options = {}) {
|
|
@@ -2289,7 +2313,7 @@ var TransactionSignerError = class extends TransactionError {
|
|
|
2289
2313
|
function isTransactionSignerError(error) {
|
|
2290
2314
|
return error instanceof TransactionSignerError || error instanceof TransactionError;
|
|
2291
2315
|
}
|
|
2292
|
-
var logger10 = createLogger("
|
|
2316
|
+
var logger10 = createLogger("KitTransactionSigner");
|
|
2293
2317
|
function encodeShortVecLength(value) {
|
|
2294
2318
|
let bytes = [], remaining = value;
|
|
2295
2319
|
for (; remaining >= 128; )
|
|
@@ -2334,7 +2358,7 @@ function extractSignature(signedTx) {
|
|
|
2334
2358
|
}
|
|
2335
2359
|
throw new Error("Cannot extract signature from transaction format");
|
|
2336
2360
|
}
|
|
2337
|
-
function
|
|
2361
|
+
function createKitTransactionSigner(connectorSigner) {
|
|
2338
2362
|
let signerAddress = address(connectorSigner.address);
|
|
2339
2363
|
return {
|
|
2340
2364
|
address: signerAddress,
|
|
@@ -2391,29 +2415,32 @@ function createGillTransactionSigner(connectorSigner) {
|
|
|
2391
2415
|
return logger10.debug("Using modified transaction from wallet", {
|
|
2392
2416
|
modifiedMessageBytesLength: walletTransaction.messageBytes.length,
|
|
2393
2417
|
signatures: Object.keys(walletTransaction.signatures)
|
|
2394
|
-
}), result;
|
|
2418
|
+
}), assertIsTransactionWithinSizeLimit(result), result;
|
|
2395
2419
|
}
|
|
2396
|
-
let
|
|
2397
|
-
|
|
2420
|
+
let extractedSignatureBytes = extractSignature(signedTxBytes), signatureBase58 = getBase58Decoder().decode(extractedSignatureBytes);
|
|
2421
|
+
logger10.debug("Extracted signature from wallet (unmodified)", {
|
|
2398
2422
|
signerAddress,
|
|
2399
|
-
signatureLength:
|
|
2423
|
+
signatureLength: extractedSignatureBytes.length,
|
|
2400
2424
|
signatureBase58
|
|
2401
2425
|
// Human-readable signature for debugging/logging
|
|
2402
|
-
})
|
|
2426
|
+
});
|
|
2427
|
+
let typedSignatureBytes = extractedSignatureBytes, signedTransaction = {
|
|
2403
2428
|
...originalTransaction,
|
|
2404
2429
|
signatures: Object.freeze({
|
|
2405
2430
|
...originalTransaction.signatures,
|
|
2406
|
-
[signerAddress]:
|
|
2431
|
+
[signerAddress]: typedSignatureBytes
|
|
2407
2432
|
})
|
|
2408
2433
|
};
|
|
2434
|
+
return assertIsTransactionWithinSizeLimit(signedTransaction), signedTransaction;
|
|
2409
2435
|
} catch (error) {
|
|
2410
|
-
return logger10.error("Failed to decode signed transaction", { error }), originalTransaction;
|
|
2436
|
+
return logger10.error("Failed to decode signed transaction", { error }), assertIsTransactionWithinSizeLimit(originalTransaction), originalTransaction;
|
|
2411
2437
|
}
|
|
2412
2438
|
});
|
|
2413
2439
|
}
|
|
2414
2440
|
};
|
|
2415
2441
|
}
|
|
2442
|
+
var createGillTransactionSigner = createKitTransactionSigner;
|
|
2416
2443
|
|
|
2417
|
-
export { ClipboardErrorType, ConfigurationError, ConnectionError, ConnectorClient, ConnectorError, ConnectorErrorBoundary, DEFAULT_MAX_RETRIES, Errors, NetworkError, PUBLIC_RPC_ENDPOINTS, TransactionError, TransactionSignerError, ValidationError, WalletErrorType, copyAddressToClipboard, copySignatureToClipboard, copyToClipboard, createGillTransactionSigner, createTransactionSigner, formatAddress, formatNumber, formatSOL, formatTokenAmount, getAddressUrl, getBlockUrl, getChainIdForWalletStandard, getClusterChainId, getClusterExplorerUrl, getClusterName, getClusterRpcUrl, getClusterType, getDefaultRpcUrl, getNetworkDisplayName, getPolyfillStatus, getTokenUrl, getTransactionUrl, getUserFriendlyMessage, getWalletsRegistry, installPolyfills, isClipboardAvailable, isConfigurationError, isConnectionError, isConnectorError, isCryptoAvailable, isDevnet, isDevnetCluster, isLocalCluster, isLocalnet, isMainnet, isMainnetCluster, isNetworkError, isPolyfillInstalled, isTestnet, isTestnetCluster, isTransactionError, isTransactionSignerError, isValidationError, normalizeNetwork, toClusterId, toConnectorError, truncate, withErrorBoundary };
|
|
2418
|
-
//# sourceMappingURL=chunk-
|
|
2419
|
-
//# sourceMappingURL=chunk-
|
|
2444
|
+
export { ClipboardErrorType, ConfigurationError, ConnectionError, ConnectorClient, ConnectorError, ConnectorErrorBoundary, DEFAULT_MAX_RETRIES, Errors, NetworkError, PUBLIC_RPC_ENDPOINTS, TransactionError, TransactionSignerError, ValidationError, WalletErrorType, copyAddressToClipboard, copySignatureToClipboard, copyToClipboard, createGillTransactionSigner, createKitTransactionSigner, createTransactionSigner, formatAddress, formatNumber, formatSOL, formatTokenAmount, getAddressUrl, getBlockUrl, getChainIdForWalletStandard, getClusterChainId, getClusterExplorerUrl, getClusterName, getClusterRpcUrl, getClusterType, getDefaultRpcUrl, getNetworkDisplayName, getPolyfillStatus, getTokenUrl, getTransactionUrl, getUserFriendlyMessage, getWalletsRegistry, installPolyfills, isClipboardAvailable, isConfigurationError, isConnectionError, isConnectorError, isCryptoAvailable, isDevnet, isDevnetCluster, isLocalCluster, isLocalnet, isMainnet, isMainnetCluster, isNetworkError, isPolyfillInstalled, isTestnet, isTestnetCluster, isTransactionError, isTransactionSignerError, isValidationError, normalizeNetwork, toClusterId, toConnectorError, truncate, withErrorBoundary };
|
|
2445
|
+
//# sourceMappingURL=chunk-YTCSTE3Q.mjs.map
|
|
2446
|
+
//# sourceMappingURL=chunk-YTCSTE3Q.mjs.map
|