@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.
@@ -0,0 +1,170 @@
1
+ 'use strict';
2
+
3
+ // src/web/cosmosProvider.ts
4
+ var PROVIDER_FILE = "cosmos-wallet.js";
5
+ var DEFAULT_LOAD_TIMEOUT_MS = 15e3;
6
+ function browserWindow() {
7
+ return typeof window !== "undefined" ? window : void 0;
8
+ }
9
+ function injectedProvider() {
10
+ const win = browserWindow();
11
+ const provider = win?.["cosmosWallet"];
12
+ return provider && typeof provider === "object" ? provider : void 0;
13
+ }
14
+ var loads = /* @__PURE__ */ new Map();
15
+ function loadHostedProvider(walletUrl, timeoutMs = DEFAULT_LOAD_TIMEOUT_MS) {
16
+ const existing = injectedProvider();
17
+ if (existing) return Promise.resolve(existing);
18
+ const win = browserWindow();
19
+ if (!win || typeof document === "undefined") return Promise.resolve(void 0);
20
+ const origin = walletUrl.replace(/\/+$/, "");
21
+ const cached = loads.get(origin);
22
+ if (cached) return cached;
23
+ const pending = new Promise((resolve) => {
24
+ const src = `${origin}/${PROVIDER_FILE}`;
25
+ const done = (value) => {
26
+ clearTimeout(timer);
27
+ resolve(value);
28
+ };
29
+ const timer = setTimeout(() => done(injectedProvider()), timeoutMs);
30
+ const existingTag = document.querySelector(`script[src="${src}"]`);
31
+ if (existingTag) {
32
+ const found = injectedProvider();
33
+ if (found) return done(found);
34
+ existingTag.addEventListener("load", () => done(injectedProvider()), { once: true });
35
+ existingTag.addEventListener("error", () => done(void 0), { once: true });
36
+ return;
37
+ }
38
+ const tag = document.createElement("script");
39
+ tag.src = src;
40
+ tag.async = true;
41
+ tag.addEventListener("load", () => done(injectedProvider()), { once: true });
42
+ tag.addEventListener("error", () => done(void 0), { once: true });
43
+ (document.head ?? document.documentElement).appendChild(tag);
44
+ });
45
+ loads.set(origin, pending);
46
+ void pending.then((provider) => {
47
+ if (!provider) loads.delete(origin);
48
+ });
49
+ return pending;
50
+ }
51
+ async function resolveProvider(options = {}) {
52
+ if (options.provider) return options.provider;
53
+ const injected = injectedProvider();
54
+ if (injected) return injected;
55
+ if (!options.walletUrl) return void 0;
56
+ return loadHostedProvider(options.walletUrl, options.loadTimeoutMs);
57
+ }
58
+ function resetProviderCache() {
59
+ loads.clear();
60
+ }
61
+
62
+ // src/swk/types.ts
63
+ var SwkModuleType = {
64
+ HW_WALLET: "HW_WALLET",
65
+ HOT_WALLET: "HOT_WALLET",
66
+ BRIDGE_WALLET: "BRIDGE_WALLET",
67
+ AIR_GAPED_WALLET: "AIR_GAPED_WALLET"
68
+ };
69
+
70
+ // src/swk/CosmosWalletModule.ts
71
+ var COSMOS_WALLET_ID = "cosmos-wallet";
72
+ var PRODUCT_NAME = "Cosmos Wallet";
73
+ var PRODUCT_URL = "https://github.com/CosmosPay/CosmosPay-Wallet";
74
+ var PRODUCT_ICON = "https://raw.githubusercontent.com/CosmosPay/CosmosPay-Wallet/main/public/logo-512.png";
75
+ var NOT_SUPPORTED = -3;
76
+ var CosmosWalletModule = class {
77
+ constructor(options = {}) {
78
+ this.productId = COSMOS_WALLET_ID;
79
+ this.moduleType = options.moduleType ?? SwkModuleType.HOT_WALLET;
80
+ this.productName = options.productName ?? PRODUCT_NAME;
81
+ this.productUrl = options.productUrl ?? PRODUCT_URL;
82
+ this.productIcon = options.productIcon ?? PRODUCT_ICON;
83
+ this.options = {
84
+ provider: options.provider,
85
+ walletUrl: options.walletUrl,
86
+ loadTimeoutMs: options.loadTimeoutMs
87
+ };
88
+ }
89
+ /**
90
+ * The kit allows 1000ms for this and shows the wallet as unavailable otherwise,
91
+ * so it answers from what is already in the page: an injected provider, or a
92
+ * configured hosted wallet — which needs no install and is therefore always
93
+ * usable. The hosted script itself is fetched on the first real call.
94
+ */
95
+ async isAvailable() {
96
+ if (this.options.provider) return true;
97
+ if (injectedProvider()) return true;
98
+ return !!this.options.walletUrl;
99
+ }
100
+ async provider() {
101
+ const provider = await resolveProvider(this.options);
102
+ if (!provider) throw kitError(`${this.productName} is not available.`, -1);
103
+ return provider;
104
+ }
105
+ /**
106
+ * `skipRequestAccess` is accepted and ignored on purpose: the wallet decides
107
+ * whether an origin it already knows needs to be asked again, and a dapp asking
108
+ * to skip the prompt is not the party that gets to decide that.
109
+ */
110
+ async getAddress(_params) {
111
+ const provider = await this.provider();
112
+ const { address } = await provider.getAddress();
113
+ if (!address) throw kitError("The wallet returned no address.", -1);
114
+ return { address };
115
+ }
116
+ async signTransaction(xdr, opts) {
117
+ const provider = await this.provider();
118
+ const result = await provider.signTransaction(xdr, {
119
+ networkPassphrase: opts?.networkPassphrase,
120
+ address: opts?.address
121
+ });
122
+ if (!result?.signedTxXdr) throw kitError("The wallet returned no signed transaction.", -1);
123
+ return { signedTxXdr: result.signedTxXdr, signerAddress: result.signerAddress };
124
+ }
125
+ async signMessage(message, opts) {
126
+ const provider = await this.provider();
127
+ const result = await provider.signMessage(message, {
128
+ networkPassphrase: opts?.networkPassphrase,
129
+ address: opts?.address
130
+ });
131
+ if (!result?.signedMessage) throw kitError("The wallet returned no signature.", -1);
132
+ return { signedMessage: result.signedMessage, signerAddress: result.signerAddress };
133
+ }
134
+ /**
135
+ * Not supported, and reported as such in the kit's own vocabulary.
136
+ *
137
+ * Cosmos Wallet has no Soroban authorization-entry signing. Anything this could
138
+ * return instead of an error would be a signature the network rejects, discovered
139
+ * by the user rather than by the dapp.
140
+ */
141
+ signAuthEntry() {
142
+ return Promise.reject(
143
+ kitError(`${this.productName} does not support the "signAuthEntry" function`, NOT_SUPPORTED)
144
+ );
145
+ }
146
+ /**
147
+ * The network the WALLET is on, which is the only one it will sign for. A dapp
148
+ * that wants another network has to ask the user to switch, not ask the wallet to
149
+ * pretend.
150
+ */
151
+ async getNetwork() {
152
+ const provider = await this.provider();
153
+ const { network, networkPassphrase } = await provider.getNetwork();
154
+ if (!networkPassphrase) throw kitError("The wallet returned no network.", -1);
155
+ return { network, networkPassphrase };
156
+ }
157
+ };
158
+ function kitError(message, code) {
159
+ return Object.assign(new Error(message), { code, message });
160
+ }
161
+
162
+ exports.COSMOS_WALLET_ID = COSMOS_WALLET_ID;
163
+ exports.CosmosWalletModule = CosmosWalletModule;
164
+ exports.SwkModuleType = SwkModuleType;
165
+ exports.injectedProvider = injectedProvider;
166
+ exports.loadHostedProvider = loadHostedProvider;
167
+ exports.resetProviderCache = resetProviderCache;
168
+ exports.resolveProvider = resolveProvider;
169
+ //# sourceMappingURL=index.cjs.map
170
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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,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,E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Aa;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"]}
@@ -0,0 +1,207 @@
1
+ import { C as CosmosProviderOptions } from '../cosmosProvider-CFASjnd5.cjs';
2
+ export { a as CosmosWalletProvider, i as injectedProvider, l as loadHostedProvider, r as resetProviderCache, b as resolveProvider } from '../cosmosProvider-CFASjnd5.cjs';
3
+
4
+ /**
5
+ * The Stellar Wallets Kit module contract, transcribed.
6
+ *
7
+ * WHY A COPY INSTEAD OF AN IMPORT. A module is one small class; depending on the
8
+ * whole kit to describe it would put a UI library (and, when this was measured, 22
9
+ * dev advisories) into an SDK whose own dependency list is empty. The kit is what a
10
+ * CONSUMER installs — this package only has to produce something that fits it.
11
+ *
12
+ * The shapes below are transcribed from `@creit.tech/stellar-wallets-kit@2.6`
13
+ * (`esm/types/mod.d.ts`) and are structural, so a module written against them is
14
+ * assignable to the kit's `ModuleInterface` without either side knowing about the
15
+ * other. The one place structural typing does not reach is `moduleType`: the kit
16
+ * declares it as a string ENUM, and TypeScript does not accept a plain string
17
+ * literal for one. `CosmosWalletModule` is therefore generic in that property —
18
+ * pass the kit's own `ModuleType.HOT_WALLET` and it type-checks exactly; pass
19
+ * nothing and you get the same string at runtime.
20
+ *
21
+ * Keep this file in step with the kit when it moves. `signAndSubmitTransaction` and
22
+ * `isPlatformWrapper` are deliberately absent below: they are optional in the kit
23
+ * and Cosmos Wallet implements neither.
24
+ */
25
+ /** `moduleType` values the kit filters and groups by. */
26
+ declare const SwkModuleType: {
27
+ readonly HW_WALLET: "HW_WALLET";
28
+ readonly HOT_WALLET: "HOT_WALLET";
29
+ readonly BRIDGE_WALLET: "BRIDGE_WALLET";
30
+ readonly AIR_GAPED_WALLET: "AIR_GAPED_WALLET";
31
+ };
32
+ type SwkModuleTypeValue = (typeof SwkModuleType)[keyof typeof SwkModuleType];
33
+ /**
34
+ * What a module rejects with. The kit's `parseError` reads `code`, `message` and
35
+ * `ext` off whatever it catches, so a plain object is the native shape — and `-3`
36
+ * is the code its own modules use for "this wallet cannot do that".
37
+ */
38
+ interface IKitError {
39
+ code: number;
40
+ message: string;
41
+ ext?: string;
42
+ }
43
+ /** Payload of the optional `onChange` subscription. */
44
+ interface IOnChangeEvent {
45
+ address: string;
46
+ /** Human-readable network name, as the wallet calls it. */
47
+ network: string;
48
+ networkPassphrase: string;
49
+ error?: IKitError;
50
+ }
51
+ /** Options every signing method accepts. `path` is for hardware wallets. */
52
+ interface SwkSignOptions {
53
+ networkPassphrase?: string;
54
+ address?: string;
55
+ path?: string;
56
+ }
57
+ /**
58
+ * The kit's `ModuleInterface`, minus the optional members Cosmos Wallet does not
59
+ * implement. `TModuleType` exists only so the kit's enum can flow through — see
60
+ * the header.
61
+ */
62
+ interface SwkModule<TModuleType extends string = SwkModuleTypeValue> {
63
+ moduleType: TModuleType;
64
+ productId: string;
65
+ productName: string;
66
+ productUrl: string;
67
+ productIcon: string;
68
+ /** Must answer in under 1000ms or the kit renders the wallet as unavailable. */
69
+ isAvailable(): Promise<boolean>;
70
+ getAddress(params?: {
71
+ path?: string;
72
+ skipRequestAccess?: boolean;
73
+ }): Promise<{
74
+ address: string;
75
+ }>;
76
+ signTransaction(xdr: string, opts?: SwkSignOptions): Promise<{
77
+ signedTxXdr: string;
78
+ signerAddress?: string;
79
+ }>;
80
+ signAuthEntry(authEntry: string, opts?: SwkSignOptions): Promise<{
81
+ signedAuthEntry: string;
82
+ signerAddress?: string;
83
+ }>;
84
+ signMessage(message: string, opts?: SwkSignOptions): Promise<{
85
+ signedMessage: string;
86
+ signerAddress?: string;
87
+ }>;
88
+ getNetwork(): Promise<{
89
+ network: string;
90
+ networkPassphrase: string;
91
+ }>;
92
+ onChange?(callback: (event: IOnChangeEvent) => void): void;
93
+ disconnect?(): Promise<void>;
94
+ }
95
+
96
+ /**
97
+ * Cosmos Wallet as a Stellar Wallets Kit module.
98
+ *
99
+ * The kit is how most Stellar dapps ask for a signature: they register a list of
100
+ * modules and it renders one button per wallet. A wallet that is not a module is a
101
+ * wallet those dapps cannot see, however good its provider is — which is the whole
102
+ * reason this file exists. Registering it:
103
+ *
104
+ * ```ts
105
+ * import { StellarWalletsKit, WalletNetwork, ModuleType } from '@creit.tech/stellar-wallets-kit';
106
+ * import { CosmosWalletModule, COSMOS_WALLET_ID } from '@cosmosapp/pay_sdk/swk';
107
+ *
108
+ * const kit = new StellarWalletsKit({
109
+ * network: WalletNetwork.PUBLIC,
110
+ * selectedWalletId: COSMOS_WALLET_ID,
111
+ * modules: [
112
+ * // `moduleType` is the kit's own enum — passing it here keeps the module
113
+ * // exactly assignable to `ModuleInterface` with no cast anywhere.
114
+ * new CosmosWalletModule({ moduleType: ModuleType.HOT_WALLET }),
115
+ * ],
116
+ * });
117
+ * ```
118
+ *
119
+ * TWO TRANSPORTS, ONE MODULE. With the extension installed the provider is already
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
122
+ * users who have installed nothing:
123
+ *
124
+ * ```ts
125
+ * new CosmosWalletModule({ walletUrl: 'https://wallet.cosmospay.lat' })
126
+ * ```
127
+ *
128
+ * WHAT IT REFUSES, AND WHY THAT IS THE POINT. `signAuthEntry` rejects with the
129
+ * kit's own `-3` "not supported" shape rather than returning something. Cosmos
130
+ * Wallet signs transactions and domain-separated messages; it does not sign Soroban
131
+ * authorization entries, and a module that faked one would hand a dapp a signature
132
+ * that fails on chain instead of an error it can render.
133
+ */
134
+
135
+ /** The id a dapp filters or preselects this wallet by. */
136
+ declare const COSMOS_WALLET_ID = "cosmos-wallet";
137
+ interface CosmosWalletModuleOptions<TModuleType extends string = string> extends CosmosProviderOptions {
138
+ /**
139
+ * Pass the kit's `ModuleType.HOT_WALLET` for exact typing. Defaults to the same
140
+ * string, which is what the enum holds at runtime.
141
+ */
142
+ moduleType?: TModuleType;
143
+ /** Override the name shown in the kit's modal. */
144
+ productName?: string;
145
+ /** Override the "get this wallet" link. */
146
+ productUrl?: string;
147
+ /** Override the icon shown in the modal. */
148
+ productIcon?: string;
149
+ }
150
+ declare class CosmosWalletModule<TModuleType extends string = string> implements SwkModule<TModuleType> {
151
+ readonly moduleType: TModuleType;
152
+ readonly productId: string;
153
+ readonly productName: string;
154
+ readonly productUrl: string;
155
+ readonly productIcon: string;
156
+ private readonly options;
157
+ constructor(options?: CosmosWalletModuleOptions<TModuleType>);
158
+ /**
159
+ * The kit allows 1000ms for this and shows the wallet as unavailable otherwise,
160
+ * so it answers from what is already in the page: an injected provider, or a
161
+ * configured hosted wallet — which needs no install and is therefore always
162
+ * usable. The hosted script itself is fetched on the first real call.
163
+ */
164
+ isAvailable(): Promise<boolean>;
165
+ private provider;
166
+ /**
167
+ * `skipRequestAccess` is accepted and ignored on purpose: the wallet decides
168
+ * whether an origin it already knows needs to be asked again, and a dapp asking
169
+ * to skip the prompt is not the party that gets to decide that.
170
+ */
171
+ getAddress(_params?: {
172
+ path?: string;
173
+ skipRequestAccess?: boolean;
174
+ }): Promise<{
175
+ address: string;
176
+ }>;
177
+ signTransaction(xdr: string, opts?: SwkSignOptions): Promise<{
178
+ signedTxXdr: string;
179
+ signerAddress?: string;
180
+ }>;
181
+ signMessage(message: string, opts?: SwkSignOptions): Promise<{
182
+ signedMessage: string;
183
+ signerAddress?: string;
184
+ }>;
185
+ /**
186
+ * Not supported, and reported as such in the kit's own vocabulary.
187
+ *
188
+ * Cosmos Wallet has no Soroban authorization-entry signing. Anything this could
189
+ * return instead of an error would be a signature the network rejects, discovered
190
+ * by the user rather than by the dapp.
191
+ */
192
+ signAuthEntry(): Promise<{
193
+ signedAuthEntry: string;
194
+ signerAddress?: string;
195
+ }>;
196
+ /**
197
+ * The network the WALLET is on, which is the only one it will sign for. A dapp
198
+ * that wants another network has to ask the user to switch, not ask the wallet to
199
+ * pretend.
200
+ */
201
+ getNetwork(): Promise<{
202
+ network: string;
203
+ networkPassphrase: string;
204
+ }>;
205
+ }
206
+
207
+ export { COSMOS_WALLET_ID, CosmosProviderOptions, CosmosWalletModule, type CosmosWalletModuleOptions, type IKitError, type IOnChangeEvent, type SwkModule, SwkModuleType, type SwkModuleTypeValue, type SwkSignOptions };
@@ -0,0 +1,207 @@
1
+ import { C as CosmosProviderOptions } from '../cosmosProvider-CFASjnd5.js';
2
+ export { a as CosmosWalletProvider, i as injectedProvider, l as loadHostedProvider, r as resetProviderCache, b as resolveProvider } from '../cosmosProvider-CFASjnd5.js';
3
+
4
+ /**
5
+ * The Stellar Wallets Kit module contract, transcribed.
6
+ *
7
+ * WHY A COPY INSTEAD OF AN IMPORT. A module is one small class; depending on the
8
+ * whole kit to describe it would put a UI library (and, when this was measured, 22
9
+ * dev advisories) into an SDK whose own dependency list is empty. The kit is what a
10
+ * CONSUMER installs — this package only has to produce something that fits it.
11
+ *
12
+ * The shapes below are transcribed from `@creit.tech/stellar-wallets-kit@2.6`
13
+ * (`esm/types/mod.d.ts`) and are structural, so a module written against them is
14
+ * assignable to the kit's `ModuleInterface` without either side knowing about the
15
+ * other. The one place structural typing does not reach is `moduleType`: the kit
16
+ * declares it as a string ENUM, and TypeScript does not accept a plain string
17
+ * literal for one. `CosmosWalletModule` is therefore generic in that property —
18
+ * pass the kit's own `ModuleType.HOT_WALLET` and it type-checks exactly; pass
19
+ * nothing and you get the same string at runtime.
20
+ *
21
+ * Keep this file in step with the kit when it moves. `signAndSubmitTransaction` and
22
+ * `isPlatformWrapper` are deliberately absent below: they are optional in the kit
23
+ * and Cosmos Wallet implements neither.
24
+ */
25
+ /** `moduleType` values the kit filters and groups by. */
26
+ declare const SwkModuleType: {
27
+ readonly HW_WALLET: "HW_WALLET";
28
+ readonly HOT_WALLET: "HOT_WALLET";
29
+ readonly BRIDGE_WALLET: "BRIDGE_WALLET";
30
+ readonly AIR_GAPED_WALLET: "AIR_GAPED_WALLET";
31
+ };
32
+ type SwkModuleTypeValue = (typeof SwkModuleType)[keyof typeof SwkModuleType];
33
+ /**
34
+ * What a module rejects with. The kit's `parseError` reads `code`, `message` and
35
+ * `ext` off whatever it catches, so a plain object is the native shape — and `-3`
36
+ * is the code its own modules use for "this wallet cannot do that".
37
+ */
38
+ interface IKitError {
39
+ code: number;
40
+ message: string;
41
+ ext?: string;
42
+ }
43
+ /** Payload of the optional `onChange` subscription. */
44
+ interface IOnChangeEvent {
45
+ address: string;
46
+ /** Human-readable network name, as the wallet calls it. */
47
+ network: string;
48
+ networkPassphrase: string;
49
+ error?: IKitError;
50
+ }
51
+ /** Options every signing method accepts. `path` is for hardware wallets. */
52
+ interface SwkSignOptions {
53
+ networkPassphrase?: string;
54
+ address?: string;
55
+ path?: string;
56
+ }
57
+ /**
58
+ * The kit's `ModuleInterface`, minus the optional members Cosmos Wallet does not
59
+ * implement. `TModuleType` exists only so the kit's enum can flow through — see
60
+ * the header.
61
+ */
62
+ interface SwkModule<TModuleType extends string = SwkModuleTypeValue> {
63
+ moduleType: TModuleType;
64
+ productId: string;
65
+ productName: string;
66
+ productUrl: string;
67
+ productIcon: string;
68
+ /** Must answer in under 1000ms or the kit renders the wallet as unavailable. */
69
+ isAvailable(): Promise<boolean>;
70
+ getAddress(params?: {
71
+ path?: string;
72
+ skipRequestAccess?: boolean;
73
+ }): Promise<{
74
+ address: string;
75
+ }>;
76
+ signTransaction(xdr: string, opts?: SwkSignOptions): Promise<{
77
+ signedTxXdr: string;
78
+ signerAddress?: string;
79
+ }>;
80
+ signAuthEntry(authEntry: string, opts?: SwkSignOptions): Promise<{
81
+ signedAuthEntry: string;
82
+ signerAddress?: string;
83
+ }>;
84
+ signMessage(message: string, opts?: SwkSignOptions): Promise<{
85
+ signedMessage: string;
86
+ signerAddress?: string;
87
+ }>;
88
+ getNetwork(): Promise<{
89
+ network: string;
90
+ networkPassphrase: string;
91
+ }>;
92
+ onChange?(callback: (event: IOnChangeEvent) => void): void;
93
+ disconnect?(): Promise<void>;
94
+ }
95
+
96
+ /**
97
+ * Cosmos Wallet as a Stellar Wallets Kit module.
98
+ *
99
+ * The kit is how most Stellar dapps ask for a signature: they register a list of
100
+ * modules and it renders one button per wallet. A wallet that is not a module is a
101
+ * wallet those dapps cannot see, however good its provider is — which is the whole
102
+ * reason this file exists. Registering it:
103
+ *
104
+ * ```ts
105
+ * import { StellarWalletsKit, WalletNetwork, ModuleType } from '@creit.tech/stellar-wallets-kit';
106
+ * import { CosmosWalletModule, COSMOS_WALLET_ID } from '@cosmosapp/pay_sdk/swk';
107
+ *
108
+ * const kit = new StellarWalletsKit({
109
+ * network: WalletNetwork.PUBLIC,
110
+ * selectedWalletId: COSMOS_WALLET_ID,
111
+ * modules: [
112
+ * // `moduleType` is the kit's own enum — passing it here keeps the module
113
+ * // exactly assignable to `ModuleInterface` with no cast anywhere.
114
+ * new CosmosWalletModule({ moduleType: ModuleType.HOT_WALLET }),
115
+ * ],
116
+ * });
117
+ * ```
118
+ *
119
+ * TWO TRANSPORTS, ONE MODULE. With the extension installed the provider is already
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
122
+ * users who have installed nothing:
123
+ *
124
+ * ```ts
125
+ * new CosmosWalletModule({ walletUrl: 'https://wallet.cosmospay.lat' })
126
+ * ```
127
+ *
128
+ * WHAT IT REFUSES, AND WHY THAT IS THE POINT. `signAuthEntry` rejects with the
129
+ * kit's own `-3` "not supported" shape rather than returning something. Cosmos
130
+ * Wallet signs transactions and domain-separated messages; it does not sign Soroban
131
+ * authorization entries, and a module that faked one would hand a dapp a signature
132
+ * that fails on chain instead of an error it can render.
133
+ */
134
+
135
+ /** The id a dapp filters or preselects this wallet by. */
136
+ declare const COSMOS_WALLET_ID = "cosmos-wallet";
137
+ interface CosmosWalletModuleOptions<TModuleType extends string = string> extends CosmosProviderOptions {
138
+ /**
139
+ * Pass the kit's `ModuleType.HOT_WALLET` for exact typing. Defaults to the same
140
+ * string, which is what the enum holds at runtime.
141
+ */
142
+ moduleType?: TModuleType;
143
+ /** Override the name shown in the kit's modal. */
144
+ productName?: string;
145
+ /** Override the "get this wallet" link. */
146
+ productUrl?: string;
147
+ /** Override the icon shown in the modal. */
148
+ productIcon?: string;
149
+ }
150
+ declare class CosmosWalletModule<TModuleType extends string = string> implements SwkModule<TModuleType> {
151
+ readonly moduleType: TModuleType;
152
+ readonly productId: string;
153
+ readonly productName: string;
154
+ readonly productUrl: string;
155
+ readonly productIcon: string;
156
+ private readonly options;
157
+ constructor(options?: CosmosWalletModuleOptions<TModuleType>);
158
+ /**
159
+ * The kit allows 1000ms for this and shows the wallet as unavailable otherwise,
160
+ * so it answers from what is already in the page: an injected provider, or a
161
+ * configured hosted wallet — which needs no install and is therefore always
162
+ * usable. The hosted script itself is fetched on the first real call.
163
+ */
164
+ isAvailable(): Promise<boolean>;
165
+ private provider;
166
+ /**
167
+ * `skipRequestAccess` is accepted and ignored on purpose: the wallet decides
168
+ * whether an origin it already knows needs to be asked again, and a dapp asking
169
+ * to skip the prompt is not the party that gets to decide that.
170
+ */
171
+ getAddress(_params?: {
172
+ path?: string;
173
+ skipRequestAccess?: boolean;
174
+ }): Promise<{
175
+ address: string;
176
+ }>;
177
+ signTransaction(xdr: string, opts?: SwkSignOptions): Promise<{
178
+ signedTxXdr: string;
179
+ signerAddress?: string;
180
+ }>;
181
+ signMessage(message: string, opts?: SwkSignOptions): Promise<{
182
+ signedMessage: string;
183
+ signerAddress?: string;
184
+ }>;
185
+ /**
186
+ * Not supported, and reported as such in the kit's own vocabulary.
187
+ *
188
+ * Cosmos Wallet has no Soroban authorization-entry signing. Anything this could
189
+ * return instead of an error would be a signature the network rejects, discovered
190
+ * by the user rather than by the dapp.
191
+ */
192
+ signAuthEntry(): Promise<{
193
+ signedAuthEntry: string;
194
+ signerAddress?: string;
195
+ }>;
196
+ /**
197
+ * The network the WALLET is on, which is the only one it will sign for. A dapp
198
+ * that wants another network has to ask the user to switch, not ask the wallet to
199
+ * pretend.
200
+ */
201
+ getNetwork(): Promise<{
202
+ network: string;
203
+ networkPassphrase: string;
204
+ }>;
205
+ }
206
+
207
+ export { COSMOS_WALLET_ID, CosmosProviderOptions, CosmosWalletModule, type CosmosWalletModuleOptions, type IKitError, type IOnChangeEvent, type SwkModule, SwkModuleType, type SwkModuleTypeValue, type SwkSignOptions };