@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,126 @@
1
+ import { c1 as AssetRef } from './wallets-CeIjESt5.js';
2
+
3
+ /**
4
+ * Error thrown when the Cosmos Pay API responds with a non-2xx status.
5
+ *
6
+ * Carries the HTTP status, the parsed response body and the request context so
7
+ * callers can branch on `error.status` (e.g. 404 → not found, 403 → gateway).
8
+ */
9
+ declare class CosmosPayAPIError extends Error {
10
+ /** HTTP status code returned by the API. */
11
+ readonly status: number;
12
+ /** HTTP method of the failed request. */
13
+ readonly method: string;
14
+ /** Absolute URL of the failed request. */
15
+ readonly url: string;
16
+ /** Parsed response body (object when JSON, string otherwise, or null). */
17
+ readonly body: unknown;
18
+ /** Machine-readable error code extracted from the body when present. */
19
+ readonly code: string | undefined;
20
+ constructor(options: {
21
+ status: number;
22
+ method: string;
23
+ url: string;
24
+ body: unknown;
25
+ });
26
+ private static resolveMessage;
27
+ private static resolveCode;
28
+ }
29
+ /**
30
+ * Error thrown when a request never reaches the API: network failure, abort or
31
+ * timeout. Distinct from {@link CosmosPayAPIError}, which always has a status.
32
+ */
33
+ declare class CosmosPayRequestError extends Error {
34
+ readonly method: string;
35
+ readonly url: string;
36
+ readonly cause: unknown;
37
+ constructor(options: {
38
+ method: string;
39
+ url: string;
40
+ cause: unknown;
41
+ });
42
+ }
43
+
44
+ /**
45
+ * Stellar address helpers + a tiny named-address book.
46
+ *
47
+ * So integrators don't have to sprinkle raw `G...` strings everywhere (and risk
48
+ * typos), they can name the accounts they care about once and reference them by
49
+ * name. A plain address string always keeps working — `resolveAddress` only
50
+ * substitutes registered names and otherwise passes the value straight through.
51
+ */
52
+ /** Whether a value looks like a Stellar account address (`G…`). */
53
+ declare function isStellarAddress(value: unknown): value is string;
54
+ /** Whether a value looks like a muxed account address (`M…`). */
55
+ declare function isMuxedAddress(value: unknown): value is string;
56
+ /** Whether a value looks like a Soroban contract id (`C…`). */
57
+ declare function isContractAddress(value: unknown): value is string;
58
+ /** Whether a value is any kind of Stellar address (account, muxed or contract). */
59
+ declare function isAddress(value: unknown): value is string;
60
+ /** Throw unless `value` is a valid Stellar account/muxed/contract address. */
61
+ declare function assertAddress(value: unknown, label?: string): string;
62
+ /**
63
+ * A registry of named Stellar addresses. Register the accounts you use a lot —
64
+ * your merchant payout account, a treasury, frequent counterparties — and refer
65
+ * to them by name anywhere an address is accepted.
66
+ *
67
+ * @example
68
+ * addresses.define('merchant', 'GC...');
69
+ * await client.paymentIntents.createPay({ destination: 'merchant', amount: '10' });
70
+ */
71
+ declare class AddressBook {
72
+ private readonly entries;
73
+ constructor(initial?: Record<string, string>);
74
+ /** Register (or overwrite) a named address. The address is validated. */
75
+ define(name: string, address: string): this;
76
+ /** Whether a name is registered. */
77
+ has(name: string): boolean;
78
+ /** Look up a registered address by name. */
79
+ get(name: string): string | undefined;
80
+ /** Remove a named address. */
81
+ delete(name: string): boolean;
82
+ /** All registered names. */
83
+ names(): string[];
84
+ /**
85
+ * Resolve a reference to a concrete address: a registered name is substituted,
86
+ * any other string is returned unchanged (so raw `G…`, muxed `M…`, federation
87
+ * `name*domain`, etc. all keep working).
88
+ */
89
+ resolve(ref: string): string;
90
+ }
91
+ /** Process-wide default address book. Use `addresses.define(...)` to populate it. */
92
+ declare const addresses: AddressBook;
93
+ /** Anything accepted where an address is expected: a raw address or a name in a book. */
94
+ type AddressRef = string;
95
+ /**
96
+ * Resolve an {@link AddressRef} using the given book (the shared {@link addresses}
97
+ * by default). Lenient: unknown strings pass through unchanged.
98
+ */
99
+ declare function resolveAddress(ref: AddressRef, book?: AddressBook): string;
100
+
101
+ /**
102
+ * Shared resolution of "create intent" input, used by both the server SDK and
103
+ * the web client so the convenience layers behave identically: a typed
104
+ * {@link AssetRef} (e.g. `Assets.USDC`) is expanded into `assetCode`/`assetIssuer`,
105
+ * and named addresses are substituted via an {@link AddressBook}.
106
+ */
107
+
108
+ /** Fields the resolver understands (everything else passes through untouched). */
109
+ interface ResolvableIntentInput {
110
+ destination?: string;
111
+ source?: string;
112
+ /** Typed asset (`Assets.USDC`, `defineAsset(...)`) — fills code + issuer. */
113
+ asset?: AssetRef;
114
+ assetCode?: string;
115
+ assetIssuer?: string;
116
+ }
117
+ /**
118
+ * Expand `asset` into `assetCode`/`assetIssuer` and resolve named
119
+ * `destination`/`source` addresses. Existing `assetCode`/`assetIssuer` win over a
120
+ * provided `asset`; native assets leave the code unset (the API treats an omitted
121
+ * asset as native XLM). Returns a new object — the input is not mutated.
122
+ */
123
+ declare function resolveIntentBody<T extends ResolvableIntentInput>(options: T, book?: AddressBook): Omit<T, 'asset'>;
124
+
125
+ export { AddressBook as A, CosmosPayAPIError as C, CosmosPayRequestError as b, addresses as c, assertAddress as d, isContractAddress as e, isMuxedAddress as f, isStellarAddress as g, resolveIntentBody as h, isAddress as i, resolveAddress as r };
126
+ export type { ResolvableIntentInput as R, AddressRef as a };
@@ -0,0 +1,126 @@
1
+ import { c1 as AssetRef } from './wallets-CeIjESt5.cjs';
2
+
3
+ /**
4
+ * Error thrown when the Cosmos Pay API responds with a non-2xx status.
5
+ *
6
+ * Carries the HTTP status, the parsed response body and the request context so
7
+ * callers can branch on `error.status` (e.g. 404 → not found, 403 → gateway).
8
+ */
9
+ declare class CosmosPayAPIError extends Error {
10
+ /** HTTP status code returned by the API. */
11
+ readonly status: number;
12
+ /** HTTP method of the failed request. */
13
+ readonly method: string;
14
+ /** Absolute URL of the failed request. */
15
+ readonly url: string;
16
+ /** Parsed response body (object when JSON, string otherwise, or null). */
17
+ readonly body: unknown;
18
+ /** Machine-readable error code extracted from the body when present. */
19
+ readonly code: string | undefined;
20
+ constructor(options: {
21
+ status: number;
22
+ method: string;
23
+ url: string;
24
+ body: unknown;
25
+ });
26
+ private static resolveMessage;
27
+ private static resolveCode;
28
+ }
29
+ /**
30
+ * Error thrown when a request never reaches the API: network failure, abort or
31
+ * timeout. Distinct from {@link CosmosPayAPIError}, which always has a status.
32
+ */
33
+ declare class CosmosPayRequestError extends Error {
34
+ readonly method: string;
35
+ readonly url: string;
36
+ readonly cause: unknown;
37
+ constructor(options: {
38
+ method: string;
39
+ url: string;
40
+ cause: unknown;
41
+ });
42
+ }
43
+
44
+ /**
45
+ * Stellar address helpers + a tiny named-address book.
46
+ *
47
+ * So integrators don't have to sprinkle raw `G...` strings everywhere (and risk
48
+ * typos), they can name the accounts they care about once and reference them by
49
+ * name. A plain address string always keeps working — `resolveAddress` only
50
+ * substitutes registered names and otherwise passes the value straight through.
51
+ */
52
+ /** Whether a value looks like a Stellar account address (`G…`). */
53
+ declare function isStellarAddress(value: unknown): value is string;
54
+ /** Whether a value looks like a muxed account address (`M…`). */
55
+ declare function isMuxedAddress(value: unknown): value is string;
56
+ /** Whether a value looks like a Soroban contract id (`C…`). */
57
+ declare function isContractAddress(value: unknown): value is string;
58
+ /** Whether a value is any kind of Stellar address (account, muxed or contract). */
59
+ declare function isAddress(value: unknown): value is string;
60
+ /** Throw unless `value` is a valid Stellar account/muxed/contract address. */
61
+ declare function assertAddress(value: unknown, label?: string): string;
62
+ /**
63
+ * A registry of named Stellar addresses. Register the accounts you use a lot —
64
+ * your merchant payout account, a treasury, frequent counterparties — and refer
65
+ * to them by name anywhere an address is accepted.
66
+ *
67
+ * @example
68
+ * addresses.define('merchant', 'GC...');
69
+ * await client.paymentIntents.createPay({ destination: 'merchant', amount: '10' });
70
+ */
71
+ declare class AddressBook {
72
+ private readonly entries;
73
+ constructor(initial?: Record<string, string>);
74
+ /** Register (or overwrite) a named address. The address is validated. */
75
+ define(name: string, address: string): this;
76
+ /** Whether a name is registered. */
77
+ has(name: string): boolean;
78
+ /** Look up a registered address by name. */
79
+ get(name: string): string | undefined;
80
+ /** Remove a named address. */
81
+ delete(name: string): boolean;
82
+ /** All registered names. */
83
+ names(): string[];
84
+ /**
85
+ * Resolve a reference to a concrete address: a registered name is substituted,
86
+ * any other string is returned unchanged (so raw `G…`, muxed `M…`, federation
87
+ * `name*domain`, etc. all keep working).
88
+ */
89
+ resolve(ref: string): string;
90
+ }
91
+ /** Process-wide default address book. Use `addresses.define(...)` to populate it. */
92
+ declare const addresses: AddressBook;
93
+ /** Anything accepted where an address is expected: a raw address or a name in a book. */
94
+ type AddressRef = string;
95
+ /**
96
+ * Resolve an {@link AddressRef} using the given book (the shared {@link addresses}
97
+ * by default). Lenient: unknown strings pass through unchanged.
98
+ */
99
+ declare function resolveAddress(ref: AddressRef, book?: AddressBook): string;
100
+
101
+ /**
102
+ * Shared resolution of "create intent" input, used by both the server SDK and
103
+ * the web client so the convenience layers behave identically: a typed
104
+ * {@link AssetRef} (e.g. `Assets.USDC`) is expanded into `assetCode`/`assetIssuer`,
105
+ * and named addresses are substituted via an {@link AddressBook}.
106
+ */
107
+
108
+ /** Fields the resolver understands (everything else passes through untouched). */
109
+ interface ResolvableIntentInput {
110
+ destination?: string;
111
+ source?: string;
112
+ /** Typed asset (`Assets.USDC`, `defineAsset(...)`) — fills code + issuer. */
113
+ asset?: AssetRef;
114
+ assetCode?: string;
115
+ assetIssuer?: string;
116
+ }
117
+ /**
118
+ * Expand `asset` into `assetCode`/`assetIssuer` and resolve named
119
+ * `destination`/`source` addresses. Existing `assetCode`/`assetIssuer` win over a
120
+ * provided `asset`; native assets leave the code unset (the API treats an omitted
121
+ * asset as native XLM). Returns a new object — the input is not mutated.
122
+ */
123
+ declare function resolveIntentBody<T extends ResolvableIntentInput>(options: T, book?: AddressBook): Omit<T, 'asset'>;
124
+
125
+ export { AddressBook as A, CosmosPayAPIError as C, CosmosPayRequestError as b, addresses as c, assertAddress as d, isContractAddress as e, isMuxedAddress as f, isStellarAddress as g, resolveIntentBody as h, isAddress as i, resolveAddress as r };
126
+ export type { ResolvableIntentInput as R, AddressRef as a };
@@ -69,7 +69,7 @@ var SwkModuleType = {
69
69
 
70
70
  // src/swk/CosmosWalletModule.ts
71
71
  var COSMOS_WALLET_ID = "cosmos-wallet";
72
- var PRODUCT_NAME = "Cosmos Wallet";
72
+ var PRODUCT_NAME = "Cosmos Pay Wallet";
73
73
  var PRODUCT_URL = "https://github.com/CosmosPay/CosmosPay-Wallet";
74
74
  var PRODUCT_ICON = "https://raw.githubusercontent.com/CosmosPay/CosmosPay-Wallet/main/public/logo-512.png";
75
75
  var NOT_SUPPORTED = -3;
@@ -134,7 +134,7 @@ var CosmosWalletModule = class {
134
134
  /**
135
135
  * Not supported, and reported as such in the kit's own vocabulary.
136
136
  *
137
- * Cosmos Wallet has no Soroban authorization-entry signing. Anything this could
137
+ * Cosmos Pay Wallet has no Soroban authorization-entry signing. Anything this could
138
138
  * return instead of an error would be a signature the network rejects, discovered
139
139
  * by the user rather than by the dapp.
140
140
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/web/cosmosProvider.ts","../../src/swk/types.ts","../../src/swk/CosmosWalletModule.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,CAA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A,MAAM,MAAA,GAAS,MAAM,QAAA,CAAS,WAAA,CAAY,OAAA,EAAS;AAAA,MACjD,mBAAmB,IAAA,EAAM,iBAAA;AAAA,MACzB,SAAS,IAAA,EAAM;AAAA,KAChB,CAAA;AACD,IAAA,IAAI,CAAC,MAAA,EAAQ,aAAA,EAAe,MAAM,QAAA,CAAS,qCAAqC,EAAE,CAAA;AAClF,IAAA,OAAO,EAAE,aAAA,EAAe,MAAA,CAAO,aAAA,EAAe,aAAA,EAAe,OAAO,aAAA,EAAc;AAAA,EACpF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,aAAA,GAA8E;AACnF,IAAA,OAAO,OAAA,CAAQ,MAAA;AAAA,MACb,QAAA,CAAS,CAAA,EAAG,IAAA,CAAK,WAAW,kDAAkD,aAAa;AAAA,KAC7F;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAa,UAAA,GAAsE;AACjF,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,QAAA,EAAS;AACrC,IAAA,MAAM,EAAE,OAAA,EAAS,iBAAA,EAAkB,GAAI,MAAM,SAAS,UAAA,EAAW;AACjE,IAAA,IAAI,CAAC,iBAAA,EAAmB,MAAM,QAAA,CAAS,mCAAmC,EAAE,CAAA;AAC5E,IAAA,OAAO,EAAE,SAAS,iBAAA,EAAkB;AAAA,EACtC;AACF;AAQA,SAAS,QAAA,CAAS,SAAiB,IAAA,EAAiC;AAClE,EAAA,OAAO,MAAA,CAAO,OAAO,IAAI,KAAA,CAAM,OAAO,CAAA,EAAG,EAAE,IAAA,EAAM,OAAA,EAAS,CAAA;AAC5D","file":"index.cjs","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","/**\n * The Stellar Wallets Kit module contract, transcribed.\n *\n * WHY A COPY INSTEAD OF AN IMPORT. A module is one small class; depending on the\n * whole kit to describe it would put a UI library (and, when this was measured, 22\n * dev advisories) into an SDK whose own dependency list is empty. The kit is what a\n * CONSUMER installs — this package only has to produce something that fits it.\n *\n * The shapes below are transcribed from `@creit.tech/stellar-wallets-kit@2.6`\n * (`esm/types/mod.d.ts`) and are structural, so a module written against them is\n * assignable to the kit's `ModuleInterface` without either side knowing about the\n * other. The one place structural typing does not reach is `moduleType`: the kit\n * declares it as a string ENUM, and TypeScript does not accept a plain string\n * literal for one. `CosmosWalletModule` is therefore generic in that property —\n * pass the kit's own `ModuleType.HOT_WALLET` and it type-checks exactly; pass\n * nothing and you get the same string at runtime.\n *\n * Keep this file in step with the kit when it moves. `signAndSubmitTransaction` and\n * `isPlatformWrapper` are deliberately absent below: they are optional in the kit\n * and Cosmos Wallet implements neither.\n */\n\n/** `moduleType` values the kit filters and groups by. */\nexport const SwkModuleType = {\n HW_WALLET: 'HW_WALLET',\n HOT_WALLET: 'HOT_WALLET',\n BRIDGE_WALLET: 'BRIDGE_WALLET',\n AIR_GAPED_WALLET: 'AIR_GAPED_WALLET',\n} as const;\n\nexport type SwkModuleTypeValue = (typeof SwkModuleType)[keyof typeof SwkModuleType];\n\n/**\n * What a module rejects with. The kit's `parseError` reads `code`, `message` and\n * `ext` off whatever it catches, so a plain object is the native shape — and `-3`\n * is the code its own modules use for \"this wallet cannot do that\".\n */\nexport interface IKitError {\n code: number;\n message: string;\n ext?: string;\n}\n\n/** Payload of the optional `onChange` subscription. */\nexport interface IOnChangeEvent {\n address: string;\n /** Human-readable network name, as the wallet calls it. */\n network: string;\n networkPassphrase: string;\n error?: IKitError;\n}\n\n/** Options every signing method accepts. `path` is for hardware wallets. */\nexport interface SwkSignOptions {\n networkPassphrase?: string;\n address?: string;\n path?: string;\n}\n\n/**\n * The kit's `ModuleInterface`, minus the optional members Cosmos Wallet does not\n * implement. `TModuleType` exists only so the kit's enum can flow through — see\n * the header.\n */\nexport interface SwkModule<TModuleType extends string = SwkModuleTypeValue> {\n moduleType: TModuleType;\n productId: string;\n productName: string;\n productUrl: string;\n productIcon: string;\n /** Must answer in under 1000ms or the kit renders the wallet as unavailable. */\n isAvailable(): Promise<boolean>;\n getAddress(params?: { path?: string; skipRequestAccess?: boolean }): Promise<{ address: string }>;\n signTransaction(\n xdr: string,\n opts?: SwkSignOptions,\n ): Promise<{ signedTxXdr: string; signerAddress?: string }>;\n signAuthEntry(\n authEntry: string,\n opts?: SwkSignOptions,\n ): Promise<{ signedAuthEntry: string; signerAddress?: string }>;\n signMessage(\n message: string,\n opts?: SwkSignOptions,\n ): Promise<{ signedMessage: string; signerAddress?: string }>;\n getNetwork(): Promise<{ network: string; networkPassphrase: string }>;\n onChange?(callback: (event: IOnChangeEvent) => void): void;\n disconnect?(): Promise<void>;\n}\n","/**\n * Cosmos Wallet as a Stellar Wallets Kit module.\n *\n * The kit is how most Stellar dapps ask for a signature: they register a list of\n * modules and it renders one button per wallet. A wallet that is not a module is a\n * wallet those dapps cannot see, however good its provider is — which is the whole\n * reason this file exists. Registering it:\n *\n * ```ts\n * import { StellarWalletsKit, WalletNetwork, ModuleType } from '@creit.tech/stellar-wallets-kit';\n * import { CosmosWalletModule, COSMOS_WALLET_ID } from '@cosmosapp/pay_sdk/swk';\n *\n * const kit = new StellarWalletsKit({\n * network: WalletNetwork.PUBLIC,\n * selectedWalletId: COSMOS_WALLET_ID,\n * modules: [\n * // `moduleType` is the kit's own enum — passing it here keeps the module\n * // exactly assignable to `ModuleInterface` with no cast anywhere.\n * new CosmosWalletModule({ moduleType: ModuleType.HOT_WALLET }),\n * ],\n * });\n * ```\n *\n * TWO TRANSPORTS, ONE MODULE. With the extension installed the provider is already\n * on the page. Without it, pass `walletUrl` and the hosted wallet's provider script\n * is fetched from that origin on first use, so a dapp can offer Cosmos Wallet to\n * users who have installed nothing:\n *\n * ```ts\n * new CosmosWalletModule({ walletUrl: 'https://wallet.cosmospay.lat' })\n * ```\n *\n * WHAT IT REFUSES, AND WHY THAT IS THE POINT. `signAuthEntry` rejects with the\n * kit's own `-3` \"not supported\" shape rather than returning something. Cosmos\n * Wallet signs transactions and domain-separated messages; it does not sign Soroban\n * authorization entries, and a module that faked one would hand a dapp a signature\n * that fails on chain instead of an error it can render.\n */\n\nimport {\n injectedProvider,\n resolveProvider,\n type CosmosProviderOptions,\n type CosmosWalletProvider,\n} from '@/web/cosmosProvider';\nimport { SwkModuleType, type IKitError, type SwkModule, type SwkSignOptions } from '@/swk/types';\n\n/** The id a dapp filters or preselects this wallet by. */\nexport const COSMOS_WALLET_ID = 'cosmos-wallet';\n\nconst PRODUCT_NAME = 'Cosmos Wallet';\nconst PRODUCT_URL = 'https://github.com/CosmosPay/CosmosPay-Wallet';\n/**\n * Served from the wallet's repository so the module has nothing to host. When this\n * module is upstreamed the kit serves its own copy from `stellar.creit.tech`, which\n * is why the URL is an option rather than a constant baked into every call site.\n */\nconst PRODUCT_ICON =\n 'https://raw.githubusercontent.com/CosmosPay/CosmosPay-Wallet/main/public/logo-512.png';\n\n/** The kit's code for \"this wallet cannot do that\" (see its own modules). */\nconst NOT_SUPPORTED = -3;\n\nexport interface CosmosWalletModuleOptions<TModuleType extends string = string>\n extends CosmosProviderOptions {\n /**\n * Pass the kit's `ModuleType.HOT_WALLET` for exact typing. Defaults to the same\n * string, which is what the enum holds at runtime.\n */\n moduleType?: TModuleType;\n /** Override the name shown in the kit's modal. */\n productName?: string;\n /** Override the \"get this wallet\" link. */\n productUrl?: string;\n /** Override the icon shown in the modal. */\n productIcon?: string;\n}\n\nexport class CosmosWalletModule<TModuleType extends string = string>\n implements SwkModule<TModuleType>\n{\n public readonly moduleType: TModuleType;\n public readonly productId: string = COSMOS_WALLET_ID;\n public readonly productName: string;\n public readonly productUrl: string;\n public readonly productIcon: string;\n\n private readonly options: CosmosProviderOptions;\n\n constructor(options: CosmosWalletModuleOptions<TModuleType> = {}) {\n this.moduleType = (options.moduleType ?? SwkModuleType.HOT_WALLET) as TModuleType;\n this.productName = options.productName ?? PRODUCT_NAME;\n this.productUrl = options.productUrl ?? PRODUCT_URL;\n this.productIcon = options.productIcon ?? PRODUCT_ICON;\n this.options = {\n provider: options.provider,\n walletUrl: options.walletUrl,\n loadTimeoutMs: options.loadTimeoutMs,\n };\n }\n\n /**\n * The kit allows 1000ms for this and shows the wallet as unavailable otherwise,\n * so it answers from what is already in the page: an injected provider, or a\n * configured hosted wallet — which needs no install and is therefore always\n * usable. The hosted script itself is fetched on the first real call.\n */\n public async isAvailable(): Promise<boolean> {\n if (this.options.provider) return true;\n if (injectedProvider()) return true;\n return !!this.options.walletUrl;\n }\n\n private async provider(): Promise<CosmosWalletProvider> {\n const provider = await resolveProvider(this.options);\n if (!provider) throw kitError(`${this.productName} is not available.`, -1);\n return provider;\n }\n\n /**\n * `skipRequestAccess` is accepted and ignored on purpose: the wallet decides\n * whether an origin it already knows needs to be asked again, and a dapp asking\n * to skip the prompt is not the party that gets to decide that.\n */\n public async getAddress(_params?: { path?: string; skipRequestAccess?: boolean }): Promise<{\n address: string;\n }> {\n const provider = await this.provider();\n const { address } = await provider.getAddress();\n if (!address) throw kitError('The wallet returned no address.', -1);\n return { address };\n }\n\n public async signTransaction(\n xdr: string,\n opts?: SwkSignOptions,\n ): Promise<{ signedTxXdr: string; signerAddress?: string }> {\n const provider = await this.provider();\n // The passphrase is forwarded, not authoritative: Cosmos Wallet parses with its\n // own network configuration and REFUSES a mismatch, so a caller cannot redirect\n // a signature to another network by naming one. Forwarding it is what turns a\n // wrong-network request into an error the dapp can show.\n const result = await provider.signTransaction(xdr, {\n networkPassphrase: opts?.networkPassphrase,\n address: opts?.address,\n });\n if (!result?.signedTxXdr) throw kitError('The wallet returned no signed transaction.', -1);\n return { signedTxXdr: result.signedTxXdr, signerAddress: result.signerAddress };\n }\n\n public async signMessage(\n message: string,\n opts?: SwkSignOptions,\n ): Promise<{ signedMessage: string; signerAddress?: string }> {\n const provider = await this.provider();\n const result = await provider.signMessage(message, {\n networkPassphrase: opts?.networkPassphrase,\n address: opts?.address,\n });\n if (!result?.signedMessage) throw kitError('The wallet returned no signature.', -1);\n return { signedMessage: result.signedMessage, signerAddress: result.signerAddress };\n }\n\n /**\n * Not supported, and reported as such in the kit's own vocabulary.\n *\n * Cosmos Wallet has no Soroban authorization-entry signing. Anything this could\n * return instead of an error would be a signature the network rejects, discovered\n * by the user rather than by the dapp.\n */\n public signAuthEntry(): Promise<{ signedAuthEntry: string; signerAddress?: string }> {\n return Promise.reject(\n kitError(`${this.productName} does not support the \"signAuthEntry\" function`, NOT_SUPPORTED),\n );\n }\n\n /**\n * The network the WALLET is on, which is the only one it will sign for. A dapp\n * that wants another network has to ask the user to switch, not ask the wallet to\n * pretend.\n */\n public async getNetwork(): Promise<{ network: string; networkPassphrase: string }> {\n const provider = await this.provider();\n const { network, networkPassphrase } = await provider.getNetwork();\n if (!networkPassphrase) throw kitError('The wallet returned no network.', -1);\n return { network, networkPassphrase };\n }\n}\n\n/**\n * The kit reads `code`, `message` and `ext` off whatever a module rejects with, and\n * its own modules reject with a plain object. This keeps the `Error` prototype (so\n * a stack survives and `instanceof Error` holds for anyone else who catches it)\n * while carrying the fields the kit looks for.\n */\nfunction kitError(message: string, code: number): Error & IKitError {\n return Object.assign(new Error(message), { code, message });\n}\n"]}
1
+ {"version":3,"sources":["../../src/web/cosmosProvider.ts","../../src/swk/types.ts","../../src/swk/CosmosWalletModule.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,CA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AA,KAC7F;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAa,UAAA,GAAsE;AACjF,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,QAAA,EAAS;AACrC,IAAA,MAAM,EAAE,OAAA,EAAS,iBAAA,EAAkB,GAAI,MAAM,SAAS,UAAA,EAAW;AACjE,IAAA,IAAI,CAAC,iBAAA,EAAmB,MAAM,QAAA,CAAS,mCAAmC,EAAE,CAAA;AAC5E,IAAA,OAAO,EAAE,SAAS,iBAAA,EAAkB;AAAA,EACtC;AACF;AAQA,SAAS,QAAA,CAAS,SAAiB,IAAA,EAAiC;AAClE,EAAA,OAAO,MAAA,CAAO,OAAO,IAAI,KAAA,CAAM,OAAO,CAAA,EAAG,EAAE,IAAA,EAAM,OAAA,EAAS,CAAA;AAC5D","file":"index.cjs","sourcesContent":["/**\n * Reaching Cosmos Pay 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 Pay 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 Pay 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","/**\n * The Stellar Wallets Kit module contract, transcribed.\n *\n * WHY A COPY INSTEAD OF AN IMPORT. A module is one small class; depending on the\n * whole kit to describe it would put a UI library (and, when this was measured, 22\n * dev advisories) into an SDK whose own dependency list is empty. The kit is what a\n * CONSUMER installs — this package only has to produce something that fits it.\n *\n * The shapes below are transcribed from `@creit.tech/stellar-wallets-kit@2.6`\n * (`esm/types/mod.d.ts`) and are structural, so a module written against them is\n * assignable to the kit's `ModuleInterface` without either side knowing about the\n * other. The one place structural typing does not reach is `moduleType`: the kit\n * declares it as a string ENUM, and TypeScript does not accept a plain string\n * literal for one. `CosmosWalletModule` is therefore generic in that property —\n * pass the kit's own `ModuleType.HOT_WALLET` and it type-checks exactly; pass\n * nothing and you get the same string at runtime.\n *\n * Keep this file in step with the kit when it moves. `signAndSubmitTransaction` and\n * `isPlatformWrapper` are deliberately absent below: they are optional in the kit\n * and Cosmos Pay Wallet implements neither.\n */\n\n/** `moduleType` values the kit filters and groups by. */\nexport const SwkModuleType = {\n HW_WALLET: 'HW_WALLET',\n HOT_WALLET: 'HOT_WALLET',\n BRIDGE_WALLET: 'BRIDGE_WALLET',\n AIR_GAPED_WALLET: 'AIR_GAPED_WALLET',\n} as const;\n\nexport type SwkModuleTypeValue = (typeof SwkModuleType)[keyof typeof SwkModuleType];\n\n/**\n * What a module rejects with. The kit's `parseError` reads `code`, `message` and\n * `ext` off whatever it catches, so a plain object is the native shape — and `-3`\n * is the code its own modules use for \"this wallet cannot do that\".\n */\nexport interface IKitError {\n code: number;\n message: string;\n ext?: string;\n}\n\n/** Payload of the optional `onChange` subscription. */\nexport interface IOnChangeEvent {\n address: string;\n /** Human-readable network name, as the wallet calls it. */\n network: string;\n networkPassphrase: string;\n error?: IKitError;\n}\n\n/** Options every signing method accepts. `path` is for hardware wallets. */\nexport interface SwkSignOptions {\n networkPassphrase?: string;\n address?: string;\n path?: string;\n}\n\n/**\n * The kit's `ModuleInterface`, minus the optional members Cosmos Pay Wallet does not\n * implement. `TModuleType` exists only so the kit's enum can flow through — see\n * the header.\n */\nexport interface SwkModule<TModuleType extends string = SwkModuleTypeValue> {\n moduleType: TModuleType;\n productId: string;\n productName: string;\n productUrl: string;\n productIcon: string;\n /** Must answer in under 1000ms or the kit renders the wallet as unavailable. */\n isAvailable(): Promise<boolean>;\n getAddress(params?: { path?: string; skipRequestAccess?: boolean }): Promise<{ address: string }>;\n signTransaction(\n xdr: string,\n opts?: SwkSignOptions,\n ): Promise<{ signedTxXdr: string; signerAddress?: string }>;\n signAuthEntry(\n authEntry: string,\n opts?: SwkSignOptions,\n ): Promise<{ signedAuthEntry: string; signerAddress?: string }>;\n signMessage(\n message: string,\n opts?: SwkSignOptions,\n ): Promise<{ signedMessage: string; signerAddress?: string }>;\n getNetwork(): Promise<{ network: string; networkPassphrase: string }>;\n onChange?(callback: (event: IOnChangeEvent) => void): void;\n disconnect?(): Promise<void>;\n}\n","/**\n * Cosmos Pay Wallet as a Stellar Wallets Kit module.\n *\n * The kit is how most Stellar dapps ask for a signature: they register a list of\n * modules and it renders one button per wallet. A wallet that is not a module is a\n * wallet those dapps cannot see, however good its provider is — which is the whole\n * reason this file exists. Registering it:\n *\n * ```ts\n * import { StellarWalletsKit, WalletNetwork, ModuleType } from '@creit.tech/stellar-wallets-kit';\n * import { CosmosWalletModule, COSMOS_WALLET_ID } from '@cosmosapp/pay_sdk/swk';\n *\n * const kit = new StellarWalletsKit({\n * network: WalletNetwork.PUBLIC,\n * selectedWalletId: COSMOS_WALLET_ID,\n * modules: [\n * // `moduleType` is the kit's own enum — passing it here keeps the module\n * // exactly assignable to `ModuleInterface` with no cast anywhere.\n * new CosmosWalletModule({ moduleType: ModuleType.HOT_WALLET }),\n * ],\n * });\n * ```\n *\n * TWO TRANSPORTS, ONE MODULE. With the extension installed the provider is already\n * on the page. Without it, pass `walletUrl` and the hosted wallet's provider script\n * is fetched from that origin on first use, so a dapp can offer Cosmos Pay Wallet to\n * users who have installed nothing:\n *\n * ```ts\n * new CosmosWalletModule({ walletUrl: 'https://wallet.cosmospay.lat' })\n * ```\n *\n * WHAT IT REFUSES, AND WHY THAT IS THE POINT. `signAuthEntry` rejects with the\n * kit's own `-3` \"not supported\" shape rather than returning something. Cosmos\n * Wallet signs transactions and domain-separated messages; it does not sign Soroban\n * authorization entries, and a module that faked one would hand a dapp a signature\n * that fails on chain instead of an error it can render.\n */\n\nimport {\n injectedProvider,\n resolveProvider,\n type CosmosProviderOptions,\n type CosmosWalletProvider,\n} from '@/web/cosmosProvider';\nimport { SwkModuleType, type IKitError, type SwkModule, type SwkSignOptions } from '@/swk/types';\n\n/** The id a dapp filters or preselects this wallet by. */\nexport const COSMOS_WALLET_ID = 'cosmos-wallet';\n\nconst PRODUCT_NAME = 'Cosmos Pay Wallet';\nconst PRODUCT_URL = 'https://github.com/CosmosPay/CosmosPay-Wallet';\n/**\n * Served from the wallet's repository so the module has nothing to host. When this\n * module is upstreamed the kit serves its own copy from `stellar.creit.tech`, which\n * is why the URL is an option rather than a constant baked into every call site.\n */\nconst PRODUCT_ICON =\n 'https://raw.githubusercontent.com/CosmosPay/CosmosPay-Wallet/main/public/logo-512.png';\n\n/** The kit's code for \"this wallet cannot do that\" (see its own modules). */\nconst NOT_SUPPORTED = -3;\n\nexport interface CosmosWalletModuleOptions<TModuleType extends string = string>\n extends CosmosProviderOptions {\n /**\n * Pass the kit's `ModuleType.HOT_WALLET` for exact typing. Defaults to the same\n * string, which is what the enum holds at runtime.\n */\n moduleType?: TModuleType;\n /** Override the name shown in the kit's modal. */\n productName?: string;\n /** Override the \"get this wallet\" link. */\n productUrl?: string;\n /** Override the icon shown in the modal. */\n productIcon?: string;\n}\n\nexport class CosmosWalletModule<TModuleType extends string = string>\n implements SwkModule<TModuleType>\n{\n public readonly moduleType: TModuleType;\n public readonly productId: string = COSMOS_WALLET_ID;\n public readonly productName: string;\n public readonly productUrl: string;\n public readonly productIcon: string;\n\n private readonly options: CosmosProviderOptions;\n\n constructor(options: CosmosWalletModuleOptions<TModuleType> = {}) {\n this.moduleType = (options.moduleType ?? SwkModuleType.HOT_WALLET) as TModuleType;\n this.productName = options.productName ?? PRODUCT_NAME;\n this.productUrl = options.productUrl ?? PRODUCT_URL;\n this.productIcon = options.productIcon ?? PRODUCT_ICON;\n this.options = {\n provider: options.provider,\n walletUrl: options.walletUrl,\n loadTimeoutMs: options.loadTimeoutMs,\n };\n }\n\n /**\n * The kit allows 1000ms for this and shows the wallet as unavailable otherwise,\n * so it answers from what is already in the page: an injected provider, or a\n * configured hosted wallet — which needs no install and is therefore always\n * usable. The hosted script itself is fetched on the first real call.\n */\n public async isAvailable(): Promise<boolean> {\n if (this.options.provider) return true;\n if (injectedProvider()) return true;\n return !!this.options.walletUrl;\n }\n\n private async provider(): Promise<CosmosWalletProvider> {\n const provider = await resolveProvider(this.options);\n if (!provider) throw kitError(`${this.productName} is not available.`, -1);\n return provider;\n }\n\n /**\n * `skipRequestAccess` is accepted and ignored on purpose: the wallet decides\n * whether an origin it already knows needs to be asked again, and a dapp asking\n * to skip the prompt is not the party that gets to decide that.\n */\n public async getAddress(_params?: { path?: string; skipRequestAccess?: boolean }): Promise<{\n address: string;\n }> {\n const provider = await this.provider();\n const { address } = await provider.getAddress();\n if (!address) throw kitError('The wallet returned no address.', -1);\n return { address };\n }\n\n public async signTransaction(\n xdr: string,\n opts?: SwkSignOptions,\n ): Promise<{ signedTxXdr: string; signerAddress?: string }> {\n const provider = await this.provider();\n // The passphrase is forwarded, not authoritative: Cosmos Pay Wallet parses with its\n // own network configuration and REFUSES a mismatch, so a caller cannot redirect\n // a signature to another network by naming one. Forwarding it is what turns a\n // wrong-network request into an error the dapp can show.\n const result = await provider.signTransaction(xdr, {\n networkPassphrase: opts?.networkPassphrase,\n address: opts?.address,\n });\n if (!result?.signedTxXdr) throw kitError('The wallet returned no signed transaction.', -1);\n return { signedTxXdr: result.signedTxXdr, signerAddress: result.signerAddress };\n }\n\n public async signMessage(\n message: string,\n opts?: SwkSignOptions,\n ): Promise<{ signedMessage: string; signerAddress?: string }> {\n const provider = await this.provider();\n const result = await provider.signMessage(message, {\n networkPassphrase: opts?.networkPassphrase,\n address: opts?.address,\n });\n if (!result?.signedMessage) throw kitError('The wallet returned no signature.', -1);\n return { signedMessage: result.signedMessage, signerAddress: result.signerAddress };\n }\n\n /**\n * Not supported, and reported as such in the kit's own vocabulary.\n *\n * Cosmos Pay Wallet has no Soroban authorization-entry signing. Anything this could\n * return instead of an error would be a signature the network rejects, discovered\n * by the user rather than by the dapp.\n */\n public signAuthEntry(): Promise<{ signedAuthEntry: string; signerAddress?: string }> {\n return Promise.reject(\n kitError(`${this.productName} does not support the \"signAuthEntry\" function`, NOT_SUPPORTED),\n );\n }\n\n /**\n * The network the WALLET is on, which is the only one it will sign for. A dapp\n * that wants another network has to ask the user to switch, not ask the wallet to\n * pretend.\n */\n public async getNetwork(): Promise<{ network: string; networkPassphrase: string }> {\n const provider = await this.provider();\n const { network, networkPassphrase } = await provider.getNetwork();\n if (!networkPassphrase) throw kitError('The wallet returned no network.', -1);\n return { network, networkPassphrase };\n }\n}\n\n/**\n * The kit reads `code`, `message` and `ext` off whatever a module rejects with, and\n * its own modules reject with a plain object. This keeps the `Error` prototype (so\n * a stack survives and `instanceof Error` holds for anyone else who catches it)\n * while carrying the fields the kit looks for.\n */\nfunction kitError(message: string, code: number): Error & IKitError {\n return Object.assign(new Error(message), { code, message });\n}\n"]}
@@ -1,5 +1,5 @@
1
- import { C as CosmosProviderOptions } from '../cosmosProvider-DTz0Y8xZ.cjs';
2
- export { a as CosmosWalletProvider, i as injectedProvider, l as loadHostedProvider, r as resetProviderCache, b as resolveProvider } from '../cosmosProvider-DTz0Y8xZ.cjs';
1
+ import { C as CosmosProviderOptions } from '../cosmosProvider-BrpOdL_b.cjs';
2
+ export { a as CosmosWalletProvider, i as injectedProvider, l as loadHostedProvider, r as resetProviderCache, b as resolveProvider } from '../cosmosProvider-BrpOdL_b.cjs';
3
3
 
4
4
  /**
5
5
  * The Stellar Wallets Kit module contract, transcribed.
@@ -20,7 +20,7 @@ export { a as CosmosWalletProvider, i as injectedProvider, l as loadHostedProvid
20
20
  *
21
21
  * Keep this file in step with the kit when it moves. `signAndSubmitTransaction` and
22
22
  * `isPlatformWrapper` are deliberately absent below: they are optional in the kit
23
- * and Cosmos Wallet implements neither.
23
+ * and Cosmos Pay Wallet implements neither.
24
24
  */
25
25
  /** `moduleType` values the kit filters and groups by. */
26
26
  declare const SwkModuleType: {
@@ -55,7 +55,7 @@ interface SwkSignOptions {
55
55
  path?: string;
56
56
  }
57
57
  /**
58
- * The kit's `ModuleInterface`, minus the optional members Cosmos Wallet does not
58
+ * The kit's `ModuleInterface`, minus the optional members Cosmos Pay Wallet does not
59
59
  * implement. `TModuleType` exists only so the kit's enum can flow through — see
60
60
  * the header.
61
61
  */
@@ -94,7 +94,7 @@ interface SwkModule<TModuleType extends string = SwkModuleTypeValue> {
94
94
  }
95
95
 
96
96
  /**
97
- * Cosmos Wallet as a Stellar Wallets Kit module.
97
+ * Cosmos Pay Wallet as a Stellar Wallets Kit module.
98
98
  *
99
99
  * The kit is how most Stellar dapps ask for a signature: they register a list of
100
100
  * modules and it renders one button per wallet. A wallet that is not a module is a
@@ -118,7 +118,7 @@ interface SwkModule<TModuleType extends string = SwkModuleTypeValue> {
118
118
  *
119
119
  * TWO TRANSPORTS, ONE MODULE. With the extension installed the provider is already
120
120
  * on the page. Without it, pass `walletUrl` and the hosted wallet's provider script
121
- * is fetched from that origin on first use, so a dapp can offer Cosmos Wallet to
121
+ * is fetched from that origin on first use, so a dapp can offer Cosmos Pay Wallet to
122
122
  * users who have installed nothing:
123
123
  *
124
124
  * ```ts
@@ -185,7 +185,7 @@ declare class CosmosWalletModule<TModuleType extends string = string> implements
185
185
  /**
186
186
  * Not supported, and reported as such in the kit's own vocabulary.
187
187
  *
188
- * Cosmos Wallet has no Soroban authorization-entry signing. Anything this could
188
+ * Cosmos Pay Wallet has no Soroban authorization-entry signing. Anything this could
189
189
  * return instead of an error would be a signature the network rejects, discovered
190
190
  * by the user rather than by the dapp.
191
191
  */
@@ -1,5 +1,5 @@
1
- import { C as CosmosProviderOptions } from '../cosmosProvider-DTz0Y8xZ.js';
2
- export { a as CosmosWalletProvider, i as injectedProvider, l as loadHostedProvider, r as resetProviderCache, b as resolveProvider } from '../cosmosProvider-DTz0Y8xZ.js';
1
+ import { C as CosmosProviderOptions } from '../cosmosProvider-BrpOdL_b.js';
2
+ export { a as CosmosWalletProvider, i as injectedProvider, l as loadHostedProvider, r as resetProviderCache, b as resolveProvider } from '../cosmosProvider-BrpOdL_b.js';
3
3
 
4
4
  /**
5
5
  * The Stellar Wallets Kit module contract, transcribed.
@@ -20,7 +20,7 @@ export { a as CosmosWalletProvider, i as injectedProvider, l as loadHostedProvid
20
20
  *
21
21
  * Keep this file in step with the kit when it moves. `signAndSubmitTransaction` and
22
22
  * `isPlatformWrapper` are deliberately absent below: they are optional in the kit
23
- * and Cosmos Wallet implements neither.
23
+ * and Cosmos Pay Wallet implements neither.
24
24
  */
25
25
  /** `moduleType` values the kit filters and groups by. */
26
26
  declare const SwkModuleType: {
@@ -55,7 +55,7 @@ interface SwkSignOptions {
55
55
  path?: string;
56
56
  }
57
57
  /**
58
- * The kit's `ModuleInterface`, minus the optional members Cosmos Wallet does not
58
+ * The kit's `ModuleInterface`, minus the optional members Cosmos Pay Wallet does not
59
59
  * implement. `TModuleType` exists only so the kit's enum can flow through — see
60
60
  * the header.
61
61
  */
@@ -94,7 +94,7 @@ interface SwkModule<TModuleType extends string = SwkModuleTypeValue> {
94
94
  }
95
95
 
96
96
  /**
97
- * Cosmos Wallet as a Stellar Wallets Kit module.
97
+ * Cosmos Pay Wallet as a Stellar Wallets Kit module.
98
98
  *
99
99
  * The kit is how most Stellar dapps ask for a signature: they register a list of
100
100
  * modules and it renders one button per wallet. A wallet that is not a module is a
@@ -118,7 +118,7 @@ interface SwkModule<TModuleType extends string = SwkModuleTypeValue> {
118
118
  *
119
119
  * TWO TRANSPORTS, ONE MODULE. With the extension installed the provider is already
120
120
  * on the page. Without it, pass `walletUrl` and the hosted wallet's provider script
121
- * is fetched from that origin on first use, so a dapp can offer Cosmos Wallet to
121
+ * is fetched from that origin on first use, so a dapp can offer Cosmos Pay Wallet to
122
122
  * users who have installed nothing:
123
123
  *
124
124
  * ```ts
@@ -185,7 +185,7 @@ declare class CosmosWalletModule<TModuleType extends string = string> implements
185
185
  /**
186
186
  * Not supported, and reported as such in the kit's own vocabulary.
187
187
  *
188
- * Cosmos Wallet has no Soroban authorization-entry signing. Anything this could
188
+ * Cosmos Pay Wallet has no Soroban authorization-entry signing. Anything this could
189
189
  * return instead of an error would be a signature the network rejects, discovered
190
190
  * by the user rather than by the dapp.
191
191
  */
package/dist/swk/index.js CHANGED
@@ -1,106 +1,4 @@
1
- import { injectedProvider, resolveProvider } from '../chunk-AYVWYEOK.js';
2
- export { injectedProvider, loadHostedProvider, resetProviderCache, resolveProvider } from '../chunk-AYVWYEOK.js';
3
-
4
- // src/swk/types.ts
5
- var SwkModuleType = {
6
- HW_WALLET: "HW_WALLET",
7
- HOT_WALLET: "HOT_WALLET",
8
- BRIDGE_WALLET: "BRIDGE_WALLET",
9
- AIR_GAPED_WALLET: "AIR_GAPED_WALLET"
10
- };
11
-
12
- // src/swk/CosmosWalletModule.ts
13
- var COSMOS_WALLET_ID = "cosmos-wallet";
14
- var PRODUCT_NAME = "Cosmos Wallet";
15
- var PRODUCT_URL = "https://github.com/CosmosPay/CosmosPay-Wallet";
16
- var PRODUCT_ICON = "https://raw.githubusercontent.com/CosmosPay/CosmosPay-Wallet/main/public/logo-512.png";
17
- var NOT_SUPPORTED = -3;
18
- var CosmosWalletModule = class {
19
- constructor(options = {}) {
20
- this.productId = COSMOS_WALLET_ID;
21
- this.moduleType = options.moduleType ?? SwkModuleType.HOT_WALLET;
22
- this.productName = options.productName ?? PRODUCT_NAME;
23
- this.productUrl = options.productUrl ?? PRODUCT_URL;
24
- this.productIcon = options.productIcon ?? PRODUCT_ICON;
25
- this.options = {
26
- provider: options.provider,
27
- walletUrl: options.walletUrl,
28
- loadTimeoutMs: options.loadTimeoutMs
29
- };
30
- }
31
- /**
32
- * The kit allows 1000ms for this and shows the wallet as unavailable otherwise,
33
- * so it answers from what is already in the page: an injected provider, or a
34
- * configured hosted wallet — which needs no install and is therefore always
35
- * usable. The hosted script itself is fetched on the first real call.
36
- */
37
- async isAvailable() {
38
- if (this.options.provider) return true;
39
- if (injectedProvider()) return true;
40
- return !!this.options.walletUrl;
41
- }
42
- async provider() {
43
- const provider = await resolveProvider(this.options);
44
- if (!provider) throw kitError(`${this.productName} is not available.`, -1);
45
- return provider;
46
- }
47
- /**
48
- * `skipRequestAccess` is accepted and ignored on purpose: the wallet decides
49
- * whether an origin it already knows needs to be asked again, and a dapp asking
50
- * to skip the prompt is not the party that gets to decide that.
51
- */
52
- async getAddress(_params) {
53
- const provider = await this.provider();
54
- const { address } = await provider.getAddress();
55
- if (!address) throw kitError("The wallet returned no address.", -1);
56
- return { address };
57
- }
58
- async signTransaction(xdr, opts) {
59
- const provider = await this.provider();
60
- const result = await provider.signTransaction(xdr, {
61
- networkPassphrase: opts?.networkPassphrase,
62
- address: opts?.address
63
- });
64
- if (!result?.signedTxXdr) throw kitError("The wallet returned no signed transaction.", -1);
65
- return { signedTxXdr: result.signedTxXdr, signerAddress: result.signerAddress };
66
- }
67
- async signMessage(message, opts) {
68
- const provider = await this.provider();
69
- const result = await provider.signMessage(message, {
70
- networkPassphrase: opts?.networkPassphrase,
71
- address: opts?.address
72
- });
73
- if (!result?.signedMessage) throw kitError("The wallet returned no signature.", -1);
74
- return { signedMessage: result.signedMessage, signerAddress: result.signerAddress };
75
- }
76
- /**
77
- * Not supported, and reported as such in the kit's own vocabulary.
78
- *
79
- * Cosmos Wallet has no Soroban authorization-entry signing. Anything this could
80
- * return instead of an error would be a signature the network rejects, discovered
81
- * by the user rather than by the dapp.
82
- */
83
- signAuthEntry() {
84
- return Promise.reject(
85
- kitError(`${this.productName} does not support the "signAuthEntry" function`, NOT_SUPPORTED)
86
- );
87
- }
88
- /**
89
- * The network the WALLET is on, which is the only one it will sign for. A dapp
90
- * that wants another network has to ask the user to switch, not ask the wallet to
91
- * pretend.
92
- */
93
- async getNetwork() {
94
- const provider = await this.provider();
95
- const { network, networkPassphrase } = await provider.getNetwork();
96
- if (!networkPassphrase) throw kitError("The wallet returned no network.", -1);
97
- return { network, networkPassphrase };
98
- }
99
- };
100
- function kitError(message, code) {
101
- return Object.assign(new Error(message), { code, message });
102
- }
103
-
104
- export { COSMOS_WALLET_ID, CosmosWalletModule, SwkModuleType };
1
+ export { COSMOS_WALLET_ID, CosmosWalletModule, SwkModuleType } from '../chunk-ALFITFBN.js';
2
+ export { injectedProvider, loadHostedProvider, resetProviderCache, resolveProvider } from '../chunk-6PHQBYQ4.js';
105
3
  //# sourceMappingURL=index.js.map
106
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/swk/types.ts","../../src/swk/CosmosWalletModule.ts"],"names":[],"mappings":";;;;AAuBO,IAAM,aAAA,GAAgB;AAAA,EAC3B,SAAA,EAAW,WAAA;AAAA,EACX,UAAA,EAAY,YAAA;AAAA,EACZ,aAAA,EAAe,eAAA;AAAA,EACf,gBAAA,EAAkB;AACpB;;;ACoBO,IAAM,gBAAA,GAAmB;AAEhC,IAAM,YAAA,GAAe,eAAA;AACrB,IAAM,WAAA,GAAc,+CAAA;AAMpB,IAAM,YAAA,GACJ,uFAAA;AAGF,IAAM,aAAA,GAAgB,EAAA;AAiBf,IAAM,qBAAN,MAEP;AAAA,EASE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AAA;AAAA;AAAA,EAOA,MAAa,UAAA,GAAsE;AACjF,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,QAAA,EAAS;AACrC,IAAA,MAAM,EAAE,OAAA,EAAS,iBAAA,EAAkB,GAAI,MAAM,SAAS,UAAA,EAAW;AACjE,IAAA,IAAI,CAAC,iBAAA,EAAmB,MAAM,QAAA,CAAS,mCAAmC,EAAE,CAAA;AAC5E,IAAA,OAAO,EAAE,SAAS,iBAAA,EAAkB;AAAA,EACtC;AACF;AAQA,SAAS,QAAA,CAAS,SAAiB,IAAA,EAAiC;AAClE,EAAA,OAAO,MAAA,CAAO,OAAO,IAAI,KAAA,CAAM,OAAO,CAAA,EAAG,EAAE,IAAA,EAAM,OAAA,EAAS,CAAA;AAC5D","file":"index.js","sourcesContent":["/**\n * The Stellar Wallets Kit module contract, transcribed.\n *\n * WHY A COPY INSTEAD OF AN IMPORT. A module is one small class; depending on the\n * whole kit to describe it would put a UI library (and, when this was measured, 22\n * dev advisories) into an SDK whose own dependency list is empty. The kit is what a\n * CONSUMER installs — this package only has to produce something that fits it.\n *\n * The shapes below are transcribed from `@creit.tech/stellar-wallets-kit@2.6`\n * (`esm/types/mod.d.ts`) and are structural, so a module written against them is\n * assignable to the kit's `ModuleInterface` without either side knowing about the\n * other. The one place structural typing does not reach is `moduleType`: the kit\n * declares it as a string ENUM, and TypeScript does not accept a plain string\n * literal for one. `CosmosWalletModule` is therefore generic in that property —\n * pass the kit's own `ModuleType.HOT_WALLET` and it type-checks exactly; pass\n * nothing and you get the same string at runtime.\n *\n * Keep this file in step with the kit when it moves. `signAndSubmitTransaction` and\n * `isPlatformWrapper` are deliberately absent below: they are optional in the kit\n * and Cosmos Wallet implements neither.\n */\n\n/** `moduleType` values the kit filters and groups by. */\nexport const SwkModuleType = {\n HW_WALLET: 'HW_WALLET',\n HOT_WALLET: 'HOT_WALLET',\n BRIDGE_WALLET: 'BRIDGE_WALLET',\n AIR_GAPED_WALLET: 'AIR_GAPED_WALLET',\n} as const;\n\nexport type SwkModuleTypeValue = (typeof SwkModuleType)[keyof typeof SwkModuleType];\n\n/**\n * What a module rejects with. The kit's `parseError` reads `code`, `message` and\n * `ext` off whatever it catches, so a plain object is the native shape — and `-3`\n * is the code its own modules use for \"this wallet cannot do that\".\n */\nexport interface IKitError {\n code: number;\n message: string;\n ext?: string;\n}\n\n/** Payload of the optional `onChange` subscription. */\nexport interface IOnChangeEvent {\n address: string;\n /** Human-readable network name, as the wallet calls it. */\n network: string;\n networkPassphrase: string;\n error?: IKitError;\n}\n\n/** Options every signing method accepts. `path` is for hardware wallets. */\nexport interface SwkSignOptions {\n networkPassphrase?: string;\n address?: string;\n path?: string;\n}\n\n/**\n * The kit's `ModuleInterface`, minus the optional members Cosmos Wallet does not\n * implement. `TModuleType` exists only so the kit's enum can flow through — see\n * the header.\n */\nexport interface SwkModule<TModuleType extends string = SwkModuleTypeValue> {\n moduleType: TModuleType;\n productId: string;\n productName: string;\n productUrl: string;\n productIcon: string;\n /** Must answer in under 1000ms or the kit renders the wallet as unavailable. */\n isAvailable(): Promise<boolean>;\n getAddress(params?: { path?: string; skipRequestAccess?: boolean }): Promise<{ address: string }>;\n signTransaction(\n xdr: string,\n opts?: SwkSignOptions,\n ): Promise<{ signedTxXdr: string; signerAddress?: string }>;\n signAuthEntry(\n authEntry: string,\n opts?: SwkSignOptions,\n ): Promise<{ signedAuthEntry: string; signerAddress?: string }>;\n signMessage(\n message: string,\n opts?: SwkSignOptions,\n ): Promise<{ signedMessage: string; signerAddress?: string }>;\n getNetwork(): Promise<{ network: string; networkPassphrase: string }>;\n onChange?(callback: (event: IOnChangeEvent) => void): void;\n disconnect?(): Promise<void>;\n}\n","/**\n * Cosmos Wallet as a Stellar Wallets Kit module.\n *\n * The kit is how most Stellar dapps ask for a signature: they register a list of\n * modules and it renders one button per wallet. A wallet that is not a module is a\n * wallet those dapps cannot see, however good its provider is — which is the whole\n * reason this file exists. Registering it:\n *\n * ```ts\n * import { StellarWalletsKit, WalletNetwork, ModuleType } from '@creit.tech/stellar-wallets-kit';\n * import { CosmosWalletModule, COSMOS_WALLET_ID } from '@cosmosapp/pay_sdk/swk';\n *\n * const kit = new StellarWalletsKit({\n * network: WalletNetwork.PUBLIC,\n * selectedWalletId: COSMOS_WALLET_ID,\n * modules: [\n * // `moduleType` is the kit's own enum — passing it here keeps the module\n * // exactly assignable to `ModuleInterface` with no cast anywhere.\n * new CosmosWalletModule({ moduleType: ModuleType.HOT_WALLET }),\n * ],\n * });\n * ```\n *\n * TWO TRANSPORTS, ONE MODULE. With the extension installed the provider is already\n * on the page. Without it, pass `walletUrl` and the hosted wallet's provider script\n * is fetched from that origin on first use, so a dapp can offer Cosmos Wallet to\n * users who have installed nothing:\n *\n * ```ts\n * new CosmosWalletModule({ walletUrl: 'https://wallet.cosmospay.lat' })\n * ```\n *\n * WHAT IT REFUSES, AND WHY THAT IS THE POINT. `signAuthEntry` rejects with the\n * kit's own `-3` \"not supported\" shape rather than returning something. Cosmos\n * Wallet signs transactions and domain-separated messages; it does not sign Soroban\n * authorization entries, and a module that faked one would hand a dapp a signature\n * that fails on chain instead of an error it can render.\n */\n\nimport {\n injectedProvider,\n resolveProvider,\n type CosmosProviderOptions,\n type CosmosWalletProvider,\n} from '@/web/cosmosProvider';\nimport { SwkModuleType, type IKitError, type SwkModule, type SwkSignOptions } from '@/swk/types';\n\n/** The id a dapp filters or preselects this wallet by. */\nexport const COSMOS_WALLET_ID = 'cosmos-wallet';\n\nconst PRODUCT_NAME = 'Cosmos Wallet';\nconst PRODUCT_URL = 'https://github.com/CosmosPay/CosmosPay-Wallet';\n/**\n * Served from the wallet's repository so the module has nothing to host. When this\n * module is upstreamed the kit serves its own copy from `stellar.creit.tech`, which\n * is why the URL is an option rather than a constant baked into every call site.\n */\nconst PRODUCT_ICON =\n 'https://raw.githubusercontent.com/CosmosPay/CosmosPay-Wallet/main/public/logo-512.png';\n\n/** The kit's code for \"this wallet cannot do that\" (see its own modules). */\nconst NOT_SUPPORTED = -3;\n\nexport interface CosmosWalletModuleOptions<TModuleType extends string = string>\n extends CosmosProviderOptions {\n /**\n * Pass the kit's `ModuleType.HOT_WALLET` for exact typing. Defaults to the same\n * string, which is what the enum holds at runtime.\n */\n moduleType?: TModuleType;\n /** Override the name shown in the kit's modal. */\n productName?: string;\n /** Override the \"get this wallet\" link. */\n productUrl?: string;\n /** Override the icon shown in the modal. */\n productIcon?: string;\n}\n\nexport class CosmosWalletModule<TModuleType extends string = string>\n implements SwkModule<TModuleType>\n{\n public readonly moduleType: TModuleType;\n public readonly productId: string = COSMOS_WALLET_ID;\n public readonly productName: string;\n public readonly productUrl: string;\n public readonly productIcon: string;\n\n private readonly options: CosmosProviderOptions;\n\n constructor(options: CosmosWalletModuleOptions<TModuleType> = {}) {\n this.moduleType = (options.moduleType ?? SwkModuleType.HOT_WALLET) as TModuleType;\n this.productName = options.productName ?? PRODUCT_NAME;\n this.productUrl = options.productUrl ?? PRODUCT_URL;\n this.productIcon = options.productIcon ?? PRODUCT_ICON;\n this.options = {\n provider: options.provider,\n walletUrl: options.walletUrl,\n loadTimeoutMs: options.loadTimeoutMs,\n };\n }\n\n /**\n * The kit allows 1000ms for this and shows the wallet as unavailable otherwise,\n * so it answers from what is already in the page: an injected provider, or a\n * configured hosted wallet — which needs no install and is therefore always\n * usable. The hosted script itself is fetched on the first real call.\n */\n public async isAvailable(): Promise<boolean> {\n if (this.options.provider) return true;\n if (injectedProvider()) return true;\n return !!this.options.walletUrl;\n }\n\n private async provider(): Promise<CosmosWalletProvider> {\n const provider = await resolveProvider(this.options);\n if (!provider) throw kitError(`${this.productName} is not available.`, -1);\n return provider;\n }\n\n /**\n * `skipRequestAccess` is accepted and ignored on purpose: the wallet decides\n * whether an origin it already knows needs to be asked again, and a dapp asking\n * to skip the prompt is not the party that gets to decide that.\n */\n public async getAddress(_params?: { path?: string; skipRequestAccess?: boolean }): Promise<{\n address: string;\n }> {\n const provider = await this.provider();\n const { address } = await provider.getAddress();\n if (!address) throw kitError('The wallet returned no address.', -1);\n return { address };\n }\n\n public async signTransaction(\n xdr: string,\n opts?: SwkSignOptions,\n ): Promise<{ signedTxXdr: string; signerAddress?: string }> {\n const provider = await this.provider();\n // The passphrase is forwarded, not authoritative: Cosmos Wallet parses with its\n // own network configuration and REFUSES a mismatch, so a caller cannot redirect\n // a signature to another network by naming one. Forwarding it is what turns a\n // wrong-network request into an error the dapp can show.\n const result = await provider.signTransaction(xdr, {\n networkPassphrase: opts?.networkPassphrase,\n address: opts?.address,\n });\n if (!result?.signedTxXdr) throw kitError('The wallet returned no signed transaction.', -1);\n return { signedTxXdr: result.signedTxXdr, signerAddress: result.signerAddress };\n }\n\n public async signMessage(\n message: string,\n opts?: SwkSignOptions,\n ): Promise<{ signedMessage: string; signerAddress?: string }> {\n const provider = await this.provider();\n const result = await provider.signMessage(message, {\n networkPassphrase: opts?.networkPassphrase,\n address: opts?.address,\n });\n if (!result?.signedMessage) throw kitError('The wallet returned no signature.', -1);\n return { signedMessage: result.signedMessage, signerAddress: result.signerAddress };\n }\n\n /**\n * Not supported, and reported as such in the kit's own vocabulary.\n *\n * Cosmos Wallet has no Soroban authorization-entry signing. Anything this could\n * return instead of an error would be a signature the network rejects, discovered\n * by the user rather than by the dapp.\n */\n public signAuthEntry(): Promise<{ signedAuthEntry: string; signerAddress?: string }> {\n return Promise.reject(\n kitError(`${this.productName} does not support the \"signAuthEntry\" function`, NOT_SUPPORTED),\n );\n }\n\n /**\n * The network the WALLET is on, which is the only one it will sign for. A dapp\n * that wants another network has to ask the user to switch, not ask the wallet to\n * pretend.\n */\n public async getNetwork(): Promise<{ network: string; networkPassphrase: string }> {\n const provider = await this.provider();\n const { network, networkPassphrase } = await provider.getNetwork();\n if (!networkPassphrase) throw kitError('The wallet returned no network.', -1);\n return { network, networkPassphrase };\n }\n}\n\n/**\n * The kit reads `code`, `message` and `ext` off whatever a module rejects with, and\n * its own modules reject with a plain object. This keeps the `Error` prototype (so\n * a stack survives and `instanceof Error` holds for anyone else who catches it)\n * while carrying the fields the kit looks for.\n */\nfunction kitError(message: string, code: number): Error & IKitError {\n return Object.assign(new Error(message), { code, message });\n}\n"]}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}