@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.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +460 -1082
  3. package/dist/{chunk-RIBOPAOD.js → chunk-CLXM6UEE.js} +149 -121
  4. package/dist/chunk-CLXM6UEE.js.map +1 -0
  5. package/dist/{chunk-JS4KJ2KK.js → chunk-D6PZY5G6.js} +71 -93
  6. package/dist/chunk-D6PZY5G6.js.map +1 -0
  7. package/dist/chunk-LUZWUZ5N.js +2012 -0
  8. package/dist/chunk-LUZWUZ5N.js.map +1 -0
  9. package/dist/{chunk-WXYUUCSD.mjs → chunk-N3Q2J2FG.mjs} +53 -71
  10. package/dist/chunk-N3Q2J2FG.mjs.map +1 -0
  11. package/dist/chunk-P5MWBDFG.mjs +298 -0
  12. package/dist/chunk-P5MWBDFG.mjs.map +1 -0
  13. package/dist/chunk-RIQH5W7D.js +311 -0
  14. package/dist/chunk-RIQH5W7D.js.map +1 -0
  15. package/dist/chunk-U64YZRJL.mjs +1984 -0
  16. package/dist/chunk-U64YZRJL.mjs.map +1 -0
  17. package/dist/{chunk-4K6QY4HR.mjs → chunk-YTCSTE3Q.mjs} +64 -37
  18. package/dist/chunk-YTCSTE3Q.mjs.map +1 -0
  19. package/dist/compat.d.mts +4 -2
  20. package/dist/compat.d.ts +4 -2
  21. package/dist/compat.js +3 -3
  22. package/dist/compat.mjs +1 -1
  23. package/dist/headless.d.mts +146 -18
  24. package/dist/headless.d.ts +146 -18
  25. package/dist/headless.js +144 -111
  26. package/dist/headless.mjs +3 -2
  27. package/dist/index.d.mts +6 -5
  28. package/dist/index.d.ts +6 -5
  29. package/dist/index.js +207 -126
  30. package/dist/index.mjs +4 -3
  31. package/dist/react.d.mts +707 -67
  32. package/dist/react.d.ts +707 -67
  33. package/dist/react.js +64 -16
  34. package/dist/react.mjs +2 -2
  35. package/dist/{transaction-signer-D3csM_Mf.d.ts → transaction-signer-D9d8nxwb.d.mts} +3 -1
  36. package/dist/{transaction-signer-D3csM_Mf.d.mts → transaction-signer-D9d8nxwb.d.ts} +3 -1
  37. package/dist/{wallet-standard-shim-Cg0GVGwu.d.mts → wallet-standard-shim-Cp4vF4oo.d.mts} +133 -6
  38. package/dist/{wallet-standard-shim-C1tisl9S.d.ts → wallet-standard-shim-DC_Z7DS-.d.ts} +133 -6
  39. package/package.json +16 -12
  40. package/dist/chunk-4K6QY4HR.mjs.map +0 -1
  41. package/dist/chunk-5ZUVZZWU.mjs +0 -180
  42. package/dist/chunk-5ZUVZZWU.mjs.map +0 -1
  43. package/dist/chunk-F2QJH5ED.mjs +0 -298
  44. package/dist/chunk-F2QJH5ED.mjs.map +0 -1
  45. package/dist/chunk-JS4KJ2KK.js.map +0 -1
  46. package/dist/chunk-RIBOPAOD.js.map +0 -1
  47. package/dist/chunk-SJEZHNYF.js +0 -314
  48. package/dist/chunk-SJEZHNYF.js.map +0 -1
  49. package/dist/chunk-SMUUAKC3.js +0 -186
  50. package/dist/chunk-SMUUAKC3.js.map +0 -1
  51. package/dist/chunk-WXYUUCSD.mjs.map +0 -1
@@ -1,8 +1,10 @@
1
- import { createLogger, __publicField, isWeb3jsTransaction, prepareTransactionForWallet, convertSignedTransaction } from './chunk-5ZUVZZWU.mjs';
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}` : ""}`, { 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}`, { expectedFormat, actualFormat }),
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: legacyResult.publicKey.toString(),
1094
- publicKey: legacyResult.publicKey.toBytes ? legacyResult.publicKey.toBytes() : new Uint8Array(),
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: directWallet.publicKey.toBytes ? directWallet.publicKey.toBytes() : new Uint8Array(),
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
- return publicKeyResult && typeof publicKeyResult.toString == "function" && publicKeyResult.toString().length > MIN_ADDRESS_LENGTH ? {
1115
- accounts: [
1116
- {
1117
- address: publicKeyResult.toString(),
1118
- publicKey: publicKeyResult.toBytes ? publicKeyResult.toBytes() : new Uint8Array(),
1119
- chains: ["solana:mainnet", "solana:devnet", "solana:testnet"],
1120
- features: []
1121
- }
1122
- ]
1123
- } : (this.debug && logger4.error("Legacy wallet: No valid publicKey found in any expected location"), { accounts: [] });
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
- return this.stateManager.updateState(
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
- ), this.debug && logger4.info("Attempting to connect via instant auto-connect", { walletName: storedWalletName }), await this.connectionManager.connect(wallet, storedWalletName), this.debug && logger4.info("Instant auto-connect successful", { walletName: storedWalletName }), setTimeout(() => {
1171
- let ws = getWalletsRegistry().get();
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 / LAMPORTS_PER_SOL).toFixed(decimals);
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) / LAMPORTS_PER_SOL).toFixed(decimals);
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("GillTransactionSigner");
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 createGillTransactionSigner(connectorSigner) {
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 signatureBytes = extractSignature(signedTxBytes), signatureBase58 = getSignatureFromBytes(signatureBytes);
2397
- return logger10.debug("Extracted signature from wallet (unmodified)", {
2420
+ let extractedSignatureBytes = extractSignature(signedTxBytes), signatureBase58 = getBase58Decoder().decode(extractedSignatureBytes);
2421
+ logger10.debug("Extracted signature from wallet (unmodified)", {
2398
2422
  signerAddress,
2399
- signatureLength: signatureBytes.length,
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]: signatureBytes
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-4K6QY4HR.mjs.map
2419
- //# sourceMappingURL=chunk-4K6QY4HR.mjs.map
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