@vue-solana/core 3.0.1 → 4.0.0-rc.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.
Files changed (50) hide show
  1. package/README.md +39 -2
  2. package/dist/action.d.ts +10 -3
  3. package/dist/action.mjs +4 -4
  4. package/dist/address.d.ts +7 -2
  5. package/dist/address.mjs +8 -2
  6. package/dist/clusters.d.ts +1 -1
  7. package/dist/clusters.mjs +10 -1
  8. package/dist/errors.d.ts +1 -1
  9. package/dist/errors.mjs +4 -1
  10. package/dist/index.d.ts +4 -11
  11. package/dist/index.mjs +2 -8
  12. package/dist/ios-wallet.d.ts +1 -2
  13. package/dist/ios-wallet.mjs +675 -1
  14. package/dist/kit.d.ts +1 -1
  15. package/dist/kit.mjs +22 -9
  16. package/dist/mobile-wallet.d.ts +12 -2
  17. package/dist/mobile-wallet.mjs +4 -1
  18. package/dist/rpc.d.ts +1 -1
  19. package/dist/shared/{core.DaUlAmcN.mjs → core.A4I__4IR.mjs} +86 -6
  20. package/dist/shared/{core.C9vxHRXl.d.mts → core.BhF1J_tt.d.ts} +40 -2
  21. package/dist/timeout.d.ts +22 -1
  22. package/dist/timeout.mjs +53 -17
  23. package/dist/token-accounts.d.ts +1 -1
  24. package/dist/token-accounts.mjs +31 -2
  25. package/dist/transaction.d.ts +9 -1
  26. package/dist/transaction.mjs +52 -10
  27. package/dist/types.d.ts +1 -1
  28. package/dist/wallet-standard.d.ts +24 -4
  29. package/dist/wallet-standard.mjs +1 -1
  30. package/dist/wallet.d.ts +1 -1
  31. package/package.json +13 -5
  32. package/dist/action.d.mts +0 -28
  33. package/dist/address.d.mts +0 -16
  34. package/dist/buffer-polyfill.d.mts +0 -7
  35. package/dist/clusters.d.mts +0 -10
  36. package/dist/errors.d.mts +0 -17
  37. package/dist/index.d.mts +0 -21
  38. package/dist/ios-wallet.d.mts +0 -62
  39. package/dist/kit.d.mts +0 -3
  40. package/dist/mobile-wallet-support.d.mts +0 -3
  41. package/dist/mobile-wallet.d.mts +0 -20
  42. package/dist/rpc.d.mts +0 -7
  43. package/dist/shared/core.C9vxHRXl.d.ts +0 -193
  44. package/dist/shared/core.DJsPYgx_.mjs +0 -625
  45. package/dist/timeout.d.mts +0 -4
  46. package/dist/token-accounts.d.mts +0 -36
  47. package/dist/transaction.d.mts +0 -18
  48. package/dist/types.d.mts +0 -3
  49. package/dist/wallet-standard.d.mts +0 -22
  50. package/dist/wallet.d.mts +0 -25
