@vue-solana/core 2.6.1 → 3.0.0

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