@cosmosapp/pay_sdk 2.3.1 → 2.4.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/CHANGELOG.md +24 -0
  2. package/README.md +97 -61
  3. package/dist/{chunk-B3HT6MCO.js → chunk-6FIALX2E.js} +3 -3
  4. package/dist/{chunk-B3HT6MCO.js.map → chunk-6FIALX2E.js.map} +1 -1
  5. package/dist/{chunk-AYVWYEOK.js → chunk-6PHQBYQ4.js} +2 -2
  6. package/dist/chunk-6PHQBYQ4.js.map +1 -0
  7. package/dist/chunk-ALFITFBN.js +105 -0
  8. package/dist/chunk-ALFITFBN.js.map +1 -0
  9. package/dist/chunk-PAQHOXQ6.js +392 -0
  10. package/dist/chunk-PAQHOXQ6.js.map +1 -0
  11. package/dist/{cosmosProvider-DTz0Y8xZ.d.cts → cosmosProvider-BrpOdL_b.d.cts} +3 -3
  12. package/dist/{cosmosProvider-DTz0Y8xZ.d.ts → cosmosProvider-BrpOdL_b.d.ts} +3 -3
  13. package/dist/errors-CZu5mmz1.d.cts +293 -0
  14. package/dist/errors-Cqh7UdUO.d.ts +293 -0
  15. package/dist/index.cjs +18 -5
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +12 -7
  18. package/dist/index.d.ts +12 -7
  19. package/dist/index.js +19 -6
  20. package/dist/index.js.map +1 -1
  21. package/dist/intent-input-BybnwL83.d.ts +126 -0
  22. package/dist/intent-input-C2PTr2XH.d.cts +126 -0
  23. package/dist/swk/index.cjs +2 -2
  24. package/dist/swk/index.cjs.map +1 -1
  25. package/dist/swk/index.d.cts +7 -7
  26. package/dist/swk/index.d.ts +7 -7
  27. package/dist/swk/index.js +2 -104
  28. package/dist/swk/index.js.map +1 -1
  29. package/dist/wallets/index.cjs +1043 -0
  30. package/dist/wallets/index.cjs.map +1 -0
  31. package/dist/wallets/index.d.cts +384 -0
  32. package/dist/wallets/index.d.ts +384 -0
  33. package/dist/wallets/index.js +629 -0
  34. package/dist/wallets/index.js.map +1 -0
  35. package/dist/{intent-input-CP5bkBYI.d.cts → wallets-CeIjESt5.d.cts} +39 -126
  36. package/dist/{intent-input-CP5bkBYI.d.ts → wallets-CeIjESt5.d.ts} +39 -126
  37. package/dist/web/index.cjs +4 -4
  38. package/dist/web/index.cjs.map +1 -1
  39. package/dist/web/index.d.cts +11 -296
  40. package/dist/web/index.d.ts +11 -296
  41. package/dist/web/index.js +6 -392
  42. package/dist/web/index.js.map +1 -1
  43. package/llms/07-webhooks.md +2 -0
  44. package/llms/15-swaps.md +2 -0
  45. package/llms/18-wallets.md +94 -0
  46. package/llms/llms-full.txt +101 -0
  47. package/llms/llms.txt +1 -0
  48. package/package.json +22 -8
  49. package/dist/chunk-AYVWYEOK.js.map +0 -1
