@solana/connector 0.0.0 → 0.1.1
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-5ZUVZZWU.mjs +180 -0
- package/dist/chunk-5ZUVZZWU.mjs.map +1 -0
- package/dist/chunk-6PBQ5CXV.mjs +635 -0
- package/dist/chunk-6PBQ5CXV.mjs.map +1 -0
- package/dist/chunk-D4JGBIP7.js +314 -0
- package/dist/chunk-D4JGBIP7.js.map +1 -0
- package/dist/chunk-EGYXJT54.mjs +298 -0
- package/dist/chunk-EGYXJT54.mjs.map +1 -0
- package/dist/chunk-P4ZLJI4L.js +706 -0
- package/dist/chunk-P4ZLJI4L.js.map +1 -0
- package/dist/chunk-P5A3XNFF.js +2482 -0
- package/dist/chunk-P5A3XNFF.js.map +1 -0
- package/dist/chunk-SMUUAKC3.js +186 -0
- package/dist/chunk-SMUUAKC3.js.map +1 -0
- package/dist/chunk-TAAXHAV2.mjs +2419 -0
- package/dist/chunk-TAAXHAV2.mjs.map +1 -0
- package/dist/compat.d.mts +47 -0
- package/dist/compat.d.ts +47 -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 +515 -0
- package/dist/headless.d.ts +515 -0
- package/dist/headless.js +445 -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 +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +502 -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 +496 -0
- package/dist/react.d.ts +496 -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-D3csM_Mf.d.mts +199 -0
- package/dist/transaction-signer-D3csM_Mf.d.ts +199 -0
- package/dist/wallet-standard-shim-C1tisl9S.d.ts +926 -0
- package/dist/wallet-standard-shim-Cg0GVGwu.d.mts +926 -0
- package/package.json +93 -10
- package/index.js +0 -1
|
@@ -0,0 +1,706 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkP5A3XNFF_js = require('./chunk-P5A3XNFF.js');
|
|
4
|
+
var chunkSMUUAKC3_js = require('./chunk-SMUUAKC3.js');
|
|
5
|
+
var core = require('@wallet-ui/core');
|
|
6
|
+
var gill = require('gill');
|
|
7
|
+
var bs58 = require('bs58');
|
|
8
|
+
var addresses = require('@solana/addresses');
|
|
9
|
+
var signers = require('@solana/signers');
|
|
10
|
+
|
|
11
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
|
|
13
|
+
var bs58__default = /*#__PURE__*/_interopDefault(bs58);
|
|
14
|
+
|
|
15
|
+
var logger = chunkSMUUAKC3_js.createLogger("EnhancedStorage"), STORAGE_VERSION = "v1", EnhancedStorage = class extends core.Storage {
|
|
16
|
+
constructor(key, initial, options) {
|
|
17
|
+
super(key, initial);
|
|
18
|
+
this.options = options;
|
|
19
|
+
chunkSMUUAKC3_js.__publicField(this, "errorHandlers", /* @__PURE__ */ new Set());
|
|
20
|
+
chunkSMUUAKC3_js.__publicField(this, "validators", []);
|
|
21
|
+
chunkSMUUAKC3_js.__publicField(this, "memoryFallback");
|
|
22
|
+
this.memoryFallback = initial, options?.onError && this.errorHandlers.add(options.onError), options?.validator && this.validators.push(options.validator);
|
|
23
|
+
}
|
|
24
|
+
set(value) {
|
|
25
|
+
try {
|
|
26
|
+
return this.validate(value) ? (super.set(value), this.memoryFallback = value, true) : (logger.warn("Validation failed", { key: this.key }), false);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
return this.handleError(error), this.options?.useMemoryFallback ? (this.memoryFallback = value, true) : false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
get() {
|
|
32
|
+
try {
|
|
33
|
+
return super.get();
|
|
34
|
+
} catch (error) {
|
|
35
|
+
return this.handleError(error), this.options?.useMemoryFallback ? this.memoryFallback : this.initial;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
validate(value) {
|
|
39
|
+
return this.validators.every((validator) => validator(value));
|
|
40
|
+
}
|
|
41
|
+
addValidator(validator) {
|
|
42
|
+
return this.validators.push(validator), this;
|
|
43
|
+
}
|
|
44
|
+
onError(handler) {
|
|
45
|
+
return this.errorHandlers.add(handler), this;
|
|
46
|
+
}
|
|
47
|
+
transform(transformer) {
|
|
48
|
+
return transformer(this.get());
|
|
49
|
+
}
|
|
50
|
+
reset() {
|
|
51
|
+
this.set(this.initial);
|
|
52
|
+
}
|
|
53
|
+
clear() {
|
|
54
|
+
try {
|
|
55
|
+
typeof window < "u" && window.localStorage && window.localStorage.removeItem(this.key), this.reset();
|
|
56
|
+
} catch (error) {
|
|
57
|
+
this.handleError(error);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
isAvailable() {
|
|
61
|
+
try {
|
|
62
|
+
if (typeof window > "u") return false;
|
|
63
|
+
let testKey = `__storage_test_${this.key}__`;
|
|
64
|
+
return window.localStorage.setItem(testKey, "test"), window.localStorage.removeItem(testKey), true;
|
|
65
|
+
} catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
static migrate(oldKey, newStorage) {
|
|
70
|
+
try {
|
|
71
|
+
if (typeof window > "u") return false;
|
|
72
|
+
let oldValue = window.localStorage.getItem(oldKey);
|
|
73
|
+
if (oldValue) {
|
|
74
|
+
let parsed = JSON.parse(oldValue);
|
|
75
|
+
return newStorage.set(parsed), window.localStorage.removeItem(oldKey), true;
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
} catch {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
handleError(error) {
|
|
83
|
+
logger.error("Storage error", { key: this.key, error }), this.errorHandlers.forEach((handler) => {
|
|
84
|
+
try {
|
|
85
|
+
handler(error);
|
|
86
|
+
} catch (err) {
|
|
87
|
+
logger.error("Error in error handler", { error: err });
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
function createEnhancedStorageAccount(options) {
|
|
93
|
+
let key = options?.key ?? `connector-kit:${STORAGE_VERSION}:account`;
|
|
94
|
+
return new EnhancedStorage(key, options?.initial, {
|
|
95
|
+
validator: options?.validator,
|
|
96
|
+
onError: options?.onError,
|
|
97
|
+
useMemoryFallback: true
|
|
98
|
+
// Always fallback for SSR
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function createEnhancedStorageCluster(options) {
|
|
102
|
+
let key = options?.key ?? `connector-kit:${STORAGE_VERSION}:cluster`, storage = new EnhancedStorage(key, options?.initial ?? "solana:mainnet", {
|
|
103
|
+
onError: options?.onError,
|
|
104
|
+
useMemoryFallback: true
|
|
105
|
+
});
|
|
106
|
+
return options?.validClusters && storage.addValidator((clusterId) => options.validClusters.includes(clusterId)), storage;
|
|
107
|
+
}
|
|
108
|
+
function createEnhancedStorageWallet(options) {
|
|
109
|
+
let key = options?.key ?? `connector-kit:${STORAGE_VERSION}:wallet`;
|
|
110
|
+
return new EnhancedStorage(key, options?.initial, {
|
|
111
|
+
onError: options?.onError,
|
|
112
|
+
useMemoryFallback: true
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
var EnhancedStorageAdapter = class {
|
|
116
|
+
constructor(storage) {
|
|
117
|
+
this.storage = storage;
|
|
118
|
+
}
|
|
119
|
+
get() {
|
|
120
|
+
return this.storage.get();
|
|
121
|
+
}
|
|
122
|
+
set(value) {
|
|
123
|
+
this.storage.set(value);
|
|
124
|
+
}
|
|
125
|
+
subscribe(callback) {
|
|
126
|
+
return this.storage.value.subscribe(callback);
|
|
127
|
+
}
|
|
128
|
+
validate(value) {
|
|
129
|
+
return this.storage.validate(value);
|
|
130
|
+
}
|
|
131
|
+
reset() {
|
|
132
|
+
this.storage.reset();
|
|
133
|
+
}
|
|
134
|
+
clear() {
|
|
135
|
+
this.storage.clear();
|
|
136
|
+
}
|
|
137
|
+
isAvailable() {
|
|
138
|
+
return this.storage.isAvailable();
|
|
139
|
+
}
|
|
140
|
+
transform(transformer) {
|
|
141
|
+
return this.storage.transform(transformer);
|
|
142
|
+
}
|
|
143
|
+
addValidator(validator) {
|
|
144
|
+
return this.storage.addValidator(validator), this;
|
|
145
|
+
}
|
|
146
|
+
onError(handler) {
|
|
147
|
+
return this.storage.onError(handler), this;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
var logger2 = chunkSMUUAKC3_js.createLogger("DefaultConfig");
|
|
151
|
+
function getDefaultConfig(options) {
|
|
152
|
+
let {
|
|
153
|
+
appName,
|
|
154
|
+
appUrl,
|
|
155
|
+
autoConnect = true,
|
|
156
|
+
debug,
|
|
157
|
+
network = "mainnet-beta",
|
|
158
|
+
enableMobile = true,
|
|
159
|
+
storage,
|
|
160
|
+
clusters,
|
|
161
|
+
customClusters = [],
|
|
162
|
+
persistClusterSelection = true,
|
|
163
|
+
clusterStorageKey,
|
|
164
|
+
enableErrorBoundary = true,
|
|
165
|
+
maxRetries = chunkP5A3XNFF_js.DEFAULT_MAX_RETRIES,
|
|
166
|
+
onError
|
|
167
|
+
} = options, defaultClusters = clusters ?? [
|
|
168
|
+
core.createSolanaMainnet(),
|
|
169
|
+
core.createSolanaDevnet(),
|
|
170
|
+
core.createSolanaTestnet(),
|
|
171
|
+
...network === "localnet" ? [core.createSolanaLocalnet()] : [],
|
|
172
|
+
...customClusters || []
|
|
173
|
+
], validClusterIds = defaultClusters.map((c) => c.id), accountStorage = createEnhancedStorageAccount({
|
|
174
|
+
validator: (address3) => address3 ? gill.isAddress(address3) : true,
|
|
175
|
+
onError: (error) => {
|
|
176
|
+
debug && logger2.error("Account Storage error", { error }), onError && onError(error, {
|
|
177
|
+
componentStack: "account-storage"
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}), clusterStorage = createEnhancedStorageCluster({
|
|
181
|
+
key: clusterStorageKey,
|
|
182
|
+
initial: getInitialCluster(network),
|
|
183
|
+
validClusters: persistClusterSelection ? validClusterIds : void 0,
|
|
184
|
+
onError: (error) => {
|
|
185
|
+
debug && logger2.error("Cluster Storage error", { error }), onError && onError(error, {
|
|
186
|
+
componentStack: "cluster-storage"
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}), walletStorage = createEnhancedStorageWallet({
|
|
190
|
+
onError: (error) => {
|
|
191
|
+
debug && logger2.error("Wallet Storage error", { error }), onError && onError(error, {
|
|
192
|
+
componentStack: "wallet-storage"
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
if (typeof window < "u") {
|
|
197
|
+
let oldAccountKey = "connector-kit:account", oldWalletKey = "connector-kit:wallet", oldClusterKey = clusterStorageKey || "connector-kit:cluster";
|
|
198
|
+
EnhancedStorage.migrate(oldAccountKey, accountStorage), EnhancedStorage.migrate(oldWalletKey, walletStorage), EnhancedStorage.migrate(oldClusterKey, clusterStorage);
|
|
199
|
+
}
|
|
200
|
+
let defaultStorage = storage ?? {
|
|
201
|
+
account: new EnhancedStorageAdapter(accountStorage),
|
|
202
|
+
cluster: new EnhancedStorageAdapter(clusterStorage),
|
|
203
|
+
wallet: new EnhancedStorageAdapter(walletStorage)
|
|
204
|
+
};
|
|
205
|
+
return {
|
|
206
|
+
autoConnect,
|
|
207
|
+
debug: debug ?? process.env.NODE_ENV === "development",
|
|
208
|
+
storage: defaultStorage,
|
|
209
|
+
appName,
|
|
210
|
+
appUrl,
|
|
211
|
+
enableMobile,
|
|
212
|
+
network,
|
|
213
|
+
cluster: {
|
|
214
|
+
clusters: defaultClusters,
|
|
215
|
+
persistSelection: persistClusterSelection,
|
|
216
|
+
initialCluster: getInitialCluster(network)
|
|
217
|
+
},
|
|
218
|
+
errorBoundary: {
|
|
219
|
+
enabled: enableErrorBoundary,
|
|
220
|
+
maxRetries,
|
|
221
|
+
onError
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
function getInitialCluster(network = "mainnet-beta") {
|
|
226
|
+
return chunkP5A3XNFF_js.toClusterId(network);
|
|
227
|
+
}
|
|
228
|
+
function getDefaultMobileConfig(options) {
|
|
229
|
+
let baseUrl = options.appUrl || (typeof window < "u" ? window.location.origin : "https://localhost:3000");
|
|
230
|
+
return {
|
|
231
|
+
appIdentity: {
|
|
232
|
+
name: options.appName,
|
|
233
|
+
uri: baseUrl,
|
|
234
|
+
icon: `${baseUrl}/favicon.ico`
|
|
235
|
+
},
|
|
236
|
+
cluster: options.network || "mainnet-beta"
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// src/config/unified-config.ts
|
|
241
|
+
function createConfig(options) {
|
|
242
|
+
let { network = "mainnet-beta", rpcUrl: customRpcUrl, ...connectorOptions } = options, normalizedNetwork = chunkP5A3XNFF_js.normalizeNetwork(typeof network == "string" ? network : "mainnet-beta"), rpcUrl = customRpcUrl || chunkP5A3XNFF_js.getDefaultRpcUrl(normalizedNetwork), rpcNetwork = normalizedNetwork === "mainnet" ? "mainnet-beta" : normalizedNetwork, connectorConfig = getDefaultConfig({
|
|
243
|
+
...connectorOptions,
|
|
244
|
+
network: rpcNetwork
|
|
245
|
+
}), mobile = options.enableMobile !== false && normalizedNetwork !== "localnet" ? getDefaultMobileConfig({
|
|
246
|
+
appName: options.appName,
|
|
247
|
+
appUrl: connectorConfig.appUrl,
|
|
248
|
+
network: rpcNetwork
|
|
249
|
+
}) : void 0;
|
|
250
|
+
return {
|
|
251
|
+
connectorConfig,
|
|
252
|
+
mobile,
|
|
253
|
+
network: normalizedNetwork,
|
|
254
|
+
rpcUrl,
|
|
255
|
+
app: {
|
|
256
|
+
name: options.appName,
|
|
257
|
+
url: connectorConfig.appUrl || (typeof window < "u" ? window.location.origin : "https://localhost:3000")
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
function isUnifiedConfig(config) {
|
|
262
|
+
return !!(config && typeof config == "object" && "connectorConfig" in config && "network" in config && "rpcUrl" in config && "app" in config);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// src/types/wallets.ts
|
|
266
|
+
function isWalletName(value) {
|
|
267
|
+
return typeof value == "string" && value.length > 0;
|
|
268
|
+
}
|
|
269
|
+
function isAccountAddress(value) {
|
|
270
|
+
return typeof value == "string" && value.length >= 32 && value.length <= 44;
|
|
271
|
+
}
|
|
272
|
+
function detectMessageModification(original, modified) {
|
|
273
|
+
if (original.length !== modified.length)
|
|
274
|
+
return true;
|
|
275
|
+
for (let i = 0; i < original.length; i++)
|
|
276
|
+
if (original[i] !== modified[i])
|
|
277
|
+
return true;
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
function updateSignatureDictionary(original, signed, originalSignatures, address3, signature) {
|
|
281
|
+
let wasModified = detectMessageModification(original, signed), signatureBytes = signature, newSignatures = {};
|
|
282
|
+
return newSignatures[address3] = signatureBytes, wasModified ? newSignatures : {
|
|
283
|
+
...originalSignatures,
|
|
284
|
+
...newSignatures
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
function freezeSigner(signer) {
|
|
288
|
+
return Object.freeze(signer);
|
|
289
|
+
}
|
|
290
|
+
function base58ToSignatureBytes(signature) {
|
|
291
|
+
try {
|
|
292
|
+
let bytes = bs58__default.default.decode(signature);
|
|
293
|
+
if (bytes.length !== 64)
|
|
294
|
+
throw new Error(`Invalid signature length: expected 64 bytes, got ${bytes.length}`);
|
|
295
|
+
return new Uint8Array(bytes);
|
|
296
|
+
} catch (error) {
|
|
297
|
+
throw new Error(`Failed to decode base58 signature: ${error instanceof Error ? error.message : String(error)}`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function signatureBytesToBase58(bytes) {
|
|
301
|
+
try {
|
|
302
|
+
if (bytes.length !== 64)
|
|
303
|
+
throw new Error(`Invalid signature length: expected 64 bytes, got ${bytes.length}`);
|
|
304
|
+
return bs58__default.default.encode(bytes);
|
|
305
|
+
} catch (error) {
|
|
306
|
+
throw new Error(`Failed to encode signature to base58: ${error instanceof Error ? error.message : String(error)}`);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// src/lib/kit-signers/factories.ts
|
|
311
|
+
function createMessageSignerFromWallet(walletAddress, signMessageFn) {
|
|
312
|
+
return freezeSigner({
|
|
313
|
+
address: walletAddress,
|
|
314
|
+
async modifyAndSignMessages(messages, config) {
|
|
315
|
+
if (messages.length !== 1)
|
|
316
|
+
throw new chunkP5A3XNFF_js.ValidationError("INVALID_FORMAT", "Wallets only support signing one message at a time", {
|
|
317
|
+
receivedCount: messages.length,
|
|
318
|
+
expectedCount: 1
|
|
319
|
+
});
|
|
320
|
+
let [message] = messages, { content, signatures: originalSignatures } = message;
|
|
321
|
+
if (config?.abortSignal?.aborted)
|
|
322
|
+
throw chunkP5A3XNFF_js.Errors.userRejected("message signing");
|
|
323
|
+
try {
|
|
324
|
+
let signature = await signMessageFn(content);
|
|
325
|
+
console.log("Signature received from wallet:", {
|
|
326
|
+
signatureLength: signature?.length,
|
|
327
|
+
signatureType: signature?.constructor?.name,
|
|
328
|
+
walletAddress
|
|
329
|
+
});
|
|
330
|
+
let signatures = updateSignatureDictionary(
|
|
331
|
+
content,
|
|
332
|
+
content,
|
|
333
|
+
// Message content doesn't change in signMessage
|
|
334
|
+
originalSignatures,
|
|
335
|
+
walletAddress,
|
|
336
|
+
signature
|
|
337
|
+
);
|
|
338
|
+
return console.log("Signatures after update:", {
|
|
339
|
+
signaturesKeys: Object.keys(signatures),
|
|
340
|
+
signaturesValues: Object.values(signatures).map((s) => ({ length: s?.length, type: s?.constructor?.name }))
|
|
341
|
+
}), [
|
|
342
|
+
{
|
|
343
|
+
content,
|
|
344
|
+
signatures
|
|
345
|
+
}
|
|
346
|
+
];
|
|
347
|
+
} catch (error) {
|
|
348
|
+
if (error instanceof Error) {
|
|
349
|
+
let message2 = error.message.toLowerCase();
|
|
350
|
+
throw message2.includes("user rejected") || message2.includes("user denied") ? chunkP5A3XNFF_js.Errors.userRejected("message signing") : new chunkP5A3XNFF_js.TransactionError("SIGNING_FAILED", "Failed to sign message", void 0, error);
|
|
351
|
+
}
|
|
352
|
+
throw new chunkP5A3XNFF_js.TransactionError("SIGNING_FAILED", "Failed to sign message", {
|
|
353
|
+
originalError: String(error)
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
function createTransactionSendingSignerFromWallet(walletAddress, chain, sendTransactionFn) {
|
|
360
|
+
return freezeSigner({
|
|
361
|
+
address: walletAddress,
|
|
362
|
+
async signAndSendTransactions(transactions, config) {
|
|
363
|
+
if (transactions.length !== 1)
|
|
364
|
+
throw new chunkP5A3XNFF_js.ValidationError("INVALID_FORMAT", "Wallets only support sending one transaction at a time", {
|
|
365
|
+
receivedCount: transactions.length,
|
|
366
|
+
expectedCount: 1
|
|
367
|
+
});
|
|
368
|
+
let [transaction] = transactions;
|
|
369
|
+
if (config?.abortSignal?.aborted)
|
|
370
|
+
throw chunkP5A3XNFF_js.Errors.userRejected("transaction sending");
|
|
371
|
+
try {
|
|
372
|
+
let signatureString = await sendTransactionFn(transaction);
|
|
373
|
+
return [base58ToSignatureBytes(signatureString)];
|
|
374
|
+
} catch (error) {
|
|
375
|
+
if (error instanceof Error) {
|
|
376
|
+
let message = error.message.toLowerCase();
|
|
377
|
+
throw message.includes("user rejected") || message.includes("user denied") ? chunkP5A3XNFF_js.Errors.userRejected("transaction sending") : message.includes("network") || message.includes("rpc") ? new chunkP5A3XNFF_js.TransactionError("SEND_FAILED", "Failed to send transaction", void 0, error) : new chunkP5A3XNFF_js.TransactionError("SEND_FAILED", "Failed to send transaction", void 0, error);
|
|
378
|
+
}
|
|
379
|
+
throw new chunkP5A3XNFF_js.TransactionError("SEND_FAILED", "Failed to send transaction", {
|
|
380
|
+
originalError: String(error)
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
function createKitSignersFromWallet(wallet, account, connection, network) {
|
|
387
|
+
if (!wallet || !account)
|
|
388
|
+
return {
|
|
389
|
+
address: null,
|
|
390
|
+
addressString: null,
|
|
391
|
+
messageSigner: null,
|
|
392
|
+
transactionSigner: null
|
|
393
|
+
};
|
|
394
|
+
let walletAddress = null, walletAddressString = null;
|
|
395
|
+
try {
|
|
396
|
+
walletAddress = addresses.address(account.address), walletAddressString = account.address;
|
|
397
|
+
} catch {
|
|
398
|
+
return {
|
|
399
|
+
address: null,
|
|
400
|
+
addressString: null,
|
|
401
|
+
messageSigner: null,
|
|
402
|
+
transactionSigner: null
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
let chain = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
|
|
406
|
+
if (network)
|
|
407
|
+
chain = {
|
|
408
|
+
mainnet: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
|
|
409
|
+
devnet: "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
|
|
410
|
+
testnet: "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z"
|
|
411
|
+
}[network] || chain;
|
|
412
|
+
else if (connection) {
|
|
413
|
+
let rpcUrl = connection.rpcEndpoint || "";
|
|
414
|
+
rpcUrl.includes("mainnet") || rpcUrl.includes("api.mainnet-beta") ? chain = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp" : rpcUrl.includes("testnet") ? chain = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z" : chain = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
|
|
415
|
+
}
|
|
416
|
+
let features = wallet.features, hasSignMessage = !!features["solana:signMessage"], hasSignAndSendTransaction = !!features["solana:signAndSendTransaction"], hasSendTransaction = !!features["solana:sendTransaction"], messageSigner = hasSignMessage ? createMessageSignerFromWallet(
|
|
417
|
+
walletAddress,
|
|
418
|
+
async (message) => {
|
|
419
|
+
if (!hasSignMessage)
|
|
420
|
+
throw chunkP5A3XNFF_js.Errors.featureNotSupported("message signing");
|
|
421
|
+
try {
|
|
422
|
+
let results = await features["solana:signMessage"].signMessage({
|
|
423
|
+
account,
|
|
424
|
+
message,
|
|
425
|
+
...chain ? { chain } : {}
|
|
426
|
+
});
|
|
427
|
+
if (console.log("Wallet signMessage result:", {
|
|
428
|
+
isArray: Array.isArray(results),
|
|
429
|
+
length: results?.length,
|
|
430
|
+
firstResult: results?.[0],
|
|
431
|
+
firstSignature: results?.[0]?.signature
|
|
432
|
+
}), !Array.isArray(results) || results.length === 0)
|
|
433
|
+
throw new Error("Wallet returned empty results array");
|
|
434
|
+
let firstResult = results[0];
|
|
435
|
+
if (!firstResult?.signature)
|
|
436
|
+
throw new Error("Wallet returned no signature in first result");
|
|
437
|
+
return firstResult.signature;
|
|
438
|
+
} catch (error) {
|
|
439
|
+
throw console.error("signMessage error:", error), error instanceof Error ? error : new Error(String(error));
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
) : null, transactionSigner = hasSignAndSendTransaction || hasSendTransaction ? createTransactionSendingSignerFromWallet(
|
|
443
|
+
walletAddress,
|
|
444
|
+
chain,
|
|
445
|
+
async (transaction) => {
|
|
446
|
+
if (hasSignAndSendTransaction)
|
|
447
|
+
try {
|
|
448
|
+
return (await features["solana:signAndSendTransaction"].signAndSendTransaction({
|
|
449
|
+
account,
|
|
450
|
+
transactions: [transaction],
|
|
451
|
+
...chain ? { chain } : {},
|
|
452
|
+
...connection ? { chain } : {}
|
|
453
|
+
})).signatures[0] || "";
|
|
454
|
+
} catch (error) {
|
|
455
|
+
throw error instanceof Error ? error : new Error(String(error));
|
|
456
|
+
}
|
|
457
|
+
if (hasSendTransaction)
|
|
458
|
+
try {
|
|
459
|
+
return (await features["solana:sendTransaction"].sendTransaction({
|
|
460
|
+
account,
|
|
461
|
+
transactions: [transaction],
|
|
462
|
+
...chain ? { chain } : {}
|
|
463
|
+
})).signatures[0] || "";
|
|
464
|
+
} catch (error) {
|
|
465
|
+
throw error instanceof Error ? error : new Error(String(error));
|
|
466
|
+
}
|
|
467
|
+
throw chunkP5A3XNFF_js.Errors.featureNotSupported("transaction sending");
|
|
468
|
+
}
|
|
469
|
+
) : null;
|
|
470
|
+
return {
|
|
471
|
+
address: walletAddress,
|
|
472
|
+
addressString: walletAddressString,
|
|
473
|
+
messageSigner,
|
|
474
|
+
transactionSigner
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// src/lib/connection/types.ts
|
|
479
|
+
function isLegacyConnection(conn) {
|
|
480
|
+
return "rpcEndpoint" in conn && typeof conn.rpcEndpoint == "string";
|
|
481
|
+
}
|
|
482
|
+
function isKitConnection(conn) {
|
|
483
|
+
if ("rpcEndpoint" in conn)
|
|
484
|
+
return false;
|
|
485
|
+
let asKitRpc = conn;
|
|
486
|
+
return typeof asKitRpc.getLatestBlockhash == "function" && typeof asKitRpc.sendTransaction == "function";
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// src/lib/connection/helpers.ts
|
|
490
|
+
async function getLatestBlockhash(connection, commitment = "confirmed") {
|
|
491
|
+
if (isLegacyConnection(connection))
|
|
492
|
+
return await connection.getLatestBlockhash(commitment);
|
|
493
|
+
if (isKitConnection(connection))
|
|
494
|
+
return (await connection.getLatestBlockhash({ commitment }).send()).value;
|
|
495
|
+
throw new Error("Unsupported connection type");
|
|
496
|
+
}
|
|
497
|
+
async function sendRawTransaction(connection, bytes, options) {
|
|
498
|
+
if (isLegacyConnection(connection))
|
|
499
|
+
return await connection.sendRawTransaction(bytes, options);
|
|
500
|
+
if (isKitConnection(connection)) {
|
|
501
|
+
let rpc = connection, base64String = Buffer.from(bytes).toString("base64");
|
|
502
|
+
return await rpc.sendTransaction(base64String, {
|
|
503
|
+
...options?.commitment ? { commitment: options.commitment } : {},
|
|
504
|
+
...options?.skipPreflight !== void 0 ? { skipPreflight: options.skipPreflight } : {},
|
|
505
|
+
...options?.maxRetries !== void 0 ? { maxRetries: options.maxRetries } : {}
|
|
506
|
+
}).send();
|
|
507
|
+
}
|
|
508
|
+
throw new Error("Unsupported connection type");
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// src/utils/chain.ts
|
|
512
|
+
var SOLANA_CHAIN_IDS = {
|
|
513
|
+
mainnet: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
|
|
514
|
+
devnet: "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
|
|
515
|
+
testnet: "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z"
|
|
516
|
+
}, CHAIN_ID_TO_CLUSTER_TYPE = {
|
|
517
|
+
[SOLANA_CHAIN_IDS.mainnet]: "mainnet",
|
|
518
|
+
[SOLANA_CHAIN_IDS.devnet]: "devnet",
|
|
519
|
+
[SOLANA_CHAIN_IDS.testnet]: "testnet"
|
|
520
|
+
}, CLUSTER_ID_TO_CHAIN_ID = {
|
|
521
|
+
"solana:mainnet": SOLANA_CHAIN_IDS.mainnet,
|
|
522
|
+
"solana:mainnet-beta": SOLANA_CHAIN_IDS.mainnet,
|
|
523
|
+
"solana:devnet": SOLANA_CHAIN_IDS.devnet,
|
|
524
|
+
"solana:testnet": SOLANA_CHAIN_IDS.testnet
|
|
525
|
+
};
|
|
526
|
+
function getChainIdFromCluster(cluster) {
|
|
527
|
+
let clusterType = chunkP5A3XNFF_js.getClusterType(cluster);
|
|
528
|
+
return clusterType === "localnet" || clusterType === "custom" ? null : getChainIdFromClusterType(clusterType);
|
|
529
|
+
}
|
|
530
|
+
function getChainIdFromClusterId(clusterId) {
|
|
531
|
+
return CLUSTER_ID_TO_CHAIN_ID[clusterId] || null;
|
|
532
|
+
}
|
|
533
|
+
function getChainIdFromClusterType(type) {
|
|
534
|
+
switch (type) {
|
|
535
|
+
case "mainnet":
|
|
536
|
+
return SOLANA_CHAIN_IDS.mainnet;
|
|
537
|
+
case "devnet":
|
|
538
|
+
return SOLANA_CHAIN_IDS.devnet;
|
|
539
|
+
case "testnet":
|
|
540
|
+
return SOLANA_CHAIN_IDS.testnet;
|
|
541
|
+
case "localnet":
|
|
542
|
+
case "custom":
|
|
543
|
+
return null;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
function getClusterTypeFromChainId(chainId) {
|
|
547
|
+
return CHAIN_ID_TO_CLUSTER_TYPE[chainId] || null;
|
|
548
|
+
}
|
|
549
|
+
function getClusterIdFromChainId(chainId) {
|
|
550
|
+
let clusterType = getClusterTypeFromChainId(chainId);
|
|
551
|
+
if (!clusterType)
|
|
552
|
+
return null;
|
|
553
|
+
switch (clusterType) {
|
|
554
|
+
case "mainnet":
|
|
555
|
+
return "solana:mainnet";
|
|
556
|
+
case "devnet":
|
|
557
|
+
return "solana:devnet";
|
|
558
|
+
case "testnet":
|
|
559
|
+
return "solana:testnet";
|
|
560
|
+
default:
|
|
561
|
+
return null;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
function isSolanaChain(chain) {
|
|
565
|
+
return chain.startsWith("solana:");
|
|
566
|
+
}
|
|
567
|
+
function isKnownSolanaChain(chain) {
|
|
568
|
+
return chain === SOLANA_CHAIN_IDS.mainnet || chain === SOLANA_CHAIN_IDS.devnet || chain === SOLANA_CHAIN_IDS.testnet;
|
|
569
|
+
}
|
|
570
|
+
function validateKnownSolanaChain(chain) {
|
|
571
|
+
if (!isSolanaChain(chain))
|
|
572
|
+
throw new Error(`Invalid chain format: expected 'solana:...', got '${chain}'`);
|
|
573
|
+
if (!isKnownSolanaChain(chain))
|
|
574
|
+
throw new Error(`Unknown Solana chain: ${chain}. Known chains: ${Object.values(SOLANA_CHAIN_IDS).join(", ")}`);
|
|
575
|
+
}
|
|
576
|
+
function getClusterTypeFromConnection(connection) {
|
|
577
|
+
if (!connection)
|
|
578
|
+
return null;
|
|
579
|
+
let rpcUrl = connection.rpcEndpoint || "";
|
|
580
|
+
return rpcUrl.includes("mainnet") || rpcUrl.includes("api.mainnet-beta") ? "mainnet" : rpcUrl.includes("testnet") ? "testnet" : rpcUrl.includes("devnet") ? "devnet" : rpcUrl.includes("localhost") || rpcUrl.includes("127.0.0.1") ? "localnet" : "custom";
|
|
581
|
+
}
|
|
582
|
+
function getChainIdFromConnection(connection, network) {
|
|
583
|
+
if (network)
|
|
584
|
+
return getChainIdFromClusterType(network);
|
|
585
|
+
let clusterType = getClusterTypeFromConnection(connection);
|
|
586
|
+
return clusterType ? getChainIdFromClusterType(clusterType) : null;
|
|
587
|
+
}
|
|
588
|
+
function clusterToChainId(cluster) {
|
|
589
|
+
return getChainIdFromCluster(cluster);
|
|
590
|
+
}
|
|
591
|
+
function chainIdToClusterType(chainId) {
|
|
592
|
+
return getClusterTypeFromChainId(chainId);
|
|
593
|
+
}
|
|
594
|
+
function chainIdToClusterId(chainId) {
|
|
595
|
+
return getClusterIdFromChainId(chainId);
|
|
596
|
+
}
|
|
597
|
+
function getSolanaExplorerUrl(signature, options = {}) {
|
|
598
|
+
let { cluster = "mainnet", customUrl } = options, normalizedCluster = cluster === "mainnet-beta" ? "mainnet" : cluster;
|
|
599
|
+
if (normalizedCluster === "localnet")
|
|
600
|
+
return `https://explorer.solana.com/tx/${signature}?cluster=custom&customUrl=${encodeURIComponent(customUrl || "http://localhost:8899")}`;
|
|
601
|
+
let explorerCluster = ["mainnet", "devnet", "testnet"].includes(normalizedCluster) ? normalizedCluster : "devnet";
|
|
602
|
+
return gill.getExplorerLink({
|
|
603
|
+
transaction: signature,
|
|
604
|
+
cluster: explorerCluster
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
function getSolscanUrl(signature, options = {}) {
|
|
608
|
+
let { cluster = "mainnet" } = options, normalizedCluster = cluster === "mainnet-beta" ? "mainnet" : cluster;
|
|
609
|
+
return normalizedCluster === "mainnet" ? `https://solscan.io/tx/${signature}` : normalizedCluster === "localnet" ? `https://solscan.io/tx/${signature}?cluster=custom` : `https://solscan.io/tx/${signature}?cluster=${normalizedCluster}`;
|
|
610
|
+
}
|
|
611
|
+
function getXrayUrl(signature) {
|
|
612
|
+
return `https://xray.helius.xyz/tx/${signature}`;
|
|
613
|
+
}
|
|
614
|
+
function getSolanaFmUrl(signature, options = {}) {
|
|
615
|
+
let { cluster = "mainnet" } = options, normalizedCluster = cluster === "mainnet-beta" ? "mainnet" : cluster;
|
|
616
|
+
return normalizedCluster === "mainnet" ? `https://solana.fm/tx/${signature}` : `https://solana.fm/tx/${signature}?cluster=${normalizedCluster}`;
|
|
617
|
+
}
|
|
618
|
+
function getAllExplorerUrls(signature, options = {}) {
|
|
619
|
+
return {
|
|
620
|
+
"solana-explorer": getSolanaExplorerUrl(signature, options),
|
|
621
|
+
solscan: getSolscanUrl(signature, options),
|
|
622
|
+
xray: getXrayUrl(signature),
|
|
623
|
+
"solana-fm": getSolanaFmUrl(signature, options)
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
function formatSignature(signature, chars = 8) {
|
|
627
|
+
return signature.length <= chars * 2 ? signature : `${signature.slice(0, chars)}...${signature.slice(-chars)}`;
|
|
628
|
+
}
|
|
629
|
+
async function copySignature(signature) {
|
|
630
|
+
try {
|
|
631
|
+
return await navigator.clipboard.writeText(signature), true;
|
|
632
|
+
} catch {
|
|
633
|
+
return false;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
Object.defineProperty(exports, "createSolanaDevnet", {
|
|
638
|
+
enumerable: true,
|
|
639
|
+
get: function () { return core.createSolanaDevnet; }
|
|
640
|
+
});
|
|
641
|
+
Object.defineProperty(exports, "createSolanaLocalnet", {
|
|
642
|
+
enumerable: true,
|
|
643
|
+
get: function () { return core.createSolanaLocalnet; }
|
|
644
|
+
});
|
|
645
|
+
Object.defineProperty(exports, "createSolanaMainnet", {
|
|
646
|
+
enumerable: true,
|
|
647
|
+
get: function () { return core.createSolanaMainnet; }
|
|
648
|
+
});
|
|
649
|
+
Object.defineProperty(exports, "createSolanaTestnet", {
|
|
650
|
+
enumerable: true,
|
|
651
|
+
get: function () { return core.createSolanaTestnet; }
|
|
652
|
+
});
|
|
653
|
+
Object.defineProperty(exports, "address", {
|
|
654
|
+
enumerable: true,
|
|
655
|
+
get: function () { return addresses.address; }
|
|
656
|
+
});
|
|
657
|
+
Object.defineProperty(exports, "createSignableMessage", {
|
|
658
|
+
enumerable: true,
|
|
659
|
+
get: function () { return signers.createSignableMessage; }
|
|
660
|
+
});
|
|
661
|
+
exports.EnhancedStorage = EnhancedStorage;
|
|
662
|
+
exports.EnhancedStorageAdapter = EnhancedStorageAdapter;
|
|
663
|
+
exports.SOLANA_CHAIN_IDS = SOLANA_CHAIN_IDS;
|
|
664
|
+
exports.base58ToSignatureBytes = base58ToSignatureBytes;
|
|
665
|
+
exports.chainIdToClusterId = chainIdToClusterId;
|
|
666
|
+
exports.chainIdToClusterType = chainIdToClusterType;
|
|
667
|
+
exports.clusterToChainId = clusterToChainId;
|
|
668
|
+
exports.copySignature = copySignature;
|
|
669
|
+
exports.createConfig = createConfig;
|
|
670
|
+
exports.createEnhancedStorageAccount = createEnhancedStorageAccount;
|
|
671
|
+
exports.createEnhancedStorageCluster = createEnhancedStorageCluster;
|
|
672
|
+
exports.createEnhancedStorageWallet = createEnhancedStorageWallet;
|
|
673
|
+
exports.createKitSignersFromWallet = createKitSignersFromWallet;
|
|
674
|
+
exports.createMessageSignerFromWallet = createMessageSignerFromWallet;
|
|
675
|
+
exports.createTransactionSendingSignerFromWallet = createTransactionSendingSignerFromWallet;
|
|
676
|
+
exports.detectMessageModification = detectMessageModification;
|
|
677
|
+
exports.formatSignature = formatSignature;
|
|
678
|
+
exports.freezeSigner = freezeSigner;
|
|
679
|
+
exports.getAllExplorerUrls = getAllExplorerUrls;
|
|
680
|
+
exports.getChainIdFromCluster = getChainIdFromCluster;
|
|
681
|
+
exports.getChainIdFromClusterId = getChainIdFromClusterId;
|
|
682
|
+
exports.getChainIdFromClusterType = getChainIdFromClusterType;
|
|
683
|
+
exports.getChainIdFromConnection = getChainIdFromConnection;
|
|
684
|
+
exports.getClusterIdFromChainId = getClusterIdFromChainId;
|
|
685
|
+
exports.getClusterTypeFromChainId = getClusterTypeFromChainId;
|
|
686
|
+
exports.getClusterTypeFromConnection = getClusterTypeFromConnection;
|
|
687
|
+
exports.getDefaultConfig = getDefaultConfig;
|
|
688
|
+
exports.getDefaultMobileConfig = getDefaultMobileConfig;
|
|
689
|
+
exports.getLatestBlockhash = getLatestBlockhash;
|
|
690
|
+
exports.getSolanaExplorerUrl = getSolanaExplorerUrl;
|
|
691
|
+
exports.getSolanaFmUrl = getSolanaFmUrl;
|
|
692
|
+
exports.getSolscanUrl = getSolscanUrl;
|
|
693
|
+
exports.getXrayUrl = getXrayUrl;
|
|
694
|
+
exports.isAccountAddress = isAccountAddress;
|
|
695
|
+
exports.isKitConnection = isKitConnection;
|
|
696
|
+
exports.isKnownSolanaChain = isKnownSolanaChain;
|
|
697
|
+
exports.isLegacyConnection = isLegacyConnection;
|
|
698
|
+
exports.isSolanaChain = isSolanaChain;
|
|
699
|
+
exports.isUnifiedConfig = isUnifiedConfig;
|
|
700
|
+
exports.isWalletName = isWalletName;
|
|
701
|
+
exports.sendRawTransaction = sendRawTransaction;
|
|
702
|
+
exports.signatureBytesToBase58 = signatureBytesToBase58;
|
|
703
|
+
exports.updateSignatureDictionary = updateSignatureDictionary;
|
|
704
|
+
exports.validateKnownSolanaChain = validateKnownSolanaChain;
|
|
705
|
+
//# sourceMappingURL=chunk-P4ZLJI4L.js.map
|
|
706
|
+
//# sourceMappingURL=chunk-P4ZLJI4L.js.map
|