@cosmosapp/pay_sdk 2.3.0 → 2.3.2

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.
@@ -140,16 +140,19 @@ declare const WebhookEventType: {
140
140
  readonly SwapSubmitted: "SWAP_SUBMITTED";
141
141
  readonly SwapSucceeded: "SWAP_SUCCEEDED";
142
142
  readonly SwapFailed: "SWAP_FAILED";
143
+ readonly SwapExpired: "SWAP_EXPIRED";
143
144
  readonly LiquidityCreated: "LIQUIDITY_CREATED";
144
145
  readonly LiquiditySubmitted: "LIQUIDITY_SUBMITTED";
145
146
  readonly LiquiditySucceeded: "LIQUIDITY_SUCCEEDED";
146
147
  readonly LiquidityFailed: "LIQUIDITY_FAILED";
148
+ readonly LiquidityExpired: "LIQUIDITY_EXPIRED";
147
149
  readonly CrossChainSwapCreated: "CROSS_CHAIN_SWAP_CREATED";
148
150
  readonly CrossChainSwapUpdated: "CROSS_CHAIN_SWAP_UPDATED";
149
151
  readonly CrossChainSwapSucceeded: "CROSS_CHAIN_SWAP_SUCCEEDED";
150
152
  readonly CrossChainSwapRefunded: "CROSS_CHAIN_SWAP_REFUNDED";
151
153
  readonly CrossChainSwapFailed: "CROSS_CHAIN_SWAP_FAILED";
152
154
  readonly CrossChainSwapExpired: "CROSS_CHAIN_SWAP_EXPIRED";
155
+ readonly PrivatePaymentSucceeded: "ZK_PAYMENT_SUCCEEDED";
153
156
  };
154
157
  type WebhookEventType = (typeof WebhookEventType)[keyof typeof WebhookEventType];
155
158
  /** Delivery state of a single webhook attempt. */
@@ -409,16 +412,22 @@ interface WebhookEventDataMap {
409
412
  SWAP_SUBMITTED: SwapData | ChainSwapData;
410
413
  SWAP_SUCCEEDED: SwapData | ChainSwapData;
411
414
  SWAP_FAILED: SwapData | ChainSwapData;
415
+ /** A swap that expired before its transaction settled (it may still be rescued if it lands). */
416
+ SWAP_EXPIRED: SwapData | ChainSwapData;
412
417
  LIQUIDITY_CREATED: LiquidityOperationData;
413
418
  LIQUIDITY_SUBMITTED: LiquidityOperationData;
414
419
  LIQUIDITY_SUCCEEDED: LiquidityOperationData;
415
420
  LIQUIDITY_FAILED: LiquidityOperationData;
421
+ /** A liquidity operation that expired before its transaction settled (a late landing can still settle it). */
422
+ LIQUIDITY_EXPIRED: LiquidityOperationData;
416
423
  CROSS_CHAIN_SWAP_CREATED: CrossChainSwapData;
417
424
  CROSS_CHAIN_SWAP_UPDATED: CrossChainSwapData;
418
425
  CROSS_CHAIN_SWAP_SUCCEEDED: CrossChainSwapData;
419
426
  CROSS_CHAIN_SWAP_REFUNDED: CrossChainSwapData;
420
427
  CROSS_CHAIN_SWAP_FAILED: CrossChainSwapData;
421
428
  CROSS_CHAIN_SWAP_EXPIRED: CrossChainSwapData;
429
+ /** A private payment the network settled (client.privatePayments). */
430
+ ZK_PAYMENT_SUCCEEDED: PrivatePaymentData;
422
431
  }
423
432
  /** One webhook event of a known type, with `data` typed for it. */
