@cosmosapp/pay_sdk 1.2.1 → 2.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  All notable changes to @cosmosapp/pay_sdk are documented here.
4
4
  Generated from [Conventional Commits](https://www.conventionalcommits.org) by [git-cliff](https://git-cliff.org).
5
+ ## [2.0.0] - 2026-09-16
6
+
7
+ ### Features
8
+ - Follow the payments API security contract changes (0e9ba8b)
9
+ - Update PollarManager documentation to clarify session handling and user registration requirements (d80aa11)
10
+ - Add dossierVersion and reviewedVersion to Receiver class and update approval logic (14689d1)
11
+
12
+ ### Miscellaneous
13
+ - Bump @types/node in the minor-and-patch group across 1 directory (#7) (9a22af8)
14
+ - Bump @types/node in the minor-and-patch group (#9) (6a0dfe6)
15
+ - Relicense the SDK to Apache-2.0 (9653c3b)
16
+ - Bump @types/node in the minor-and-patch group (65f6819)
17
+
5
18
  ## [1.2.1] - 2026-08-19
6
19
 
7
20
  ### Bug Fixes
package/LICENSE CHANGED
@@ -1,78 +1,3 @@
1
- Cosmos Pay Source-Available License
2
- Version 1.0
3
-
4
- Copyright (c) 2026 Cosmos Pay
5
-
6
- This software is "source available." You may use it freely — including in
7
- commercial products and services — subject to the terms below. It is licensed
8
- under the Apache License, Version 2.0 (the "Apache License", reproduced in full
9
- below), AS MODIFIED by the two Additional Restrictions set out in this preamble.
10
-
11
- In case of any conflict between the Additional Restrictions and the Apache
12
- License, the Additional Restrictions control. Every copy or substantial portion
13
- of the software must retain this preamble (both Additional Restrictions) together
14
- with the Apache License text.
15
-
16
- ================================================================================
17
- Additional Restriction 1 — No Resale Without Modification ("Commons Clause")
18
- ================================================================================
19
-
20
- The license granted under the Apache License does not include, and this
21
- Additional Restriction removes, the right to Sell the Software.
22
-
23
- "Sell" means practicing any or all of the rights granted to you under the Apache
24
- License to provide to third parties, for a fee or other consideration (including
25
- without limitation fees for hosting, support, or consulting services related to
26
- the Software), a product or service whose value derives, entirely or
27
- substantially, from the functionality of the Software in its original or
28
- substantially unmodified form.
29
-
30
- For clarity:
31
-
32
- - You MAY use the Software, free of charge, in your own commercial and
33
- non-commercial projects.
34
- - You MAY build, sell, and operate products and services that include or are
35
- built on top of the Software, provided your product or service adds
36
- substantial independent value beyond the Software's own functionality.
37
- - You MAY modify the Software and distribute your modifications under these
38
- same terms.
39
- - You MAY NOT resell or redistribute the Software substantially as-is (whether
40
- standalone, rebranded, or as a hosted/managed offering) as your product or
41
- service.
42
-
43
- "Software" means the work of authorship made available under this license.
44
-
45
- ================================================================================
46
- Additional Restriction 2 — Acceptable Use (No Malicious Use)
47
- ================================================================================
48
-
49
- You may not use the Software:
50
-
51
- (a) to commit, facilitate, or conceal any unlawful, fraudulent, or deceptive
52
- activity;
53
- (b) to harm, defraud, or steal from any person, including the theft or
54
- unauthorized movement of funds, assets, or credentials;
55
- (c) to develop, distribute, or operate malware, ransomware, phishing,
56
- scams, or other malicious software or schemes; or
57
- (d) in any manner that violates applicable law or infringes the human rights
58
- of others.
59
-
60
- Your rights under this license terminate automatically and immediately if you
61
- breach this Additional Restriction.
62
-
63
- ================================================================================
64
- NOTE ON OPEN SOURCE
65
- ================================================================================
66
-
67
- Because of the Additional Restrictions above, this license is "source available"
68
- and is NOT an Open Source license as defined by the Open Source Initiative, nor
69
- "Free Software" as defined by the Free Software Foundation. Aside from those
70
- Additional Restrictions, the terms of the Apache License, Version 2.0 apply.
71
-
72
- ================================================================================
73
- Apache License, Version 2.0
74
- ================================================================================
75
-
76
1
  Apache License
77
2
  Version 2.0, January 2004
78
3
  http://www.apache.org/licenses/
package/NOTICE ADDED
@@ -0,0 +1,8 @@
1
+ Cosmos Pay JavaScript SDK (@cosmosapp/pay_sdk)
2
+ Copyright 2026 Cosmos Pay
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
package/README.md CHANGED
@@ -11,7 +11,7 @@ Stellar **SEP-7 payment intents** · **webhooks** · **products** · **customers
11
11
  [![npm downloads](https://img.shields.io/npm/dm/@cosmosapp/pay_sdk?style=flat-square&color=7c3aed)](https://www.npmjs.com/package/@cosmosapp/pay_sdk)
12
12
  [![types](https://img.shields.io/npm/types/@cosmosapp/pay_sdk?style=flat-square&color=3178c6)](https://www.npmjs.com/package/@cosmosapp/pay_sdk)
13
13
  [![node](https://img.shields.io/node/v/@cosmosapp/pay_sdk?style=flat-square&color=339933)](https://nodejs.org)
14
- [![license](https://img.shields.io/badge/license-Source--Available-22c55e?style=flat-square)](./LICENSE)
14
+ [![license](https://img.shields.io/badge/license-Apache_2.0-blue?style=flat-square)](./LICENSE)
15
15
 
16
16
  </div>
17
17
 
@@ -706,17 +706,12 @@ pushing unrelated commits is always safe. Packages ship with
706
706
 
707
707
  ## 📄 License
708
708
 
709
- **Cosmos Pay Source-Available License** — see [`LICENSE`](./LICENSE).
710
-
711
- It's based on the **Apache License 2.0** with two additional restrictions, so in short:
709
+ **[Apache License 2.0](./LICENSE)** — a permissive, OSI-approved open-source license. In short:
712
710
 
713
711
  - ✅ **Free to use**, including in **commercial** products and services.
714
- - ✅ **Modify and distribute** your changes under the same terms.
715
- - ❌ **No reselling the SDK as-is** — you can't redistribute or host it substantially
716
- unmodified as your own product/service (Commons Clause). Building real products *on top of* it is
717
- fine.
718
- - ❌ **No malicious use** — no fraud, theft, malware/phishing, or uses that break the law or
719
- violate others' rights.
720
-
721
- > Because of those restrictions this is a **source-available** license, not an OSI-approved
722
- > "open source" one. This is not legal advice.
712
+ - ✅ **Modify, distribute and sublicense** — you may even sell it.
713
+ - ✅ **Explicit patent grant** from contributors, with patent-retaliation protection.
714
+ - ℹ️ When you redistribute, keep the [`LICENSE`](./LICENSE) + [`NOTICE`](./NOTICE) and note any
715
+ significant changes you made.
716
+
717
+ > This is not legal advice.
@@ -0,0 +1,62 @@
1
+ // src/web/cosmosProvider.ts
2
+ var PROVIDER_FILE = "cosmos-wallet.js";
3
+ var DEFAULT_LOAD_TIMEOUT_MS = 15e3;
4
+ function browserWindow() {
5
+ return typeof window !== "undefined" ? window : void 0;
6
+ }
7
+ function injectedProvider() {
8
+ const win = browserWindow();
9
+ const provider = win?.["cosmosWallet"];
10
+ return provider && typeof provider === "object" ? provider : void 0;
11
+ }
12
+ var loads = /* @__PURE__ */ new Map();
13
+ function loadHostedProvider(walletUrl, timeoutMs = DEFAULT_LOAD_TIMEOUT_MS) {
14
+ const existing = injectedProvider();
15
+ if (existing) return Promise.resolve(existing);
16
+ const win = browserWindow();
17
+ if (!win || typeof document === "undefined") return Promise.resolve(void 0);
18
+ const origin = walletUrl.replace(/\/+$/, "");
19
+ const cached = loads.get(origin);
20
+ if (cached) return cached;
21
+ const pending = new Promise((resolve) => {
22
+ const src = `${origin}/${PROVIDER_FILE}`;
23
+ const done = (value) => {
24
+ clearTimeout(timer);
25
+ resolve(value);
26
+ };
27
+ const timer = setTimeout(() => done(injectedProvider()), timeoutMs);
28
+ const existingTag = document.querySelector(`script[src="${src}"]`);
29
+ if (existingTag) {
30
+ const found = injectedProvider();
31
+ if (found) return done(found);
32
+ existingTag.addEventListener("load", () => done(injectedProvider()), { once: true });
33
+ existingTag.addEventListener("error", () => done(void 0), { once: true });
34
+ return;
35
+ }
36
+ const tag = document.createElement("script");
37
+ tag.src = src;
38
+ tag.async = true;
39
+ tag.addEventListener("load", () => done(injectedProvider()), { once: true });
40
+ tag.addEventListener("error", () => done(void 0), { once: true });
41
+ (document.head ?? document.documentElement).appendChild(tag);
42
+ });
43
+ loads.set(origin, pending);
44
+ void pending.then((provider) => {
45
+ if (!provider) loads.delete(origin);
46
+ });
47
+ return pending;
48
+ }
49
+ async function resolveProvider(options = {}) {
50
+ if (options.provider) return options.provider;
51
+ const injected = injectedProvider();
52
+ if (injected) return injected;
53
+ if (!options.walletUrl) return void 0;
54
+ return loadHostedProvider(options.walletUrl, options.loadTimeoutMs);
55
+ }
56
+ function resetProviderCache() {
57
+ loads.clear();
58
+ }
59
+
60
+ export { injectedProvider, loadHostedProvider, resetProviderCache, resolveProvider };
61
+ //# sourceMappingURL=chunk-AYVWYEOK.js.map
62
+ //# sourceMappingURL=chunk-AYVWYEOK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/web/cosmosProvider.ts"],"names":[],"mappings":";AAwEA,IAAM,aAAA,GAAgB,kBAAA;AACtB,IAAM,uBAAA,GAA0B,IAAA;AAGhC,SAAS,aAAA,GAA0D;AACjE,EAAA,OAAO,OAAO,MAAA,KAAW,WAAA,GAAc,MAAA,GAAS,MAAA;AAClD;AAGO,SAAS,gBAAA,GAAqD;AACnE,EAAA,MAAM,MAAM,aAAA,EAAc;AAC1B,EAAA,MAAM,QAAA,GAAW,MAAM,cAAc,CAAA;AACrC,EAAA,OAAO,QAAA,IAAY,OAAO,QAAA,KAAa,QAAA,GAAY,QAAA,GAAoC,MAAA;AACzF;AAGA,IAAM,KAAA,uBAAY,GAAA,EAAuD;AAQlE,SAAS,kBAAA,CACd,SAAA,EACA,SAAA,GAAoB,uBAAA,EACuB;AAC3C,EAAA,MAAM,WAAW,gBAAA,EAAiB;AAClC,EAAA,IAAI,QAAA,EAAU,OAAO,OAAA,CAAQ,OAAA,CAAQ,QAAQ,CAAA;AAE7C,EAAA,MAAM,MAAM,aAAA,EAAc;AAC1B,EAAA,IAAI,CAAC,OAAO,OAAO,QAAA,KAAa,aAAa,OAAO,OAAA,CAAQ,QAAQ,MAAS,CAAA;AAE7E,EAAA,MAAM,MAAA,GAAS,SAAA,CAAU,OAAA,CAAQ,MAAA,EAAQ,EAAE,CAAA;AAC3C,EAAA,MAAM,MAAA,GAAS,KAAA,CAAM,GAAA,CAAI,MAAM,CAAA;AAC/B,EAAA,IAAI,QAAQ,OAAO,MAAA;AAEnB,EAAA,MAAM,OAAA,GAAU,IAAI,OAAA,CAA0C,CAAC,OAAA,KAAY;AACzE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AA,CAAS,IAAA,IAAQ,QAAA,CAAS,eAAA,EAAiB,YAAY,GAAG,CAAA;AAAA,EAC7D,CAAC,CAAA;AAKD,EAAA,KAAA,CAAM,GAAA,CAAI,QAAQ,OAAO,CAAA;AACzB,EAAA,KAAK,OAAA,CAAQ,IAAA,CAAK,CAAC,QAAA,KAAa;AAC9B,IAAA,IAAI,CAAC,QAAA,EAAU,KAAA,CAAM,MAAA,CAAO,MAAM,CAAA;AAAA,EACpC,CAAC,CAAA;AACD,EAAA,OAAO,OAAA;AACT;AAMA,eAAsB,eAAA,CACpB,OAAA,GAAiC,EAAC,EACS;AAC3C,EAAA,IAAI,OAAA,CAAQ,QAAA,EAAU,OAAO,OAAA,CAAQ,QAAA;AACrC,EAAA,MAAM,WAAW,gBAAA,EAAiB;AAClC,EAAA,IAAI,UAAU,OAAO,QAAA;AACrB,EAAA,IAAI,CAAC,OAAA,CAAQ,SAAA,EAAW,OAAO,MAAA;AAC/B,EAAA,OAAO,kBAAA,CAAmB,OAAA,CAAQ,SAAA,EAAW,OAAA,CAAQ,aAAa,CAAA;AACpE;AAGO,SAAS,kBAAA,GAA2B;AACzC,EAAA,KAAA,CAAM,KAAA,EAAM;AACd","file":"chunk-AYVWYEOK.js","sourcesContent":["/**\n * Reaching Cosmos Wallet, over either of the two transports it ships.\n *\n * Cosmos Pay's own wallet exposes a SEP-43-shaped provider on `window.cosmosWallet`,\n * and it gets there two different ways:\n *\n * extension the browser extension's content script injects it at document start,\n * so the global is simply there — nothing to configure.\n * hosted the wallet also runs as a plain web page, and a site opts in by\n * loading `<wallet origin>/cosmos-wallet.js`. Each call then opens the\n * wallet's own approval window. Nothing is installed.\n *\n * One module for both, because everything above the provider — the SDK's wallet\n * adapter and the Stellar Wallets Kit module — cares about the same five methods\n * and not at all about how they arrived.\n *\n * WHY THE SCRIPT IS LOADED ONCE AND MEMOISED AS A PROMISE: `isAvailable()` and\n * `getAddress()` can be called in the same tick (a kit rendering its modal does\n * exactly that), and two `<script>` tags for one provider is a race whose loser\n * silently wins — the second load finds `window.cosmosWallet` already defined and\n * bails, and whichever promise settles last is the one the caller reads.\n */\n\n/** The provider surface this SDK uses. A superset lives on the real object. */\nexport interface CosmosWalletProvider {\n /** Marker the wallet sets on its own provider. */\n isCosmosWallet?: boolean;\n /** `'web'` on the hosted build; absent on the extension's provider. */\n transport?: string;\n isConnected?(): Promise<boolean>;\n getAddress(): Promise<{\n address: string;\n network?: string;\n networkPassphrase?: string;\n networkUrl?: string;\n }>;\n getNetwork(): Promise<{ network: string; networkPassphrase: string; networkUrl?: string }>;\n signTransaction(\n xdr: string,\n opts?: { networkPassphrase?: string; address?: string },\n ): Promise<{ signedTxXdr: string; signerAddress?: string }>;\n signMessage(\n message: string,\n opts?: { networkPassphrase?: string; address?: string },\n ): Promise<{ signedMessage: string; signerAddress?: string; domain?: string }>;\n /** SEP-7 `web+stellar:pay…` — the wallet builds, signs and submits it. */\n requestPayment?(uri: string): Promise<{ hash: string; signerAddress?: string }>;\n}\n\n/** How to find the provider. Everything is optional: an extension needs nothing. */\nexport interface CosmosProviderOptions {\n /**\n * A provider object supplied by the host (tests, or an app that already holds\n * one). Wins over everything else and is never probed for.\n */\n provider?: CosmosWalletProvider;\n /**\n * Origin of a hosted Cosmos Wallet — e.g. `https://wallet.cosmospay.lat`. Set it\n * to support users who have not installed the extension: the provider script is\n * pulled from that origin on first use, and signing happens in the wallet's own\n * window on its own origin. Leave it unset to require the extension.\n */\n walletUrl?: string;\n /**\n * How long to wait for that script, in ms. The kit gives a module 1000ms to answer\n * `isAvailable()`, which is why availability never waits for this — see\n * `CosmosWalletModule`.\n */\n loadTimeoutMs?: number;\n}\n\n/** File the hosted wallet serves its provider from, relative to the wallet origin. */\nconst PROVIDER_FILE = 'cosmos-wallet.js';\nconst DEFAULT_LOAD_TIMEOUT_MS = 15_000;\n\n/** The window, or undefined outside a browser (SSR-safe). */\nfunction browserWindow(): (Window & typeof globalThis) | undefined {\n return typeof window !== 'undefined' ? window : undefined;\n}\n\n/** The provider the extension injected, if any. Never throws, never loads. */\nexport function injectedProvider(): CosmosWalletProvider | undefined {\n const win = browserWindow() as unknown as Record<string, unknown> | undefined;\n const provider = win?.['cosmosWallet'];\n return provider && typeof provider === 'object' ? (provider as CosmosWalletProvider) : undefined;\n}\n\n/** One in-flight load per wallet origin, shared by every caller. */\nconst loads = new Map<string, Promise<CosmosWalletProvider | undefined>>();\n\n/**\n * Load the hosted wallet's provider script from `walletUrl` and resolve with the\n * provider it defines. Resolves `undefined` rather than throwing when there is no\n * document, no URL, or the script never arrives: \"no wallet\" is an answer every\n * caller here already has to handle.\n */\nexport function loadHostedProvider(\n walletUrl: string,\n timeoutMs: number = DEFAULT_LOAD_TIMEOUT_MS,\n): Promise<CosmosWalletProvider | undefined> {\n const existing = injectedProvider();\n if (existing) return Promise.resolve(existing);\n\n const win = browserWindow();\n if (!win || typeof document === 'undefined') return Promise.resolve(undefined);\n\n const origin = walletUrl.replace(/\\/+$/, '');\n const cached = loads.get(origin);\n if (cached) return cached;\n\n const pending = new Promise<CosmosWalletProvider | undefined>((resolve) => {\n const src = `${origin}/${PROVIDER_FILE}`;\n const done = (value: CosmosWalletProvider | undefined) => {\n clearTimeout(timer);\n resolve(value);\n };\n const timer = setTimeout(() => done(injectedProvider()), timeoutMs);\n\n // A tag for this exact src may already be on the page — the site can ship it\n // itself, which is the documented integration. Reuse it instead of adding a\n // second one; `onload` on an already-loaded script never fires, so the\n // provider is read directly in that case.\n const existingTag = document.querySelector<HTMLScriptElement>(`script[src=\"${src}\"]`);\n if (existingTag) {\n const found = injectedProvider();\n if (found) return done(found);\n existingTag.addEventListener('load', () => done(injectedProvider()), { once: true });\n existingTag.addEventListener('error', () => done(undefined), { once: true });\n return;\n }\n\n const tag = document.createElement('script');\n tag.src = src;\n tag.async = true;\n tag.addEventListener('load', () => done(injectedProvider()), { once: true });\n tag.addEventListener('error', () => done(undefined), { once: true });\n (document.head ?? document.documentElement).appendChild(tag);\n });\n\n // Not cached on failure: a wallet origin that was down once should be retried,\n // and a memoised `undefined` would make the wallet permanently unavailable for\n // the life of the page.\n loads.set(origin, pending);\n void pending.then((provider) => {\n if (!provider) loads.delete(origin);\n });\n return pending;\n}\n\n/**\n * The provider to act on: the injected one, the host's, or the hosted build's —\n * in that order. `undefined` when Cosmos Wallet cannot be reached at all.\n */\nexport async function resolveProvider(\n options: CosmosProviderOptions = {},\n): Promise<CosmosWalletProvider | undefined> {\n if (options.provider) return options.provider;\n const injected = injectedProvider();\n if (injected) return injected;\n if (!options.walletUrl) return undefined;\n return loadHostedProvider(options.walletUrl, options.loadTimeoutMs);\n}\n\n/** Forget memoised loads. Exposed for tests; harmless in an app. */\nexport function resetProviderCache(): void {\n loads.clear();\n}\n"]}
@@ -145,7 +145,7 @@ function resolveIntentBody(options, book = addresses) {
145
145
  }
146
146
 
147
147
  // src/util/Constants.ts
148
- var version = "1.2.1";
148
+ var version = "2.0.0";
149
149
  var DEFAULT_BASE_URL = "https://api.cosmospay.lat/cosmos-api";
150
150
  var DEFAULT_VERSION = "v1";
151
151
  var DEFAULT_TIMEOUT = 3e4;
@@ -204,6 +204,8 @@ var CosmosPayRequestError = class _CosmosPayRequestError extends Error {
204
204
 
205
205
  // src/common/wallets.ts
206
206
  var Wallets = {
207
+ /** Cosmos Pay's own wallet — extension, or the hosted build (see CosmosWalletAdapter). */
208
+ COSMOS: "cosmos",
207
209
  FREIGHTER: "freighter",
208
210
  XBULL: "xbull",
209
211
  RABET: "rabet",
@@ -212,5 +214,5 @@ var Wallets = {
212
214
  };
213
215
 
214
216
  export { AddressBook, Assets, CosmosPayAPIError, CosmosPayRequestError, DEFAULT_BASE_URL, DEFAULT_RETRIES, DEFAULT_TIMEOUT, DEFAULT_VERSION, Events, SIGNATURE_HEADER, TestnetAssets, Wallets, addresses, assertAddress, defineAsset, isAddress, isContractAddress, isMuxedAddress, isNativeAsset, isStellarAddress, resolveAddress, resolveAsset, resolveIntentBody, version };
215
- //# sourceMappingURL=chunk-KZNJR223.js.map
216
- //# sourceMappingURL=chunk-KZNJR223.js.map
217
+ //# sourceMappingURL=chunk-TM4HAKWE.js.map
218
+ //# sourceMappingURL=chunk-TM4HAKWE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/common/addresses.ts","../src/common/assets.ts","../src/common/intent-input.ts","../src/util/Constants.ts","../src/errors/CosmosPayError.ts","../src/common/wallets.ts"],"names":[],"mappings":";AAWA,IAAM,SAAA,GAAY,iBAAA;AAClB,IAAM,SAAA,GAAY,iBAAA;AAClB,IAAM,SAAA,GAAY,iBAAA;AAGX,SAAS,iBAAiB,KAAA,EAAiC;AAChE,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,SAAA,CAAU,KAAK,KAAK,CAAA;AAC1D;AAGO,SAAS,eAAe,KAAA,EAAiC;AAC9D,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,SAAA,CAAU,KAAK,KAAK,CAAA;AAC1D;AAGO,SAAS,kBAAkB,KAAA,EAAiC;AACjE,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,SAAA,CAAU,KAAK,KAAK,CAAA;AAC1D;AAGO,SAAS,UAAU,KAAA,EAAiC;AACzD,EAAA,OAAO,iBAAiB,KAAK,CAAA,IAAK,eAAe,KAAK,CAAA,IAAK,kBAAkB,KAAK,CAAA;AACpF;AAGO,SAAS,aAAA,CAAc,KAAA,EAAgB,KAAA,GAAQ,SAAA,EAAmB;AACvE,EAAA,IAAI,CAAC,SAAA,CAAU,KAAK,CAAA,EAAG;AACrB,IAAA,MAAM,IAAI,UAAU,CAAA,gBAAA,EAAmB,KAAK,KAAK,MAAA,CAAO,KAAK,CAAC,CAAA,CAAE,CAAA;AAAA,EAClE;AACA,EAAA,OAAO,KAAA;AACT;AAWO,IAAM,cAAN,MAAkB;AAAA,EAGvB,WAAA,CAAY,OAAA,GAAkC,EAAC,EAAG;AAFlD,IAAA,IAAA,CAAiB,OAAA,uBAAc,GAAA,EAAoB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ACT;AACF;AAMO,IAAM,qBAAA,GAAN,MAAM,sBAAA,SAA8B,KAAA,CAAM;AAAA,EAK/C,YAAY,OAAA,EAA0D;AACpE,IAAA,MAAM,MAAA,GACJ,QAAQ,KAAA,YAAiB,KAAA,GAAQ,QAAQ,KAAA,CAAM,OAAA,GAAU,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA;AAC/E,IAAA,KAAA,CAAM,CAAA,WAAA,EAAc,QAAQ,MAAM,CAAA,CAAA,EAAI,QAAQ,GAAG,CAAA,SAAA,EAAY,MAAM,CAAA,CAAE,CAAA;AACrE,IAAA,IAAA,CAAK,IAAA,GAAO,uBAAA;AACZ,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,MAAA;AACtB,IAAA,IAAA,CAAK,MAAM,OAAA,CAAQ,GAAA;AACnB,IAAA,IAAA,CAAK,QAAQ,OAAA,CAAQ,KAAA;AACrB,IAAA,KAAA,CAAM,iBAAA,GAAoB,MAAM,sBAAqB,CAAA;AAAA,EACvD;AACF;;;ACpEO,IAAM,OAAA,GAAU;AAAA;AAAA,EAErB,MAAA,EAAQ,QAAA;AAAA,EACR,SAAA,EAAW,WAAA;AAAA,EACX,KAAA,EAAO,OAAA;AAAA,EACP,KAAA,EAAO,OAAA;AAAA,EACP,MAAA,EAAQ,QAAA;AAAA,EACR,MAAA,EAAQ;AACV","file":"chunk-TM4HAKWE.js","sourcesContent":["/**\n * Stellar address helpers + a tiny named-address book.\n *\n * So integrators don't have to sprinkle raw `G...` strings everywhere (and risk\n * typos), they can name the accounts they care about once and reference them by\n * name. A plain address string always keeps working — `resolveAddress` only\n * substitutes registered names and otherwise passes the value straight through.\n */\n\n// Stellar strkeys are base32 (RFC 4648 alphabet, no padding). These checks are\n// length/prefix sanity checks, not full checksum validation.\nconst G_ADDRESS = /^G[A-Z2-7]{55}$/; // ed25519 public key (account)\nconst M_ADDRESS = /^M[A-Z2-7]{68}$/; // muxed account\nconst C_ADDRESS = /^C[A-Z2-7]{55}$/; // contract id\n\n/** Whether a value looks like a Stellar account address (`G…`). */\nexport function isStellarAddress(value: unknown): value is string {\n return typeof value === 'string' && G_ADDRESS.test(value);\n}\n\n/** Whether a value looks like a muxed account address (`M…`). */\nexport function isMuxedAddress(value: unknown): value is string {\n return typeof value === 'string' && M_ADDRESS.test(value);\n}\n\n/** Whether a value looks like a Soroban contract id (`C…`). */\nexport function isContractAddress(value: unknown): value is string {\n return typeof value === 'string' && C_ADDRESS.test(value);\n}\n\n/** Whether a value is any kind of Stellar address (account, muxed or contract). */\nexport function isAddress(value: unknown): value is string {\n return isStellarAddress(value) || isMuxedAddress(value) || isContractAddress(value);\n}\n\n/** Throw unless `value` is a valid Stellar account/muxed/contract address. */\nexport function assertAddress(value: unknown, label = 'address'): string {\n if (!isAddress(value)) {\n throw new TypeError(`Invalid Stellar ${label}: ${String(value)}`);\n }\n return value;\n}\n\n/**\n * A registry of named Stellar addresses. Register the accounts you use a lot —\n * your merchant payout account, a treasury, frequent counterparties — and refer\n * to them by name anywhere an address is accepted.\n *\n * @example\n * addresses.define('merchant', 'GC...');\n * await client.paymentIntents.createPay({ destination: 'merchant', amount: '10' });\n */\nexport class AddressBook {\n private readonly entries = new Map<string, string>();\n\n constructor(initial: Record<string, string> = {}) {\n for (const [name, address] of Object.entries(initial)) {\n this.define(name, address);\n }\n }\n\n /** Register (or overwrite) a named address. The address is validated. */\n public define(name: string, address: string): this {\n this.entries.set(name, assertAddress(address, `address for \"${name}\"`));\n return this;\n }\n\n /** Whether a name is registered. */\n public has(name: string): boolean {\n return this.entries.has(name);\n }\n\n /** Look up a registered address by name. */\n public get(name: string): string | undefined {\n return this.entries.get(name);\n }\n\n /** Remove a named address. */\n public delete(name: string): boolean {\n return this.entries.delete(name);\n }\n\n /** All registered names. */\n public names(): string[] {\n return [...this.entries.keys()];\n }\n\n /**\n * Resolve a reference to a concrete address: a registered name is substituted,\n * any other string is returned unchanged (so raw `G…`, muxed `M…`, federation\n * `name*domain`, etc. all keep working).\n */\n public resolve(ref: string): string {\n return this.entries.get(ref) ?? ref;\n }\n}\n\n/** Process-wide default address book. Use `addresses.define(...)` to populate it. */\nexport const addresses = new AddressBook();\n\n/** Anything accepted where an address is expected: a raw address or a name in a book. */\nexport type AddressRef = string;\n\n/**\n * Resolve an {@link AddressRef} using the given book (the shared {@link addresses}\n * by default). Lenient: unknown strings pass through unchanged.\n */\nexport function resolveAddress(ref: AddressRef, book: AddressBook = addresses): string {\n return book.resolve(ref);\n}\n","/**\n * A typed, extensible catalog of Stellar assets.\n *\n * Instead of hunting down an asset's issuer (or pasting the wrong one), use the\n * built-in catalog — `Assets.USDC`, `Assets.EURC`, `Assets.XLM` — which carries\n * the verified issuer for you. Need something else? `defineAsset(...)` makes a\n * typed asset you can reuse. And a plain code string still works everywhere.\n *\n * ⚠️ Issuers are network-specific. The {@link Assets} catalog targets **mainnet**;\n * {@link TestnetAssets} carries the testnet issuers. Bare code strings (e.g.\n * `'USDC'`) are treated as *code only* (no issuer) for backwards compatibility —\n * use the catalog object or `defineAsset` when you want the issuer filled in.\n */\n\nimport { isStellarAddress } from '@/common/addresses';\n\n/** A fully-described Stellar asset. */\nexport interface AssetDefinition {\n /** Asset code, e.g. `USDC`. Use `XLM` (or omit the issuer) for native lumens. */\n code: string;\n /** Issuer account (`G…`). `null`/omitted means the native asset (XLM). */\n issuer?: string | null;\n /** Optional Soroban contract id (`C…`) for the SAC / token contract. */\n contract?: string;\n /** Human-readable name. */\n name?: string;\n /** Network the `issuer` is valid on. */\n network?: 'public' | 'testnet';\n}\n\n/** Anything accepted where an asset is expected: a code string or a definition. */\nexport type AssetRef = string | AssetDefinition;\n\n/** Normalized asset: a code plus a concrete issuer (or `null` for native). */\nexport interface ResolvedAsset {\n /** `XLM` for the native asset, otherwise the asset code. */\n code: string;\n /** Issuer `G…`, or `null` for the native asset. */\n issuer: string | null;\n /** Optional Soroban contract id. */\n contract?: string;\n}\n\nconst NATIVE: AssetDefinition = { code: 'XLM', issuer: null, name: 'Stellar Lumens' };\n\n/**\n * Built-in **mainnet** assets with verified issuers. Extend with your own via\n * {@link defineAsset}. Issuers sourced from the official issuers (Circle for\n * USDC/EURC).\n */\nexport const Assets = {\n /** Native lumens. */\n XLM: NATIVE,\n /** USD Coin by Circle (mainnet). */\n USDC: {\n code: 'USDC',\n issuer: 'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN',\n name: 'USD Coin',\n network: 'public',\n },\n /** Euro Coin by Circle (mainnet). */\n EURC: {\n code: 'EURC',\n issuer: 'GDHU6WRG4IEQXM5NZ4BMPKOXHW76MZM4Y2IEMFDVXBSDP6SJY4ITNPP2',\n name: 'Euro Coin',\n network: 'public',\n },\n} as const satisfies Record<string, AssetDefinition>;\n\n/** Built-in **testnet** assets (Circle's Test SDF Network issuers). */\nexport const TestnetAssets = {\n XLM: NATIVE,\n USDC: {\n code: 'USDC',\n issuer: 'GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5',\n name: 'USD Coin',\n network: 'testnet',\n },\n EURC: {\n code: 'EURC',\n issuer: 'GB3Q6QDZYTHWT7E5PVS3W7FUT5GVAFC5KSZFFLPU25GO7VTC3NM2ZTVO',\n name: 'Euro Coin',\n network: 'testnet',\n },\n} as const satisfies Record<string, AssetDefinition>;\n\n/** Whether a reference denotes the native asset (XLM). */\nexport function isNativeAsset(ref: AssetRef): boolean {\n if (typeof ref === 'string') {\n const code = ref.trim().toLowerCase();\n return code === '' || code === 'xlm' || code === 'native';\n }\n return !ref.issuer || isNativeAsset(ref.code);\n}\n\n/**\n * Create a reusable, typed custom asset. Validates the issuer/contract format so\n * a typo surfaces immediately rather than on-chain.\n *\n * @example\n * const AQUA = defineAsset({ code: 'AQUA', issuer: 'GBNZ...', name: 'Aquarius' });\n * await client.paymentIntents.createPay({ destination, amount: '5', asset: AQUA });\n */\nexport function defineAsset(def: AssetDefinition): AssetDefinition {\n if (!def.code) throw new TypeError('defineAsset requires a `code`.');\n if (def.issuer != null && !isStellarAddress(def.issuer)) {\n throw new TypeError(`defineAsset: invalid issuer for ${def.code}: ${def.issuer}`);\n }\n if (def.contract != null && !/^C[A-Z2-7]{55}$/.test(def.contract)) {\n throw new TypeError(`defineAsset: invalid contract for ${def.code}: ${def.contract}`);\n }\n return Object.freeze({ ...def });\n}\n\n/**\n * Normalize an {@link AssetRef} into `{ code, issuer, contract }`.\n *\n * - A bare string is treated as *code only* (`issuer: null`) — pass a catalog\n * object or `defineAsset(...)` result when you want the issuer included.\n * - The native asset normalizes to `{ code: 'XLM', issuer: null }`.\n */\nexport function resolveAsset(ref: AssetRef): ResolvedAsset {\n if (isNativeAsset(ref)) return { code: 'XLM', issuer: null };\n if (typeof ref === 'string') return { code: ref, issuer: null };\n return {\n code: ref.code,\n issuer: ref.issuer ?? null,\n ...(ref.contract ? { contract: ref.contract } : {}),\n };\n}\n","/**\n * Shared resolution of \"create intent\" input, used by both the server SDK and\n * the web client so the convenience layers behave identically: a typed\n * {@link AssetRef} (e.g. `Assets.USDC`) is expanded into `assetCode`/`assetIssuer`,\n * and named addresses are substituted via an {@link AddressBook}.\n */\n\nimport { addresses as defaultBook, AddressBook, resolveAddress } from '@/common/addresses';\nimport { resolveAsset, type AssetRef } from '@/common/assets';\n\n/** Fields the resolver understands (everything else passes through untouched). */\nexport interface ResolvableIntentInput {\n destination?: string;\n source?: string;\n /** Typed asset (`Assets.USDC`, `defineAsset(...)`) — fills code + issuer. */\n asset?: AssetRef;\n assetCode?: string;\n assetIssuer?: string;\n}\n\n/**\n * Expand `asset` into `assetCode`/`assetIssuer` and resolve named\n * `destination`/`source` addresses. Existing `assetCode`/`assetIssuer` win over a\n * provided `asset`; native assets leave the code unset (the API treats an omitted\n * asset as native XLM). Returns a new object — the input is not mutated.\n */\nexport function resolveIntentBody<T extends ResolvableIntentInput>(\n options: T,\n book: AddressBook = defaultBook,\n): Omit<T, 'asset'> {\n const out: Record<string, unknown> = { ...(options as Record<string, unknown>) };\n\n if (typeof out['destination'] === 'string') {\n out['destination'] = resolveAddress(out['destination'], book);\n }\n if (typeof out['source'] === 'string') {\n out['source'] = resolveAddress(out['source'], book);\n }\n\n if (out['asset'] != null) {\n const { code, issuer } = resolveAsset(out['asset'] as AssetRef);\n delete out['asset'];\n if (issuer) {\n // Non-native: fill code + issuer unless the caller set them explicitly.\n out['assetCode'] ??= code;\n out['assetIssuer'] ??= issuer;\n }\n // Native (issuer == null) → leave assetCode/assetIssuer omitted = native XLM.\n }\n\n return out as Omit<T, 'asset'>;\n}\n","/** Library version, kept in sync with package.json. */\nexport const version = '2.0.0';\n\n/**\n * Default base URL of the Cosmos Pay gateway. Maintained by Cosmos Pay — users\n * never need to set this; it's part of the {@link shared} configuration. Override\n * only when self-hosting or pointing at a staging gateway.\n *\n * This is the public APISIX gateway: requests under `/cosmos-api/*` are\n * authenticated (API key) and proxied to the Payments API. The version segment\n * (`/v1`, see {@link DEFAULT_VERSION}) is appended by the REST layer, producing\n * e.g. `https://api.cosmospay.lat/cosmos-api/v1/payment-intents/pay`.\n */\nexport const DEFAULT_BASE_URL = 'https://api.cosmospay.lat/cosmos-api';\n\n/** Default API version segment prefixed to every route (`/v1/...`). */\nexport const DEFAULT_VERSION = 'v1';\n\n/** Default request timeout in milliseconds. */\nexport const DEFAULT_TIMEOUT = 30_000;\n\n/** Default number of retries for transient failures (network / 429 / 5xx). */\nexport const DEFAULT_RETRIES = 2;\n\n/** Default HMAC signature header sent by the Cosmos Pay webhook dispatcher. */\nexport const SIGNATURE_HEADER = 'x-cosmos-signature';\n\n/**\n * Client debug/telemetry events. The {@link Client} extends EventEmitter and\n * emits these for observability (`debug`/`rateLimit`-style events).\n */\nexport const Events = {\n Debug: 'debug',\n Request: 'request',\n Response: 'response',\n RateLimited: 'rateLimited',\n} as const;\nexport type ClientEvent = (typeof Events)[keyof typeof Events];\n","/**\n * Error thrown when the Cosmos Pay API responds with a non-2xx status.\n *\n * Carries the HTTP status, the parsed response body and the request context so\n * callers can branch on `error.status` (e.g. 404 → not found, 403 → gateway).\n */\nexport class CosmosPayAPIError extends Error {\n /** HTTP status code returned by the API. */\n public readonly status: number;\n /** HTTP method of the failed request. */\n public readonly method: string;\n /** Absolute URL of the failed request. */\n public readonly url: string;\n /** Parsed response body (object when JSON, string otherwise, or null). */\n public readonly body: unknown;\n /** Machine-readable error code extracted from the body when present. */\n public readonly code: string | undefined;\n\n constructor(options: {\n status: number;\n method: string;\n url: string;\n body: unknown;\n }) {\n const message = CosmosPayAPIError.resolveMessage(options.status, options.body);\n super(message);\n this.name = 'CosmosPayAPIError';\n this.status = options.status;\n this.method = options.method;\n this.url = options.url;\n this.body = options.body;\n this.code = CosmosPayAPIError.resolveCode(options.body);\n Error.captureStackTrace?.(this, CosmosPayAPIError);\n }\n\n private static resolveMessage(status: number, body: unknown): string {\n if (body && typeof body === 'object') {\n const maybe = body as { message?: unknown; error?: unknown };\n const msg = maybe.message ?? maybe.error;\n if (Array.isArray(msg)) return `[${status}] ${msg.join(', ')}`;\n if (typeof msg === 'string') return `[${status}] ${msg}`;\n }\n if (typeof body === 'string' && body.length) return `[${status}] ${body}`;\n return `[${status}] Request failed`;\n }\n\n private static resolveCode(body: unknown): string | undefined {\n if (body && typeof body === 'object') {\n const maybe = body as { code?: unknown; error?: unknown };\n if (typeof maybe.code === 'string') return maybe.code;\n if (typeof maybe.error === 'string') return maybe.error;\n }\n return undefined;\n }\n}\n\n/**\n * Error thrown when a request never reaches the API: network failure, abort or\n * timeout. Distinct from {@link CosmosPayAPIError}, which always has a status.\n */\nexport class CosmosPayRequestError extends Error {\n public readonly method: string;\n public readonly url: string;\n public readonly cause: unknown;\n\n constructor(options: { method: string; url: string; cause: unknown }) {\n const reason =\n options.cause instanceof Error ? options.cause.message : String(options.cause);\n super(`Request to ${options.method} ${options.url} failed: ${reason}`);\n this.name = 'CosmosPayRequestError';\n this.method = options.method;\n this.url = options.url;\n this.cause = options.cause;\n Error.captureStackTrace?.(this, CosmosPayRequestError);\n }\n}\n","/**\n * Typed identifiers for the wallets the web client knows about, so you can write\n * `Wallets.FREIGHTER` instead of remembering the `'freighter'` magic string —\n * while any custom adapter id still works.\n */\n\n/** Built-in wallet ids (matches each adapter's `id`). */\nexport const Wallets = {\n /** Cosmos Pay's own wallet — extension, or the hosted build (see CosmosWalletAdapter). */\n COSMOS: 'cosmos',\n FREIGHTER: 'freighter',\n XBULL: 'xbull',\n RABET: 'rabet',\n LOBSTR: 'lobstr',\n ALBEDO: 'albedo',\n} as const;\n\n/** A known wallet id, or any custom adapter id (autocomplete for the built-ins). */\nexport type WalletId = (typeof Wallets)[keyof typeof Wallets] | (string & {});\n"]}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Reaching Cosmos Wallet, over either of the two transports it ships.
3
+ *
4
+ * Cosmos Pay's own wallet exposes a SEP-43-shaped provider on `window.cosmosWallet`,
5
+ * and it gets there two different ways:
6
+ *
7
+ * extension the browser extension's content script injects it at document start,
8
+ * so the global is simply there — nothing to configure.
9
+ * hosted the wallet also runs as a plain web page, and a site opts in by
10
+ * loading `<wallet origin>/cosmos-wallet.js`. Each call then opens the
11
+ * wallet's own approval window. Nothing is installed.
12
+ *
13
+ * One module for both, because everything above the provider — the SDK's wallet
14
+ * adapter and the Stellar Wallets Kit module — cares about the same five methods
15
+ * and not at all about how they arrived.
16
+ *
17
+ * WHY THE SCRIPT IS LOADED ONCE AND MEMOISED AS A PROMISE: `isAvailable()` and
18
+ * `getAddress()` can be called in the same tick (a kit rendering its modal does
19
+ * exactly that), and two `<script>` tags for one provider is a race whose loser
20
+ * silently wins — the second load finds `window.cosmosWallet` already defined and
21
+ * bails, and whichever promise settles last is the one the caller reads.
22
+ */
23
+ /** The provider surface this SDK uses. A superset lives on the real object. */
24
+ interface CosmosWalletProvider {
25
+ /** Marker the wallet sets on its own provider. */
26
+ isCosmosWallet?: boolean;
27
+ /** `'web'` on the hosted build; absent on the extension's provider. */
28
+ transport?: string;
29
+ isConnected?(): Promise<boolean>;
30
+ getAddress(): Promise<{
31
+ address: string;
32
+ network?: string;
33
+ networkPassphrase?: string;
34
+ networkUrl?: string;
35
+ }>;
36
+ getNetwork(): Promise<{
37
+ network: string;
38
+ networkPassphrase: string;
39
+ networkUrl?: string;
40
+ }>;
41
+ signTransaction(xdr: string, opts?: {
42
+ networkPassphrase?: string;
43
+ address?: string;
44
+ }): Promise<{
45
+ signedTxXdr: string;
46
+ signerAddress?: string;
47
+ }>;
48
+ signMessage(message: string, opts?: {
49
+ networkPassphrase?: string;
50
+ address?: string;
51
+ }): Promise<{
52
+ signedMessage: string;
53
+ signerAddress?: string;
54
+ domain?: string;
55
+ }>;
56
+ /** SEP-7 `web+stellar:pay…` — the wallet builds, signs and submits it. */
57
+ requestPayment?(uri: string): Promise<{
58
+ hash: string;
59
+ signerAddress?: string;
60
+ }>;
61
+ }
62
+ /** How to find the provider. Everything is optional: an extension needs nothing. */
63
+ interface CosmosProviderOptions {
64
+ /**
65
+ * A provider object supplied by the host (tests, or an app that already holds
66
+ * one). Wins over everything else and is never probed for.
67
+ */
68
+ provider?: CosmosWalletProvider;
69
+ /**
70
+ * Origin of a hosted Cosmos Wallet — e.g. `https://wallet.cosmospay.lat`. Set it
71
+ * to support users who have not installed the extension: the provider script is
72
+ * pulled from that origin on first use, and signing happens in the wallet's own
73
+ * window on its own origin. Leave it unset to require the extension.
74
+ */
75
+ walletUrl?: string;
76
+ /**
77
+ * How long to wait for that script, in ms. The kit gives a module 1000ms to answer
78
+ * `isAvailable()`, which is why availability never waits for this — see
79
+ * `CosmosWalletModule`.
80
+ */
81
+ loadTimeoutMs?: number;
82
+ }
83
+ /** The provider the extension injected, if any. Never throws, never loads. */
84
+ declare function injectedProvider(): CosmosWalletProvider | undefined;
85
+ /**
86
+ * Load the hosted wallet's provider script from `walletUrl` and resolve with the
87
+ * provider it defines. Resolves `undefined` rather than throwing when there is no
88
+ * document, no URL, or the script never arrives: "no wallet" is an answer every
89
+ * caller here already has to handle.
90
+ */
91
+ declare function loadHostedProvider(walletUrl: string, timeoutMs?: number): Promise<CosmosWalletProvider | undefined>;
92
+ /**
93
+ * The provider to act on: the injected one, the host's, or the hosted build's —
94
+ * in that order. `undefined` when Cosmos Wallet cannot be reached at all.
95
+ */
96
+ declare function resolveProvider(options?: CosmosProviderOptions): Promise<CosmosWalletProvider | undefined>;
97
+ /** Forget memoised loads. Exposed for tests; harmless in an app. */
98
+ declare function resetProviderCache(): void;
99
+
100
+ export { type CosmosProviderOptions as C, type CosmosWalletProvider as a, resolveProvider as b, injectedProvider as i, loadHostedProvider as l, resetProviderCache as r };
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Reaching Cosmos Wallet, over either of the two transports it ships.
3
+ *
4
+ * Cosmos Pay's own wallet exposes a SEP-43-shaped provider on `window.cosmosWallet`,
5
+ * and it gets there two different ways:
6
+ *
7
+ * extension the browser extension's content script injects it at document start,
8
+ * so the global is simply there — nothing to configure.
9
+ * hosted the wallet also runs as a plain web page, and a site opts in by
10
+ * loading `<wallet origin>/cosmos-wallet.js`. Each call then opens the
11
+ * wallet's own approval window. Nothing is installed.
12
+ *
13
+ * One module for both, because everything above the provider — the SDK's wallet
14
+ * adapter and the Stellar Wallets Kit module — cares about the same five methods
15
+ * and not at all about how they arrived.
16
+ *
17
+ * WHY THE SCRIPT IS LOADED ONCE AND MEMOISED AS A PROMISE: `isAvailable()` and
18
+ * `getAddress()` can be called in the same tick (a kit rendering its modal does
19
+ * exactly that), and two `<script>` tags for one provider is a race whose loser
20
+ * silently wins — the second load finds `window.cosmosWallet` already defined and
21
+ * bails, and whichever promise settles last is the one the caller reads.
22
+ */
23
+ /** The provider surface this SDK uses. A superset lives on the real object. */
24
+ interface CosmosWalletProvider {
25
+ /** Marker the wallet sets on its own provider. */
26
+ isCosmosWallet?: boolean;
27
+ /** `'web'` on the hosted build; absent on the extension's provider. */
28
+ transport?: string;
29
+ isConnected?(): Promise<boolean>;
30
+ getAddress(): Promise<{
31
+ address: string;
32
+ network?: string;
33
+ networkPassphrase?: string;
34
+ networkUrl?: string;
35
+ }>;
36
+ getNetwork(): Promise<{
37
+ network: string;
38
+ networkPassphrase: string;
39
+ networkUrl?: string;
40
+ }>;
41
+ signTransaction(xdr: string, opts?: {
42
+ networkPassphrase?: string;
43
+ address?: string;
44
+ }): Promise<{
45
+ signedTxXdr: string;
46
+ signerAddress?: string;
47
+ }>;
48
+ signMessage(message: string, opts?: {
49
+ networkPassphrase?: string;
50
+ address?: string;
51
+ }): Promise<{
52
+ signedMessage: string;
53
+ signerAddress?: string;
54
+ domain?: string;
55
+ }>;
56
+ /** SEP-7 `web+stellar:pay…` — the wallet builds, signs and submits it. */
57
+ requestPayment?(uri: string): Promise<{
58
+ hash: string;
59
+ signerAddress?: string;
60
+ }>;
61
+ }
62
+ /** How to find the provider. Everything is optional: an extension needs nothing. */
63
+ interface CosmosProviderOptions {
64
+ /**
65
+ * A provider object supplied by the host (tests, or an app that already holds
66
+ * one). Wins over everything else and is never probed for.
67
+ */
68
+ provider?: CosmosWalletProvider;
69
+ /**
70
+ * Origin of a hosted Cosmos Wallet — e.g. `https://wallet.cosmospay.lat`. Set it
71
+ * to support users who have not installed the extension: the provider script is
72
+ * pulled from that origin on first use, and signing happens in the wallet's own
73
+ * window on its own origin. Leave it unset to require the extension.
74
+ */
75
+ walletUrl?: string;
76
+ /**
77
+ * How long to wait for that script, in ms. The kit gives a module 1000ms to answer
78
+ * `isAvailable()`, which is why availability never waits for this — see
79
+ * `CosmosWalletModule`.
80
+ */
81
+ loadTimeoutMs?: number;
82
+ }
83
+ /** The provider the extension injected, if any. Never throws, never loads. */
84
+ declare function injectedProvider(): CosmosWalletProvider | undefined;
85
+ /**
86
+ * Load the hosted wallet's provider script from `walletUrl` and resolve with the
87
+ * provider it defines. Resolves `undefined` rather than throwing when there is no
88
+ * document, no URL, or the script never arrives: "no wallet" is an answer every
89
+ * caller here already has to handle.
90
+ */
91
+ declare function loadHostedProvider(walletUrl: string, timeoutMs?: number): Promise<CosmosWalletProvider | undefined>;
92
+ /**
93
+ * The provider to act on: the injected one, the host's, or the hosted build's —
94
+ * in that order. `undefined` when Cosmos Wallet cannot be reached at all.
95
+ */
96
+ declare function resolveProvider(options?: CosmosProviderOptions): Promise<CosmosWalletProvider | undefined>;
97
+ /** Forget memoised loads. Exposed for tests; harmless in an app. */
98
+ declare function resetProviderCache(): void;
99
+
100
+ export { type CosmosProviderOptions as C, type CosmosWalletProvider as a, resolveProvider as b, injectedProvider as i, loadHostedProvider as l, resetProviderCache as r };