@@ -1,625 +0,0 @@
1
- import { isAddress } from '@solana/kit';
2
- import bs58 from 'bs58';
3
- import * as naclModule from 'tweetnacl';
4
- import { createSolanaError } from '../errors.mjs';
5
-
6
- const DEFAULT_IOS_WALLET_CHAINS = [
7
- "solana:mainnet",
8
- "solana:devnet"
9
- ];
10
- const CALLBACK_PARAMS = /* @__PURE__ */ new Set([
11
- "data",
12
- "nonce",
13
- "errorCode",
14
- "errorMessage",
15
- "phantom_encryption_public_key",
16
- "solflare_encryption_public_key",
17
- "wallet_encryption_public_key"
18
- ]);
19
- function isSolanaIosBrowserWalletSupported() {
20
- return isIosBrowser();
21
- }
22
- function isIosBrowser() {
23
- if (typeof window === "undefined" || typeof navigator === "undefined") {
24
- return false;
25
- }
26
- const userAgentDataPlatform = getNavigatorUserAgentDataPlatform();
27
- if (isIosPlatform(userAgentDataPlatform)) {
28
- return true;
29
- }
30
- const userAgent = navigator.userAgent;
31
- const platform = getNavigatorPlatform();
32
- const maxTouchPoints = navigator.maxTouchPoints ?? 0;
33
- return /iPad|iPhone|iPod/i.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
34
- }
35
- function getDefaultIosWalletAppIdentity() {
36
- if (typeof window === "undefined") {
37
- return {
38
- name: "Vue Solana App",
39
- uri: "https://localhost"
40
- };
41
- }
42
- return {
43
- name: document.title || "Vue Solana App",
44
- uri: window.location.origin,
45
- icon: getDocumentIconUrl()
46
- };
47
- }
48
- function getDefaultIosWalletRedirectUrl() {
49
- if (typeof window === "undefined") {
50
- return "https://localhost";
51
- }
52
- const url = new URL(window.location.href);
53
- for (const param of CALLBACK_PARAMS) {
54
- url.searchParams.delete(param);
55
- }
56
- return url.toString();
57
- }
58
- function openIosWalletUrl(url) {
59
- if (typeof window === "undefined") {
60
- throw new Error("iOS wallet links are only available in browser runtimes");
61
- }
62
- window.location.assign(url);
63
- }
64
- function waitForRedirect() {
65
- return new Promise(() => {
66
- });
67
- }
68
- function hasIosWalletCallbackParams(url) {
69
- for (const param of CALLBACK_PARAMS) {
70
- if (url.searchParams.has(param)) {
71
- return true;
72
- }
73
- }
74
- return false;
75
- }
76
- function cleanCallbackUrl(url, clearUrl) {
77
- if (!clearUrl || typeof window === "undefined") {
78
- return;
79
- }
80
- for (const param of CALLBACK_PARAMS) {
81
- url.searchParams.delete(param);
82
- }
83
- window.history.replaceState(window.history.state, document.title, url.toString());
84
- }
85
- function getDocumentIconUrl() {
86
- const icon = document.querySelector(
87
- 'link[rel="icon"], link[rel="shortcut icon"], link[rel="apple-touch-icon"]'
88
- );
89
- return icon?.href;
90
- }
91
- function getNavigatorUserAgentDataPlatform() {
92
- const userAgentData = Reflect.get(navigator, "userAgentData");
93
- if (!isObjectRecord(userAgentData)) {
94
- return void 0;
95
- }
96
- const platform = Reflect.get(userAgentData, "platform");
97
- return typeof platform === "string" ? platform : void 0;
98
- }
99
- function getNavigatorPlatform() {
100
- const platform = Reflect.get(navigator, "platform");
101
- return typeof platform === "string" ? platform : "";
102
- }
103
- function isIosPlatform(platform) {
104
- return platform?.toLowerCase() === "ios";
105
- }
106
- function isObjectRecord(value) {
107
- return typeof value === "object" && value !== null;
108
- }
109
-
110
- let cachedNacl;
111
- function getNacl() {
112
- return cachedNacl ??= resolveTweetNaCl();
113
- }
114
- function createRequestId() {
115
- return bs58.encode(getNacl().randomBytes(16));
116
- }
117
- function getSharedSecret(walletEncryptionPublicKey, dappSecretKey) {
118
- if (!walletEncryptionPublicKey) {
119
- throw createSolanaError("INVALID_INPUT", "Missing iOS wallet encryption public key");
120
- }
121
- let walletPk;
122
- let dappSk;
123
- try {
124
- walletPk = bs58.decode(walletEncryptionPublicKey);
125
- dappSk = bs58.decode(dappSecretKey);
126
- } catch (cause) {
127
- throw createSolanaError("INVALID_INPUT", "Invalid iOS wallet encryption key encoding", {
128
- cause
129
- });
130
- }
131
- if (walletPk.length !== getNacl().box.publicKeyLength) {
132
- throw createSolanaError("INVALID_INPUT", "Invalid iOS wallet encryption public key length");
133
- }
134
- if (dappSk.length !== getNacl().box.secretKeyLength) {
135
- throw createSolanaError("INVALID_INPUT", "Invalid iOS wallet dapp secret key length");
136
- }
137
- return getNacl().box.before(walletPk, dappSk);
138
- }
139
- function encryptPayload(payload, nonce, sharedSecret) {
140
- if (sharedSecret.length !== getNacl().box.sharedKeyLength) {
141
- throw createSolanaError("INVALID_INPUT", "Invalid iOS wallet shared secret length");
142
- }
143
- if (nonce.length !== getNacl().box.nonceLength) {
144
- throw createSolanaError("INVALID_INPUT", "Invalid iOS wallet nonce length");
145
- }
146
- try {
147
- return bs58.encode(getNacl().box.after(encodeJson(payload), nonce, sharedSecret));
148
- } catch (cause) {
149
- throw createSolanaError("INVALID_INPUT", "Failed to encrypt iOS wallet payload", { cause });
150
- }
151
- }
152
- function decryptPayload(data, nonce, sharedSecret) {
153
- let decodedData;
154
- let decodedNonce;
155
- try {
156
- decodedData = bs58.decode(data);
157
- decodedNonce = bs58.decode(nonce);
158
- } catch (cause) {
159
- throw createSolanaError("INVALID_INPUT", "Invalid iOS wallet callback encoding", { cause });
160
- }
161
- if (sharedSecret.length !== getNacl().box.sharedKeyLength) {
162
- throw createSolanaError("INVALID_INPUT", "Invalid iOS wallet shared secret length");
163
- }
164
- if (decodedNonce.length !== getNacl().box.nonceLength) {
165
- throw createSolanaError("INVALID_INPUT", "Invalid iOS wallet callback nonce length");
166
- }
167
- const decrypted = getNacl().box.open.after(decodedData, decodedNonce, sharedSecret);
168
- if (!decrypted) {
169
- throw createSolanaError("DECRYPTION_FAILED", "Unable to decrypt iOS wallet callback");
170
- }
171
- try {
172
- return JSON.parse(new TextDecoder().decode(decrypted));
173
- } catch (cause) {
174
- throw createSolanaError("DECRYPTION_FAILED", "Unable to decode iOS wallet callback payload", {
175
- cause
176
- });
177
- }
178
- }
179
- function resolveTweetNaCl() {
180
- const moduleDefault = naclModule.default;
181
- const globalNacl = globalThis.nacl;
182
- return "box" in naclModule ? naclModule : moduleDefault ?? globalNacl;
183
- }
184
- function encodeJson(value) {
185
- return new TextEncoder().encode(JSON.stringify(value));
186
- }
187
-
188
- const IOS_WALLETS = [
189
- {
190
- id: "phantom",
191
- name: "Phantom",
192
- icon: "https://phantom.app/img/phantom-logo.svg",
193
- appUrl: "https://phantom.app",
194
- installUrl: "https://phantom.app/download",
195
- encryptionPublicKeyParam: "phantom_encryption_public_key",
196
- connectUrl: "https://phantom.app/ul/v1/connect",
197
- signTransactionUrl: "https://phantom.app/ul/v1/signTransaction",
198
- signAllTransactionsUrl: "https://phantom.app/ul/v1/signAllTransactions"
199
- },
200
- {
201
- id: "solflare",
202
- name: "Solflare",
203
- icon: "https://solflare.com/favicon.ico",
204
- appUrl: "https://solflare.com",
205
- installUrl: "https://solflare.com/download",
206
- encryptionPublicKeyParam: "solflare_encryption_public_key",
207
- connectUrl: "https://solflare.com/ul/v1/connect",
208
- signTransactionUrl: "https://solflare.com/ul/v1/signTransaction",
209
- signAllTransactionsUrl: "https://solflare.com/ul/v1/signAllTransactions",
210
- signAndSendTransactionUrl: "https://solflare.com/ul/v1/signAndSendTransaction"
211
- },
212
- {
213
- id: "backpack",
214
- name: "Backpack",
215
- icon: "https://backpack.app/favicon.ico",
216
- appUrl: "https://backpack.app",
217
- installUrl: "https://backpack.app/download",
218
- encryptionPublicKeyParam: "wallet_encryption_public_key",
219
- connectUrl: "https://backpack.app/ul/v1/connect",
220
- signTransactionUrl: "https://backpack.app/ul/v1/signTransaction",
221
- signAllTransactionsUrl: "https://backpack.app/ul/v1/signAllTransactions",
222
- signAndSendTransactionUrl: "https://backpack.app/ul/v1/signAndSendTransaction"
223
- }
224
- ];
225
- function getIosWalletDefinitionById(walletId) {
226
- const definition = IOS_WALLETS.find((wallet) => wallet.id === walletId);
227
- if (!definition) {
228
- throw new Error(`Unknown iOS wallet: ${walletId}`);
229
- }
230
- return definition;
231
- }
232
- function isIosWalletDefinition(value) {
233
- return typeof value === "object" && value !== null && "id" in value && typeof value.id === "string" && IOS_WALLETS.some((wallet) => wallet.id === value.id);
234
- }
235
-
236
- const PENDING_REQUEST_KEY = "vue-solana:ios-wallet:pending";
237
- const PENDING_REQUEST_TTL_MS = 10 * 60 * 1e3;
238
- const SESSION_PREFIX = "vue-solana:ios-wallet:session:";
239
- function createPendingRequest(walletId, method, keyPair, redirectUrl, requestedTransactionCount) {
240
- return {
241
- id: createRequestId(),
242
- walletId,
243
- method,
244
- dappEncryptionPublicKey: bs58.encode(keyPair.publicKey),
245
- dappEncryptionSecretKey: bs58.encode(keyPair.secretKey),
246
- redirectUrl: redirectUrl ?? getDefaultIosWalletRedirectUrl(),
247
- createdAt: Date.now(),
248
- requestedTransactionCount
249
- };
250
- }
251
- function getStoredIosWalletAccount(walletId, chains) {
252
- const session = getStoredSession(walletId);
253
- if (!session) {
254
- return [];
255
- }
256
- return [
257
- {
258
- address: session.publicKey,
259
- publicKey: bs58.decode(session.publicKey),
260
- chains
261
- }
262
- ];
263
- }
264
- function getStoredSession(walletId) {
265
- return readJson(
266
- `${SESSION_PREFIX}${walletId}`,
267
- (session) => isAddress(session.publicKey)
268
- );
269
- }
270
- function storeSession(session) {
271
- writeJson(`${SESSION_PREFIX}${session.walletId}`, session);
272
- }
273
- function removeStoredSession(walletId) {
274
- removeJson(`${SESSION_PREFIX}${walletId}`);
275
- }
276
- function getPendingRequest() {
277
- return readJson(PENDING_REQUEST_KEY);
278
- }
279
- function storePendingRequest(request) {
280
- writeJson(PENDING_REQUEST_KEY, request);
281
- }
282
- function clearPendingRequest() {
283
- removeJson(PENDING_REQUEST_KEY);
284
- }
285
- function isPendingRequestExpired(request) {
286
- return Date.now() - request.createdAt > PENDING_REQUEST_TTL_MS;
287
- }
288
- function readJson(key, validate) {
289
- const value = getStorage()?.getItem(key);
290
- if (!value) {
291
- return null;
292
- }
293
- try {
294
- const parsed = JSON.parse(value);
295
- if (validate && !validate(parsed)) {
296
- throw new Error("Invalid stored value");
297
- }
298
- return parsed;
299
- } catch {
300
- getStorage()?.removeItem(key);
301
- return null;
302
- }
303
- }
304
- function writeJson(key, value) {
305
- getStorage()?.setItem(key, JSON.stringify(value));
306
- }
307
- function removeJson(key) {
308
- getStorage()?.removeItem(key);
309
- }
310
- function getStorage() {
311
- if (typeof window === "undefined") {
312
- return null;
313
- }
314
- try {
315
- return window.sessionStorage;
316
- } catch {
317
- return null;
318
- }
319
- }
320
-
321
- function handleSolanaIosWalletCallback(options = {}) {
322
- if (typeof window === "undefined") {
323
- return null;
324
- }
325
- const url = new URL(window.location.href);
326
- if (!hasIosWalletCallbackParams(url)) {
327
- return null;
328
- }
329
- const errorCode = url.searchParams.get("errorCode");
330
- const errorMessage = url.searchParams.get("errorMessage");
331
- if (errorCode || errorMessage) {
332
- clearPendingRequest();
333
- cleanCallbackUrl(url, options.clearUrl);
334
- throw new Error(errorMessage || `iOS wallet request failed: ${errorCode}`);
335
- }
336
- const pending = getPendingRequest();
337
- if (!pending) {
338
- cleanCallbackUrl(url, options.clearUrl);
339
- throw new Error("Received an iOS wallet callback without a pending request");
340
- }
341
- if (isPendingRequestExpired(pending)) {
342
- clearPendingRequest();
343
- cleanCallbackUrl(url, options.clearUrl);
344
- throw new Error("Received an expired iOS wallet callback");
345
- }
346
- const definition = getIosWalletDefinitionById(pending.walletId);
347
- const walletEncryptionPublicKey = url.searchParams.get(definition.encryptionPublicKeyParam);
348
- const nonce = url.searchParams.get("nonce");
349
- const data = url.searchParams.get("data");
350
- if (!nonce || !data) {
351
- clearPendingRequest();
352
- cleanCallbackUrl(url, options.clearUrl);
353
- throw new Error("Received an incomplete iOS wallet callback");
354
- }
355
- try {
356
- const sharedSecret = getSharedSecret(
357
- walletEncryptionPublicKey ?? getStoredSession(pending.walletId)?.walletEncryptionPublicKey,
358
- pending.dappEncryptionSecretKey
359
- );
360
- const payload = decryptPayload(data, nonce, sharedSecret);
361
- const result = createCallbackResult(pending, payload);
362
- if (pending.method === "connect") {
363
- if (!walletEncryptionPublicKey) {
364
- throw new Error("iOS wallet connect callback did not include an encryption public key");
365
- }
366
- const publicKey = getPublicKeyField(payload, "public_key");
367
- storeSession({
368
- walletId: pending.walletId,
369
- publicKey,
370
- session: getStringField(payload, "session"),
371
- dappEncryptionPublicKey: pending.dappEncryptionPublicKey,
372
- dappEncryptionSecretKey: pending.dappEncryptionSecretKey,
373
- walletEncryptionPublicKey,
374
- sharedSecret: bs58.encode(sharedSecret)
375
- });
376
- }
377
- return result;
378
- } finally {
379
- clearPendingRequest();
380
- cleanCallbackUrl(url, options.clearUrl);
381
- }
382
- }
383
- function createCallbackResult(pending, payload) {
384
- if (pending.method === "connect") {
385
- return {
386
- walletId: pending.walletId,
387
- method: pending.method,
388
- publicKey: getPublicKeyField(payload, "public_key")
389
- };
390
- }
391
- if (pending.method === "signTransaction") {
392
- return {
393
- walletId: pending.walletId,
394
- method: pending.method,
395
- transaction: bs58.decode(getStringField(payload, "transaction"))
396
- };
397
- }
398
- if (pending.method === "signAllTransactions") {
399
- const transactions = payload.transactions;
400
- if (!Array.isArray(transactions) || transactions.some((transaction) => typeof transaction !== "string")) {
401
- throw new Error("iOS wallet returned invalid signed transactions");
402
- }
403
- if (typeof pending.requestedTransactionCount === "number" && transactions.length !== pending.requestedTransactionCount) {
404
- throw new Error(
405
- `iOS wallet returned ${transactions.length} signed transactions for ${pending.requestedTransactionCount} requested transactions`
406
- );
407
- }
408
- return {
409
- walletId: pending.walletId,
410
- method: pending.method,
411
- transactions: transactions.map((transaction) => bs58.decode(transaction))
412
- };
413
- }
414
- return {
415
- walletId: pending.walletId,
416
- method: pending.method,
417
- signature: getStringField(payload, "signature")
418
- };
419
- }
420
- function getStringField(payload, field) {
421
- const value = payload[field];
422
- if (typeof value !== "string" || !value) {
423
- throw new Error(`iOS wallet callback is missing ${field}`);
424
- }
425
- return value;
426
- }
427
- function getPublicKeyField(payload, field) {
428
- const value = getStringField(payload, field);
429
- if (!isAddress(value)) {
430
- throw new Error(`iOS wallet callback returned an invalid ${field}`);
431
- }
432
- return value;
433
- }
434
-
435
- function launchConnect(definition, options) {
436
- const keyPair = getNacl().box.keyPair();
437
- const pending = createPendingRequest(definition.id, "connect", keyPair, options.redirectUrl);
438
- const appIdentity = options.appIdentity ?? getDefaultIosWalletAppIdentity();
439
- const url = new URL(definition.connectUrl);
440
- url.searchParams.set("app_url", appIdentity.uri);
441
- url.searchParams.set("dapp_encryption_public_key", pending.dappEncryptionPublicKey);
442
- url.searchParams.set("redirect_link", pending.redirectUrl);
443
- if (options.cluster && options.cluster !== "localnet") {
444
- url.searchParams.set("cluster", options.cluster);
445
- }
446
- storePendingRequest(pending);
447
- openIosWalletUrl(url.toString());
448
- }
449
- async function launchSignTransaction(definition, transaction, options) {
450
- const response = await launchEncryptedWalletRequest(definition, "signTransaction", options, {
451
- transaction: bs58.encode(new Uint8Array(transaction))
452
- });
453
- if (!response.transaction) {
454
- throw new Error("iOS wallet did not return a signed transaction");
455
- }
456
- return response.transaction;
457
- }
458
- async function launchSignAllTransactions(definition, transactions, options) {
459
- const response = await launchEncryptedWalletRequest(definition, "signAllTransactions", options, {
460
- transactions: transactions.map((transaction) => bs58.encode(new Uint8Array(transaction)))
461
- });
462
- if (!response.transactions) {
463
- throw new Error("iOS wallet did not return signed transactions");
464
- }
465
- return response.transactions;
466
- }
467
- async function launchSignAndSendTransaction(definition, transaction, sendOptions, options) {
468
- const response = await launchEncryptedWalletRequest(
469
- definition,
470
- "signAndSendTransaction",
471
- options,
472
- {
473
- transaction: bs58.encode(new Uint8Array(transaction)),
474
- sendOptions
475
- }
476
- );
477
- if (!response.signature) {
478
- throw new Error("iOS wallet did not return a transaction signature");
479
- }
480
- return { signature: response.signature };
481
- }
482
- async function launchEncryptedWalletRequest(definition, method, options, payload) {
483
- const session = getStoredSession(definition.id);
484
- if (!session) {
485
- throw new Error("Connect the iOS wallet before signing");
486
- }
487
- const methodUrl = getIosWalletMethodUrl(definition, method);
488
- const pending = createPendingRequest(
489
- definition.id,
490
- method,
491
- {
492
- publicKey: bs58.decode(session.dappEncryptionPublicKey),
493
- secretKey: bs58.decode(session.dappEncryptionSecretKey)
494
- },
495
- options.redirectUrl,
496
- method === "signAllTransactions" && Array.isArray(payload.transactions) ? payload.transactions.length : void 0
497
- );
498
- const nonce = getNacl().randomBytes(getNacl().box.nonceLength);
499
- const encryptedPayload = encryptPayload(
500
- { ...payload, session: session.session },
501
- nonce,
502
- bs58.decode(session.sharedSecret)
503
- );
504
- const url = new URL(methodUrl);
505
- url.searchParams.set("dapp_encryption_public_key", session.dappEncryptionPublicKey);
506
- url.searchParams.set("nonce", bs58.encode(nonce));
507
- url.searchParams.set("redirect_link", pending.redirectUrl);
508
- url.searchParams.set("payload", encryptedPayload);
509
- storePendingRequest(pending);
510
- openIosWalletUrl(url.toString());
511
- return waitForRedirect();
512
- }
513
- function getIosWalletMethodUrl(definition, method) {
514
- const url = definition[`${method}Url`];
515
- if (!url) {
516
- throw new Error(`${definition.name} does not support ${method} through iOS deeplinks`);
517
- }
518
- return url;
519
- }
520
-
521
- function getSolanaIosWallets(options = {}) {
522
- if (!isSolanaIosBrowserWalletSupported()) {
523
- return [];
524
- }
525
- const chains = options.chains?.length ? options.chains : DEFAULT_IOS_WALLET_CHAINS;
526
- const callbackUrl = options.redirectUrl ?? getDefaultIosWalletRedirectUrl();
527
- return IOS_WALLETS.map((wallet) => ({
528
- name: wallet.name,
529
- icon: wallet.icon,
530
- chains,
531
- platform: "mobile",
532
- source: "deep-link",
533
- appUrl: wallet.appUrl,
534
- installUrl: wallet.installUrl,
535
- callbackUrl,
536
- capabilities: {
537
- connect: true,
538
- disconnect: true,
539
- signTransaction: Boolean(wallet.signTransactionUrl),
540
- signAllTransactions: Boolean(wallet.signAllTransactionsUrl),
541
- signAndSendTransaction: Boolean(wallet.signAndSendTransactionUrl)
542
- },
543
- accounts: getStoredIosWalletAccount(wallet.id, chains),
544
- wallet
545
- }));
546
- }
547
- function adaptSolanaIosWallet(walletInfo, options = {}) {
548
- const definition = getIosWalletDefinition(walletInfo);
549
- let connecting = false;
550
- let disconnecting = false;
551
- let session = getStoredSession(definition.id);
552
- function refreshSession() {
553
- session = getStoredSession(definition.id);
554
- options.onChange?.();
555
- }
556
- return {
557
- get publicKey() {
558
- return session?.publicKey ? session.publicKey : null;
559
- },
560
- get connected() {
561
- return Boolean(session?.publicKey && session.session);
562
- },
563
- get connecting() {
564
- return connecting;
565
- },
566
- get disconnecting() {
567
- return disconnecting;
568
- },
569
- async connect() {
570
- const callback = handleSolanaIosWalletCallback({ clearUrl: true });
571
- if (callback?.walletId === definition.id) {
572
- refreshSession();
573
- return;
574
- }
575
- connecting = true;
576
- options.onChange?.();
577
- try {
578
- launchConnect(definition, options);
579
- await waitForRedirect();
580
- } finally {
581
- connecting = false;
582
- options.onChange?.();
583
- }
584
- },
585
- async disconnect() {
586
- disconnecting = true;
587
- options.onChange?.();
588
- try {
589
- removeStoredSession(definition.id);
590
- refreshSession();
591
- } finally {
592
- disconnecting = false;
593
- options.onChange?.();
594
- }
595
- },
596
- signTransaction: definition.signTransactionUrl ? async (transaction) => {
597
- return launchSignTransaction(definition, transaction, options);
598
- } : void 0,
599
- signAllTransactions: definition.signAllTransactionsUrl ? async (transactions) => {
600
- const signedTransactions = await launchSignAllTransactions(
601
- definition,
602
- transactions,
603
- options
604
- );
605
- if (signedTransactions.length !== transactions.length) {
606
- throw new Error(
607
- `iOS wallet returned ${signedTransactions.length} signed transactions for ${transactions.length} requested transactions`
608
- );
609
- }
610
- return signedTransactions;
611
- } : void 0,
612
- signAndSendTransaction: definition.signAndSendTransactionUrl ? async (transaction, sendOptions) => launchSignAndSendTransaction(definition, transaction, sendOptions, options) : void 0
613
- };
614
- }
615
- function isSolanaIosWalletInfo(walletInfo) {
616
- return walletInfo.source === "deep-link" && isIosWalletDefinition(walletInfo.wallet);
617
- }
618
- function getIosWalletDefinition(walletInfo) {
619
- if (!isIosWalletDefinition(walletInfo.wallet)) {
620
- throw new Error("Solana wallet info is not an iOS wallet");
621
- }
622
- return walletInfo.wallet;
623
- }
624
-
625
- export { adaptSolanaIosWallet as a, getDefaultIosWalletRedirectUrl as b, getSolanaIosWallets as c, isSolanaIosBrowserWalletSupported as d, isSolanaIosWalletInfo as e, getDefaultIosWalletAppIdentity as g, handleSolanaIosWalletCallback as h, isIosBrowser as i };
@@ -1,4 +0,0 @@
1
- declare function withTimeout<T>(promise: Promise<T>, timeoutMs: number | undefined, createError: () => unknown): Promise<T>;
2
- declare function withSolanaTimeout<T>(promise: Promise<T>, timeoutMs: number | undefined, message: string): Promise<T>;
3
-
4
- export { withSolanaTimeout, withTimeout };
@@ -1,36 +0,0 @@
1
- import { Address, Commitment } from '@solana/kit';
2
- import { b as SolanaClient } from './shared/core.C9vxHRXl.mjs';
3
- import '@solana/kit-plugin-rpc';
4
-
5
- interface TokenAccountInfo {
6
- address: Address;
7
- mint: Address;
8
- owner: Address;
9
- amount: bigint;
10
- decimals: number;
11
- state: "frozen" | "initialized" | "uninitialized";
12
- isNative: boolean;
13
- }
14
- interface TokenAccountsByOwnerOptions {
15
- commitment?: Commitment;
16
- programId?: Address;
17
- }
18
- /**
19
- * Get all SPL token accounts for an owner using parsed kit RPC reads.
20
- */
21
- declare function getTokenAccountsByOwner(client: SolanaClient, owner: Address, options?: TokenAccountsByOwnerOptions): Promise<TokenAccountInfo[]>;
22
- /**
23
- * Get a single parsed token account at the given address.
24
- */
25
- declare function getTokenAccount(client: SolanaClient, address: Address, commitment?: Commitment): Promise<TokenAccountInfo | null>;
26
- interface TokenBalanceResult {
27
- amount: bigint;
28
- decimals: number;
29
- }
30
- /**
31
- * Read the token balance of the accounts an owner holds for a given mint.
32
- */
33
- declare function getTokenBalance(client: SolanaClient, mint: Address, owner: Address, commitment?: Commitment): Promise<TokenBalanceResult | null>;
34
-
35
- export { getTokenAccount, getTokenAccountsByOwner, getTokenBalance };
36
- export type { TokenAccountInfo, TokenAccountsByOwnerOptions, TokenBalanceResult };
@@ -1,18 +0,0 @@
1
- import { Signature } from '@solana/kit';
2
- import { b as SolanaClient, C as ConfirmTransactionOptions, T as TransactionConfirmation, k as SolanaWallet, j as SolanaTransaction, S as SendTransactionOptions } from './shared/core.C9vxHRXl.mjs';
3
- import '@solana/kit-plugin-rpc';
4
-
5
- /**
6
- * Sign and send a transaction through a connected wallet.
7
- *
8
- * Walks through the supported kit RPC path: the wallet signs the raw wire
9
- * transaction, and the client sends it via `client.rpc.sendTransaction`.
10
- */
11
- declare function signAndSendTransaction(client: SolanaClient, wallet: SolanaWallet, transaction: SolanaTransaction, options?: SendTransactionOptions): Promise<Signature>;
12
- /**
13
- * Confirm a transaction signature against the kit RPC until it reaches the
14
- * requested commitment.
15
- */
16
- declare function confirmTransactionSignature(client: SolanaClient, signature: Signature, options?: ConfirmTransactionOptions): Promise<TransactionConfirmation>;
17
-
18
- export { confirmTransactionSignature, signAndSendTransaction };
package/dist/types.d.mts DELETED
@@ -1,3 +0,0 @@
1
- import '@solana/kit';
2
- export { C as ConfirmTransactionOptions, S as SendTransactionOptions, a as SolanaChain, c as SolanaCluster, d as SolanaConfig, e as SolanaContext, f as SolanaSignInAccount, g as SolanaSignInInput, h as SolanaSignInResult, i as SolanaSignMessageResult, j as SolanaTransaction, k as SolanaWallet, l as SolanaWalletInfo, T as TransactionConfirmation, m as TransactionStatus } from './shared/core.C9vxHRXl.mjs';
3
- import '@solana/kit-plugin-rpc';