@@ -0,0 +1,629 @@
1
+ import { COSMOS_WALLET_ID } from '../chunk-ALFITFBN.js';
2
+ import { defaultAdapters, getWindow, WalletError, errorMessage, PASSPHRASES, HORIZON_URLS } from '../chunk-PAQHOXQ6.js';
3
+ export { WalletError } from '../chunk-PAQHOXQ6.js';
4
+ import '../chunk-6PHQBYQ4.js';
5
+
6
+ // src/wallets/stellar-injected.ts
7
+ function check(result) {
8
+ if (result && typeof result === "object" && result.error) {
9
+ const error = result.error;
10
+ throw new Error(typeof error === "string" ? error : errorMessage(error));
11
+ }
12
+ return result;
13
+ }
14
+ function pick(result, keys) {
15
+ check(result);
16
+ if (typeof result === "string" && result) return result;
17
+ if (result && typeof result === "object") {
18
+ for (const key of keys) {
19
+ const value = result[key];
20
+ if (typeof value === "string" && value) return value;
21
+ }
22
+ }
23
+ throw new Error("The wallet answered nothing usable.");
24
+ }
25
+ var positional = (p, xdr, opts) => p["signTransaction"](xdr, opts);
26
+ async function withAccess(p, strict) {
27
+ if (typeof p["requestAccess"] === "function") {
28
+ try {
29
+ check(await p["requestAccess"]());
30
+ } catch (error) {
31
+ if (strict) throw error;
32
+ }
33
+ }
34
+ return typeof p["getAddress"] === "function" ? p["getAddress"]() : p["getPublicKey"]();
35
+ }
36
+ var INJECTED_STELLAR_WALLETS = [
37
+ {
38
+ id: "hana",
39
+ name: "Hana Wallet",
40
+ provider: (w) => w["hanaWallet"]?.stellar,
41
+ address: (p) => p["getPublicKey"](),
42
+ sign: (p, xdr, o) => p["signTransaction"]({ xdr, accountToSign: o.address, networkPassphrase: o.networkPassphrase })
43
+ },
44
+ {
45
+ id: "klever",
46
+ name: "Klever Wallet",
47
+ provider: (w) => w["kleverWallet"]?.stellar,
48
+ address: (p) => p["getAddress"](),
49
+ sign: positional
50
+ },
51
+ {
52
+ id: "onekey",
53
+ name: "OneKey Wallet",
54
+ provider: (w) => w["$onekey"]?.stellar,
55
+ address: (p) => p["getPublicKey"](),
56
+ sign: positional
57
+ },
58
+ {
59
+ id: "bitget",
60
+ name: "Bitget Wallet",
61
+ provider: (w) => w["bitkeep"]?.stellar,
62
+ address: (p) => p["connect"](),
63
+ sign: positional
64
+ },
65
+ {
66
+ id: "cactuslink",
67
+ name: "Cactus Link",
68
+ provider: (w) => w["cactuslink_stellar"],
69
+ address: (p) => withAccess(p, true),
70
+ sign: positional
71
+ },
72
+ {
73
+ id: "dcent",
74
+ name: "D'CENT Wallet",
75
+ // The extension and the in-app browser both mark themselves on `window.stellar`.
76
+ provider: (w) => w["stellar"]?.provider === "dcent" ? w["dcentStellarProvider"] : void 0,
77
+ // Its in-app browser has no access step and exposes the account directly.
78
+ address: (p) => withAccess(p, false),
79
+ sign: positional
80
+ },
81
+ {
82
+ id: "scopuly",
83
+ name: "Scopuly",
84
+ provider: (w) => w["scopuly"]?.isScopuly === true ? w["scopuly"] : void 0,
85
+ address: (p) => withAccess(p, true),
86
+ sign: positional
87
+ }
88
+ ];
89
+ function injectedWallet(spec, provider) {
90
+ const id = `stellar:${spec.id}`;
91
+ const run = async (work) => {
92
+ try {
93
+ return await work();
94
+ } catch (error) {
95
+ if (error instanceof WalletError) throw error;
96
+ throw new WalletError(spec.id, errorMessage(error), error);
97
+ }
98
+ };
99
+ return {
100
+ id,
101
+ name: spec.name,
102
+ ecosystem: "stellar",
103
+ connect: () => run(async () => pick(await spec.address(provider), ["address", "publicKey"])),
104
+ signTransaction: (xdr, options) => run(
105
+ async () => pick(
106
+ await spec.sign(provider, xdr, {
107
+ networkPassphrase: PASSPHRASES[options.network],
108
+ address: options.address
109
+ }),
110
+ ["signedTxXdr", "signedXDR", "signedTransaction"]
111
+ )
112
+ )
113
+ };
114
+ }
115
+ function discoverInjectedStellarWallets(win) {
116
+ if (!win) return [];
117
+ const globals = win;
118
+ const out = [];
119
+ for (const spec of INJECTED_STELLAR_WALLETS) {
120
+ let provider;
121
+ try {
122
+ provider = spec.provider(globals);
123
+ } catch {
124
+ provider = void 0;
125
+ }
126
+ if (provider && typeof provider === "object") out.push(injectedWallet(spec, provider));
127
+ }
128
+ return out;
129
+ }
130
+
131
+ // src/wallets/stellar.ts
132
+ var KIT_TO_ADAPTER = {
133
+ [COSMOS_WALLET_ID]: "cosmos",
134
+ // Freighter is now Varial: kit v2 lists it as `varial` (v1 as `freighter`).
135
+ varial: "freighter",
136
+ BitgetWallet: "bitget"
137
+ };
138
+ function networkConfig(network) {
139
+ return { network, passphrase: PASSPHRASES[network], horizonUrl: HORIZON_URLS[network] };
140
+ }
141
+ function fromAdapter(adapter, listed) {
142
+ return {
143
+ id: `stellar:${adapter.id}`,
144
+ // The kit follows wallets' branding (Freighter became Varial): its name and icon win.
145
+ name: listed?.name ?? adapter.name,
146
+ icon: listed?.icon ?? adapter.icon,
147
+ ecosystem: "stellar",
148
+ connect: (network) => adapter.getPublicKey(networkConfig(network)),
149
+ signTransaction: (xdr, options) => adapter.signTransaction(xdr, {
150
+ network: options.network,
151
+ networkPassphrase: PASSPHRASES[options.network],
152
+ address: options.address
153
+ })
154
+ };
155
+ }
156
+ function fromKit(kit, wallet) {
157
+ const id = `stellar:${wallet.id}`;
158
+ const run = async (work) => {
159
+ try {
160
+ kit.setWallet(wallet.id);
161
+ return await work();
162
+ } catch (error) {
163
+ if (error instanceof WalletError) throw error;
164
+ throw new WalletError(wallet.id, errorMessage(error), error);
165
+ }
166
+ };
167
+ return {
168
+ id,
169
+ name: wallet.name,
170
+ icon: wallet.icon,
171
+ ecosystem: "stellar",
172
+ connect: () => run(async () => (await (kit.fetchAddress ? kit.fetchAddress() : kit.getAddress())).address),
173
+ signTransaction: (xdr, options) => run(async () => {
174
+ const { signedTxXdr } = await kit.signTransaction(xdr, {
175
+ networkPassphrase: PASSPHRASES[options.network],
176
+ address: options.address
177
+ });
178
+ if (!signedTxXdr) throw new WalletError(wallet.id, "The wallet returned no signed transaction.");
179
+ return signedTxXdr;
180
+ })
181
+ };
182
+ }
183
+ async function availableAdapters(adapters, timeoutMs) {
184
+ const checks = await Promise.all(
185
+ adapters.map(async (adapter) => {
186
+ let timer;
187
+ const timeout = new Promise((resolve) => {
188
+ timer = setTimeout(() => resolve(false), timeoutMs);
189
+ });
190
+ try {
191
+ return await Promise.race([adapter.isAvailable(), timeout]) ? adapter : null;
192
+ } catch {
193
+ return null;
194
+ } finally {
195
+ clearTimeout(timer);
196
+ }
197
+ })
198
+ );
199
+ return checks.filter((adapter) => adapter !== null);
200
+ }
201
+ async function discoverStellarWallets(options = {}) {
202
+ const adapters = await availableAdapters(
203
+ options.adapters ?? defaultAdapters(options.injected),
204
+ options.availabilityTimeoutMs ?? 2500
205
+ );
206
+ let kitWallets = [];
207
+ const kit = options.kit;
208
+ if (kit) {
209
+ try {
210
+ kitWallets = await (kit.refreshSupportedWallets ? kit.refreshSupportedWallets() : kit.getSupportedWallets?.()) ?? [];
211
+ } catch {
212
+ kitWallets = [];
213
+ }
214
+ }
215
+ const byAdapter = new Map(
216
+ kitWallets.map((wallet) => [KIT_TO_ADAPTER[wallet.id] ?? wallet.id, wallet])
217
+ );
218
+ const wallets = adapters.map((adapter) => fromAdapter(adapter, byAdapter.get(adapter.id)));
219
+ const listed = new Set(adapters.map((adapter) => adapter.id));
220
+ if (options.injectedProviders !== false) {
221
+ const win = options.window ?? getWindow();
222
+ for (const wallet of discoverInjectedStellarWallets(win)) {
223
+ const key = wallet.id.slice("stellar:".length);
224
+ if (listed.has(key)) continue;
225
+ listed.add(key);
226
+ const listing = byAdapter.get(key);
227
+ wallets.push(listing ? { ...wallet, name: listing.name, icon: listing.icon ?? wallet.icon } : wallet);
228
+ }
229
+ }
230
+ for (const wallet of kitWallets) {
231
+ const adapterId = KIT_TO_ADAPTER[wallet.id] ?? wallet.id;
232
+ if (wallet.isAvailable === false || listed.has(adapterId) || !kit) continue;
233
+ listed.add(adapterId);
234
+ wallets.push(fromKit(kit, wallet));
235
+ }
236
+ return wallets;
237
+ }
238
+
239
+ // src/wallets/encoding.ts
240
+ function base64ToBytes(base64) {
241
+ const binary = atob(base64.trim());
242
+ const out = new Uint8Array(binary.length);
243
+ for (let i = 0; i < binary.length; i += 1) out[i] = binary.charCodeAt(i);
244
+ return out;
245
+ }
246
+ function bytesToBase64(bytes) {
247
+ let binary = "";
248
+ const chunk = 32768;
249
+ for (let i = 0; i < bytes.length; i += chunk) {
250
+ binary += String.fromCharCode(...bytes.subarray(i, i + chunk));
251
+ }
252
+ return btoa(binary);
253
+ }
254
+ var MAX_UINT256 = (1n << 256n) - 1n;
255
+ function uint256(value) {
256
+ if (value < 0n) throw new RangeError("An EVM amount cannot be negative");
257
+ if (value > MAX_UINT256) throw new RangeError("An EVM amount cannot exceed 2^256 - 1");
258
+ return value;
259
+ }
260
+ function toQuantity(value) {
261
+ if (typeof value === "string" && !/^0x[0-9a-fA-F]+$/.test(value) && !/^\d+$/.test(value)) {
262
+ throw new TypeError(`Not an amount of wei: "${value}"`);
263
+ }
264
+ if (typeof value === "number" && !Number.isSafeInteger(value)) {
265
+ throw new TypeError(`Not a safe integer amount of wei: ${value}`);
266
+ }
267
+ return `0x${uint256(BigInt(value)).toString(16)}`;
268
+ }
269
+ function erc20TransferData(to, amount) {
270
+ if (!/^0x[0-9a-fA-F]{40}$/.test(to)) throw new TypeError(`Not an EVM address: "${to}"`);
271
+ if (typeof amount === "string" && !/^\d+$/.test(amount)) {
272
+ throw new TypeError(`Not an amount in base units: "${amount}"`);
273
+ }
274
+ const value = uint256(typeof amount === "bigint" ? amount : BigInt(amount));
275
+ const word = (hex) => hex.padStart(64, "0");
276
+ return `0xa9059cbb${word(to.slice(2).toLowerCase())}${word(value.toString(16))}`;
277
+ }
278
+
279
+ // src/wallets/evm.ts
280
+ function isProvider(value) {
281
+ return !!value && typeof value.request === "function";
282
+ }
283
+ function errorCode(error) {
284
+ const e = error;
285
+ if (typeof e?.code === "number" && e.code !== -32603) return e.code;
286
+ const nested = e?.data?.originalError?.code;
287
+ if (typeof nested === "number") return nested;
288
+ return typeof e?.code === "number" ? e.code : void 0;
289
+ }
290
+ function legacyName(provider) {
291
+ if (provider["isRabby"]) return { id: "io.rabby", name: "Rabby" };
292
+ if (provider["isCoinbaseWallet"]) return { id: "com.coinbase.wallet", name: "Coinbase Wallet" };
293
+ if (provider["isBraveWallet"]) return { id: "com.brave.wallet", name: "Brave Wallet" };
294
+ if (provider["isOkxWallet"] || provider["isOKExWallet"]) return { id: "com.okex.wallet", name: "OKX Wallet" };
295
+ if (provider["isTrust"] || provider["isTrustWallet"]) return { id: "com.trustwallet.app", name: "Trust Wallet" };
296
+ if (provider["isMetaMask"]) return { id: "io.metamask", name: "MetaMask" };
297
+ return { id: "injected", name: "Browser wallet" };
298
+ }
299
+ var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
300
+ function evmWallet(provider, info) {
301
+ const walletId = `evm:${info.id}`;
302
+ const call = async (method, params) => {
303
+ try {
304
+ return await provider.request(params ? { method, params } : { method });
305
+ } catch (error) {
306
+ throw new WalletError(walletId, errorMessage(error), error);
307
+ }
308
+ };
309
+ const chainId = async () => Number(await call("eth_chainId"));
310
+ const switchChain = async (chain) => {
311
+ const id = typeof chain === "number" ? chain : chain.chainId;
312
+ const hex = `0x${id.toString(16)}`;
313
+ try {
314
+ await provider.request({ method: "wallet_switchEthereumChain", params: [{ chainId: hex }] });
315
+ } catch (error) {
316
+ if (errorCode(error) !== 4902) throw new WalletError(walletId, errorMessage(error), error);
317
+ if (typeof chain === "number") {
318
+ throw new WalletError(walletId, `The wallet does not know chain ${id}: pass its details to add it.`, error);
319
+ }
320
+ await call("wallet_addEthereumChain", [
321
+ {
322
+ chainId: hex,
323
+ chainName: chain.chainName,
324
+ nativeCurrency: chain.nativeCurrency,
325
+ rpcUrls: chain.rpcUrls,
326
+ ...chain.blockExplorerUrls ? { blockExplorerUrls: chain.blockExplorerUrls } : {}
327
+ }
328
+ ]);
329
+ }
330
+ };
331
+ return {
332
+ id: walletId,
333
+ name: info.name,
334
+ icon: info.icon,
335
+ rdns: info.rdns,
336
+ ecosystem: "evm",
337
+ provider,
338
+ async connect() {
339
+ const accounts = await call("eth_requestAccounts");
340
+ const account = accounts?.[0];
341
+ if (!account) throw new WalletError(walletId, "The wallet shared no account.");
342
+ return account;
343
+ },
344
+ chainId,
345
+ switchChain,
346
+ async sendTransaction(tx, chain) {
347
+ const target = tx.chainId ?? chain?.chainId;
348
+ if (target !== void 0 && await chainId() !== target) {
349
+ await switchChain(chain && chain.chainId === target ? chain : target);
350
+ }
351
+ const params = { from: tx.from, to: tx.to };
352
+ if (tx.data) params["data"] = tx.data;
353
+ if (tx.value !== void 0 && tx.value !== "0") params["value"] = toQuantity(tx.value);
354
+ if (tx.gas) params["gas"] = toQuantity(tx.gas);
355
+ if (tx.maxFeePerGas) params["maxFeePerGas"] = toQuantity(tx.maxFeePerGas);
356
+ if (tx.maxPriorityFeePerGas) params["maxPriorityFeePerGas"] = toQuantity(tx.maxPriorityFeePerGas);
357
+ const hash = await call("eth_sendTransaction", [params]);
358
+ if (typeof hash !== "string" || !/^0x[0-9a-fA-F]{64}$/.test(hash)) {
359
+ throw new WalletError(walletId, "The wallet returned no transaction hash.");
360
+ }
361
+ return hash;
362
+ },
363
+ async waitForTransaction(hash, options = {}) {
364
+ const deadline = Date.now() + (options.timeoutMs ?? 12e4);
365
+ const interval = options.intervalMs ?? 1500;
366
+ for (; ; ) {
367
+ const receipt = await call(
368
+ "eth_getTransactionReceipt",
369
+ [hash]
370
+ );
371
+ if (receipt && receipt.blockNumber) {
372
+ return {
373
+ hash,
374
+ status: receipt.status === "0x1" ? "success" : "reverted",
375
+ blockNumber: Number(receipt.blockNumber)
376
+ };
377
+ }
378
+ if (Date.now() >= deadline) {
379
+ throw new WalletError(walletId, `Transaction ${hash} was not mined in time.`);
380
+ }
381
+ await sleep(interval);
382
+ }
383
+ }
384
+ };
385
+ }
386
+ async function discoverEvmWallets(win, options = {}) {
387
+ if (!win) return [];
388
+ const found = /* @__PURE__ */ new Map();
389
+ const providers = /* @__PURE__ */ new Set();
390
+ const onAnnounce = (event) => {
391
+ const detail = event.detail;
392
+ if (!detail || !isProvider(detail.provider) || !detail.info?.name) return;
393
+ const key = detail.info.rdns || detail.info.uuid || detail.info.name;
394
+ if (found.has(key)) return;
395
+ providers.add(detail.provider);
396
+ found.set(
397
+ key,
398
+ evmWallet(detail.provider, {
399
+ id: key,
400
+ name: detail.info.name,
401
+ icon: detail.info.icon,
402
+ rdns: detail.info.rdns
403
+ })
404
+ );
405
+ };
406
+ win.addEventListener("eip6963:announceProvider", onAnnounce);
407
+ try {
408
+ win.dispatchEvent(new Event("eip6963:requestProvider"));
409
+ await sleep(options.timeoutMs ?? 200);
410
+ } finally {
411
+ win.removeEventListener("eip6963:announceProvider", onAnnounce);
412
+ }
413
+ const legacy = win.ethereum;
414
+ if (found.size === 0 && isProvider(legacy) && !providers.has(legacy)) {
415
+ const { id, name } = legacyName(legacy);
416
+ found.set(id, evmWallet(legacy, { id, name }));
417
+ }
418
+ return [...found.values()];
419
+ }
420
+
421
+ // src/wallets/solana.ts
422
+ var BASE58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
423
+ function bytesToBase58(bytes) {
424
+ const digits = [];
425
+ for (const byte of bytes) {
426
+ let carry = byte;
427
+ for (let i = 0; i < digits.length; i += 1) {
428
+ carry += digits[i] << 8;
429
+ digits[i] = carry % 58;
430
+ carry = Math.floor(carry / 58);
431
+ }
432
+ while (carry > 0) {
433
+ digits.push(carry % 58);
434
+ carry = Math.floor(carry / 58);
435
+ }
436
+ }
437
+ let out = "";
438
+ for (const byte of bytes) {
439
+ if (byte !== 0) break;
440
+ out += "1";
441
+ }
442
+ for (let i = digits.length - 1; i >= 0; i -= 1) out += BASE58[digits[i]];
443
+ return out;
444
+ }
445
+ var registries = /* @__PURE__ */ new WeakMap();
446
+ function registryOf(win) {
447
+ const existing = registries.get(win);
448
+ if (existing) return existing;
449
+ const registry = { wallets: /* @__PURE__ */ new Set() };
450
+ const api = {
451
+ register: (...wallets) => {
452
+ for (const wallet of wallets) registry.wallets.add(wallet);
453
+ return () => {
454
+ for (const wallet of wallets) registry.wallets.delete(wallet);
455
+ };
456
+ },
457
+ get: () => [...registry.wallets],
458
+ on: () => () => void 0
459
+ };
460
+ win.addEventListener("wallet-standard:register-wallet", (event) => {
461
+ const callback = event.detail;
462
+ if (typeof callback === "function") callback(api);
463
+ });
464
+ registries.set(win, registry);
465
+ win.dispatchEvent(detailEvent("wallet-standard:app-ready", api));
466
+ return registry;
467
+ }
468
+ function detailEvent(type, detail) {
469
+ if (typeof CustomEvent === "function") return new CustomEvent(type, { detail });
470
+ return Object.assign(new Event(type), { detail });
471
+ }
472
+ function slug(name) {
473
+ return name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "") || "wallet";
474
+ }
475
+ var isSolana = (wallet) => wallet.chains.some((chain) => chain.startsWith("solana:")) && !!wallet.features["standard:connect"] && (!!wallet.features["solana:signTransaction"] || !!wallet.features["solana:signAndSendTransaction"]);
476
+ function solanaWallet(wallet) {
477
+ const id = `solana:${slug(wallet.name)}`;
478
+ let account;
479
+ const fail = (error) => {
480
+ if (error instanceof WalletError) throw error;
481
+ throw new WalletError(id, errorMessage(error), error);
482
+ };
483
+ const ensureAccount = async () => {
484
+ if (account) return account;
485
+ const connect = wallet.features["standard:connect"];
486
+ const { accounts } = await connect.connect();
487
+ account = accounts[0] ?? wallet.accounts[0];
488
+ if (!account) throw new WalletError(id, "The wallet shared no account.");
489
+ return account;
490
+ };
491
+ const signAndSend = wallet.features["solana:signAndSendTransaction"];
492
+ return {
493
+ id,
494
+ name: wallet.name,
495
+ icon: wallet.icon,
496
+ ecosystem: "solana",
497
+ chains: wallet.chains,
498
+ canSignAndSend: !!signAndSend,
499
+ async connect() {
500
+ try {
501
+ account = void 0;
502
+ return (await ensureAccount()).address;
503
+ } catch (error) {
504
+ return fail(error);
505
+ }
506
+ },
507
+ async signTransaction(transaction, chain = "solana:mainnet") {
508
+ try {
509
+ const feature = wallet.features["solana:signTransaction"];
510
+ if (!feature) throw new WalletError(id, "This wallet can only sign and send in one step.");
511
+ const signer = await ensureAccount();
512
+ const [output] = await feature.signTransaction({
513
+ account: signer,
514
+ transaction: base64ToBytes(transaction),
515
+ chain
516
+ });
517
+ if (!output?.signedTransaction) throw new WalletError(id, "The wallet returned no signed transaction.");
518
+ return bytesToBase64(output.signedTransaction);
519
+ } catch (error) {
520
+ return fail(error);
521
+ }
522
+ },
523
+ async signAndSendTransaction(transaction, chain = "solana:mainnet") {
524
+ try {
525
+ if (!signAndSend) throw new WalletError(id, "This wallet cannot send a transaction.");
526
+ const signer = await ensureAccount();
527
+ const [output] = await signAndSend.signAndSendTransaction({
528
+ account: signer,
529
+ transaction: base64ToBytes(transaction),
530
+ chain
531
+ });
532
+ if (!output?.signature) throw new WalletError(id, "The wallet returned no signature.");
533
+ return bytesToBase58(output.signature);
534
+ } catch (error) {
535
+ return fail(error);
536
+ }
537
+ }
538
+ };
539
+ }
540
+ function discoverSolanaWallets(win) {
541
+ if (!win) return [];
542
+ const seen = /* @__PURE__ */ new Set();
543
+ const out = [];
544
+ for (const wallet of registryOf(win).wallets) {
545
+ if (!isSolana(wallet)) continue;
546
+ const descriptor = solanaWallet(wallet);
547
+ if (seen.has(descriptor.id)) continue;
548
+ seen.add(descriptor.id);
549
+ out.push(descriptor);
550
+ }
551
+ return out;
552
+ }
553
+
554
+ // src/wallets/eip681.ts
555
+ var ADDRESS = /^0x[0-9a-fA-F]{40}$/;
556
+ function parseEip681(uri) {
557
+ const match = /^ethereum:(?:pay-)?(0x[0-9a-fA-F]{40})(?:@(\d+))?(?:\/([A-Za-z_]\w*))?(?:\?(.*))?$/.exec(
558
+ uri.trim()
559
+ );
560
+ if (!match) throw new TypeError("Not an EIP-681 payment link");
561
+ const [, target = "", chain, fn, query = ""] = match;
562
+ const params = new URLSearchParams(query);
563
+ const chainId = chain ? Number(chain) : 1;
564
+ if (!Number.isSafeInteger(chainId) || chainId <= 0) throw new TypeError("Not a valid chain id");
565
+ if (!fn) {
566
+ const value = params.get("value");
567
+ return { chainId, to: target, ...value ? { value: toQuantity(plainInteger(value)) } : {} };
568
+ }
569
+ if (fn !== "transfer") throw new TypeError(`Unsupported EIP-681 function: ${fn}`);
570
+ const recipient = params.get("address") ?? "";
571
+ const amount = params.get("uint256");
572
+ if (!ADDRESS.test(recipient)) throw new TypeError("The link names no recipient address");
573
+ if (!amount) throw new TypeError("The link names no amount");
574
+ return { chainId, to: target, data: erc20TransferData(recipient, plainInteger(amount)) };
575
+ }
576
+ function plainInteger(value) {
577
+ if (/^\d+$/.test(value)) return value;
578
+ const sci = /^(\d+)(?:\.(\d+))?e(\d+)$/i.exec(value);
579
+ if (sci) {
580
+ const [, whole = "", fraction = "", exponent = "0"] = sci;
581
+ const shift = Number(exponent);
582
+ if (fraction.length <= shift) return (whole + fraction.padEnd(shift, "0")).replace(/^0+(?=\d)/, "");
583
+ }
584
+ throw new TypeError(`Not an integer amount: "${value}"`);
585
+ }
586
+
587
+ // src/wallets/index.ts
588
+ var EvmChains = {
589
+ monad: {
590
+ chainId: 143,
591
+ chainName: "Monad",
592
+ nativeCurrency: { name: "Monad", symbol: "MON", decimals: 18 },
593
+ rpcUrls: ["https://rpc.monad.xyz"],
594
+ blockExplorerUrls: ["https://monadscan.com"]
595
+ },
596
+ monadTestnet: {
597
+ chainId: 10143,
598
+ chainName: "Monad Testnet",
599
+ nativeCurrency: { name: "Monad", symbol: "MON", decimals: 18 },
600
+ rpcUrls: ["https://testnet-rpc.monad.xyz"],
601
+ blockExplorerUrls: ["https://testnet.monadexplorer.com"]
602
+ }
603
+ };
604
+ async function discoverWallets(options = {}) {
605
+ const want = new Set(options.ecosystems ?? ["stellar", "evm", "solana"]);
606
+ const win = options.window ?? getWindow();
607
+ const [stellar, evm] = await Promise.all([
608
+ want.has("stellar") ? discoverStellarWallets({ window: win, ...options.stellar }) : Promise.resolve([]),
609
+ want.has("evm") ? discoverEvmWallets(win, { timeoutMs: options.timeoutMs }) : Promise.resolve([])
610
+ ]);
611
+ const solana = want.has("solana") ? discoverSolanaWallets(win) : [];
612
+ return { stellar, evm, solana };
613
+ }
614
+ function isUserRejection(error) {
615
+ const seen = /* @__PURE__ */ new Set();
616
+ let current = error;
617
+ while (current && typeof current === "object" && !seen.has(current)) {
618
+ seen.add(current);
619
+ const e = current;
620
+ if (e.code === 4001 || e.code === "ACTION_REJECTED") return true;
621
+ if (typeof e.message === "string" && /reject|declin|denied|cancel/i.test(e.message)) return true;
622
+ current = e.cause;
623
+ }
624
+ return typeof error === "string" && /reject|declin|denied|cancel/i.test(error);
625
+ }
626
+
627
+ export { EvmChains, INJECTED_STELLAR_WALLETS, base64ToBytes, bytesToBase58, bytesToBase64, discoverEvmWallets, discoverInjectedStellarWallets, discoverSolanaWallets, discoverStellarWallets, discoverWallets, erc20TransferData, evmWallet, isUserRejection, parseEip681, solanaWallet, toQuantity };
628
+ //# sourceMappingURL=index.js.map
629
+ //# sourceMappingURL=index.js.map