424
433
  type TypedWebhookEvent<K extends keyof WebhookEventDataMap> = Omit<WebhookEvent<WebhookEventDataMap[K]>, 'type'> & {
@@ -140,16 +140,19 @@ declare const WebhookEventType: {
140
140
  readonly SwapSubmitted: "SWAP_SUBMITTED";
141
141
  readonly SwapSucceeded: "SWAP_SUCCEEDED";
142
142
  readonly SwapFailed: "SWAP_FAILED";
143
+ readonly SwapExpired: "SWAP_EXPIRED";
143
144
  readonly LiquidityCreated: "LIQUIDITY_CREATED";
144
145
  readonly LiquiditySubmitted: "LIQUIDITY_SUBMITTED";
145
146
  readonly LiquiditySucceeded: "LIQUIDITY_SUCCEEDED";
146
147
  readonly LiquidityFailed: "LIQUIDITY_FAILED";
148
+ readonly LiquidityExpired: "LIQUIDITY_EXPIRED";
147
149
  readonly CrossChainSwapCreated: "CROSS_CHAIN_SWAP_CREATED";
148
150
  readonly CrossChainSwapUpdated: "CROSS_CHAIN_SWAP_UPDATED";
149
151
  readonly CrossChainSwapSucceeded: "CROSS_CHAIN_SWAP_SUCCEEDED";
150
152
  readonly CrossChainSwapRefunded: "CROSS_CHAIN_SWAP_REFUNDED";
151
153
  readonly CrossChainSwapFailed: "CROSS_CHAIN_SWAP_FAILED";
152
154
  readonly CrossChainSwapExpired: "CROSS_CHAIN_SWAP_EXPIRED";
155
+ readonly PrivatePaymentSucceeded: "ZK_PAYMENT_SUCCEEDED";
153
156
  };
154
157
  type WebhookEventType = (typeof WebhookEventType)[keyof typeof WebhookEventType];
155
158
  /** Delivery state of a single webhook attempt. */
@@ -409,16 +412,22 @@ interface WebhookEventDataMap {
409
412
  SWAP_SUBMITTED: SwapData | ChainSwapData;
410
413
  SWAP_SUCCEEDED: SwapData | ChainSwapData;
411
414
  SWAP_FAILED: SwapData | ChainSwapData;
415
+ /** A swap that expired before its transaction settled (it may still be rescued if it lands). */
416
+ SWAP_EXPIRED: SwapData | ChainSwapData;
412
417
  LIQUIDITY_CREATED: LiquidityOperationData;
413
418
  LIQUIDITY_SUBMITTED: LiquidityOperationData;
414
419
  LIQUIDITY_SUCCEEDED: LiquidityOperationData;
415
420
  LIQUIDITY_FAILED: LiquidityOperationData;
421
+ /** A liquidity operation that expired before its transaction settled (a late landing can still settle it). */
422
+ LIQUIDITY_EXPIRED: LiquidityOperationData;
416
423
  CROSS_CHAIN_SWAP_CREATED: CrossChainSwapData;
417
424
  CROSS_CHAIN_SWAP_UPDATED: CrossChainSwapData;
418
425
  CROSS_CHAIN_SWAP_SUCCEEDED: CrossChainSwapData;
419
426
  CROSS_CHAIN_SWAP_REFUNDED: CrossChainSwapData;
420
427
  CROSS_CHAIN_SWAP_FAILED: CrossChainSwapData;
421
428
  CROSS_CHAIN_SWAP_EXPIRED: CrossChainSwapData;
429
+ /** A private payment the network settled (client.privatePayments). */
430
+ ZK_PAYMENT_SUCCEEDED: PrivatePaymentData;
422
431
  }
423
432
  /** One webhook event of a known type, with `data` typed for it. */
424
433
  type TypedWebhookEvent<K extends keyof WebhookEventDataMap> = Omit<WebhookEvent<WebhookEventDataMap[K]>, 'type'> & {
@@ -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,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,C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,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,CAAA;AAC3C,EAAA,MAAM,MAAA,GAAS,KAAA,CAAM,GAAA,CAAI,MAAM,CAAA;AAC/B,EAAA,IAAI,QAAQ,OAAO,MAAA;AAEnB,EAAA,MAAM,OAAA,GAAU,IAAI,OAAA,CAA0C,CAAC,OAAA,KAAY;AACzE,IAAA,MAAM,GAAA,GAAM,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,aAAa,CAAA,CAAA;AACtC,IAA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A,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,5 +1,5 @@
1
- import { injectedProvider, resolveProvider } from '../chunk-AYVWYEOK.js';
2
- export { injectedProvider, loadHostedProvider, resetProviderCache, resolveProvider } from '../chunk-AYVWYEOK.js';
1
+ import { injectedProvider, resolveProvider } from '../chunk-6PHQBYQ4.js';
2
+ export { injectedProvider, loadHostedProvider, resetProviderCache, resolveProvider } from '../chunk-6PHQBYQ4.js';
3
3
 
4
4
  // src/swk/types.ts
5
5
  var SwkModuleType = {
@@ -11,7 +11,7 @@ var SwkModuleType = {
11
11
 
12
12
  // src/swk/CosmosWalletModule.ts
13
13
  var COSMOS_WALLET_ID = "cosmos-wallet";
14
- var PRODUCT_NAME = "Cosmos Wallet";
14
+ var PRODUCT_NAME = "Cosmos Pay Wallet";
15
15
  var PRODUCT_URL = "https://github.com/CosmosPay/CosmosPay-Wallet";
16
16
  var PRODUCT_ICON = "https://raw.githubusercontent.com/CosmosPay/CosmosPay-Wallet/main/public/logo-512.png";
17
17
  var NOT_SUPPORTED = -3;
@@ -76,7 +76,7 @@ var CosmosWalletModule = class {
76
76
  /**
77
77
  * Not supported, and reported as such in the kit's own vocabulary.
78
78
  *
79
- * Cosmos Wallet has no Soroban authorization-entry signing. Anything this could
79
+ * Cosmos Pay Wallet has no Soroban authorization-entry signing. Anything this could
80
80
  * return instead of an error would be a signature the network rejects, discovered
81
81
  * by the user rather than by the dapp.
82
82
  */
@@ -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,WAAA,CAAY,OAAA,GAAkD,EAAC,EAAG;AAPlE,IAAA,IAAA,CAAgB,SAAA,GAAoB,gBAAA;AAQlC,IAAA,IAAA,CAAK,UAAA,GAAc,OAAA,CAAQ,UAAA,IAAc,aAAA,CAAc,UAAA;AACvD,IAAA,IAAA,CAAK,WAAA,GAAc,QAAQ,WAAA,IAAe,YAAA;AAC1C,IAAA,IAAA,CAAK,UAAA,GAAa,QAAQ,UAAA,IAAc,WAAA;AACxC,IAAA,IAAA,CAAK,WAAA,GAAc,QAAQ,WAAA,IAAe,YAAA;AAC1C,IAAA,IAAA,CAAK,OAAA,GAAU;AAAA,MACb,UAAU,OAAA,CAAQ,QAAA;AAAA,MAClB,WAAW,OAAA,CAAQ,SAAA;AAAA,MACnB,eAAe,OAAA,CAAQ;AAAA,KACzB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAa,WAAA,GAAgC;AAC3C,IAAA,IAAI,IAAA,CAAK,OAAA,CAAQ,QAAA,EAAU,OAAO,IAAA;AAClC,IAAA,IAAI,gBAAA,IAAoB,OAAO,IAAA;AAC/B,IAAA,OAAO,CAAC,CAAC,IAAA,C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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.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":["../../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,mBAAA;AACrB,IAAM,WAAA,GAAc,+CAAA;AAMpB,IAAM,YAAA,GACJ,uFAAA;AAGF,IAAM,aAAA,GAAgB,EAAA;AAiBf,IAAM,qBAAN,MAEP;AAAA,EASE,WAAA,CAAY,OAAA,GAAkD,EAAC,EAAG;AAPlE,IAAA,IAAA,CAAgB,SAAA,GAAoB,gBAAA;AAQlC,IAAA,IAAA,CAAK,UAAA,GAAc,OAAA,CAAQ,UAAA,IAAc,aAAA,CAAc,UAAA;AACvD,IAAA,IAAA,CAAK,WAAA,GAAc,QAAQ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BAAA,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 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"]}
@@ -529,7 +529,7 @@ var CosmosWalletAdapter = class {
529
529
  */
530
530
  constructor(options = {}) {
531
531
  this.id = "cosmos";
532
- this.name = "Cosmos Wallet";
532
+ this.name = "Cosmos Pay Wallet";
533
533
  this.options = isProvider(options) ? { provider: options } : options;
534
534
  }
535
535
  /**
@@ -547,7 +547,7 @@ var CosmosWalletAdapter = class {
547
547
  }
548
548
  async provider() {
549
549
  const provider = await resolveProvider(this.options);
550
- if (!provider) throw new WalletError(this.id, "Cosmos Wallet is not available.");
550
+ if (!provider) throw new WalletError(this.id, "Cosmos Pay Wallet is not available.");
551
551
  return provider;
552
552
  }
553
553
  async getPublicKey(_network) {
@@ -585,7 +585,7 @@ function defaultAdapters(injected = {}) {
585
585
  new AlbedoAdapter(injected.albedo),
586
586
  // Appended LAST on purpose. Auto-detection takes the first available adapter,
587
587
  // so putting the first-party wallet at the front would silently move an
588
- // existing integration off Freighter the day a user installs Cosmos Wallet.
588
+ // existing integration off Freighter the day a user installs Cosmos Pay Wallet.
589
589
  // A dapp that wants it preferred says so — `pay({ wallet: Wallets.COSMOS })`,
590
590
  // or `registry.register(adapter, true)`.
591
591
  new CosmosWalletAdapter(injected.cosmos ?? {})
@@ -949,7 +949,7 @@ var CosmosPayRequestError = class _CosmosPayRequestError extends Error {
949
949
  };
950
950
 
951
951
  // src/util/Constants.ts
952
- var version = "2.3.0";
952
+ var version = "2.3.2";
953
953
  var DEFAULT_BASE_URL = "https://api.cosmospay.lat/cosmos-api";
954
954
 
955
955
  // src/web/rest.ts