@cosmosapp/pay_sdk 1.2.0 → 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.
Files changed (40) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/LICENSE +0 -75
  3. package/NOTICE +8 -0
  4. package/README.md +15 -18
  5. package/dist/chunk-AYVWYEOK.js +62 -0
  6. package/dist/chunk-AYVWYEOK.js.map +1 -0
  7. package/dist/{chunk-TZDZBVFS.js → chunk-TM4HAKWE.js} +5 -3
  8. package/dist/chunk-TM4HAKWE.js.map +1 -0
  9. package/dist/cosmosProvider-CFASjnd5.d.cts +100 -0
  10. package/dist/cosmosProvider-CFASjnd5.d.ts +100 -0
  11. package/dist/index.cjs +739 -3
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +618 -6
  14. package/dist/index.d.ts +618 -6
  15. package/dist/index.js +731 -5
  16. package/dist/index.js.map +1 -1
  17. package/dist/intent-input-BtUp3tFN.d.cts +1697 -0
  18. package/dist/intent-input-BtUp3tFN.d.ts +1697 -0
  19. package/dist/swk/index.cjs +170 -0
  20. package/dist/swk/index.cjs.map +1 -0
  21. package/dist/swk/index.d.cts +207 -0
  22. package/dist/swk/index.d.ts +207 -0
  23. package/dist/swk/index.js +106 -0
  24. package/dist/swk/index.js.map +1 -0
  25. package/dist/web/index.cjs +129 -2
  26. package/dist/web/index.cjs.map +1 -1
  27. package/dist/web/index.d.cts +49 -4
  28. package/dist/web/index.d.ts +49 -4
  29. package/dist/web/index.js +67 -4
  30. package/dist/web/index.js.map +1 -1
  31. package/llms/03-quickstart.md +4 -4
  32. package/llms/05-payment-intents.md +6 -2
  33. package/llms/08-products-customers.md +1 -1
  34. package/llms/13-types-reference.md +1 -1
  35. package/llms/14-recipes.md +14 -8
  36. package/llms/llms-full.txt +26 -16
  37. package/package.json +17 -6
  38. package/dist/chunk-TZDZBVFS.js.map +0 -1
  39. package/dist/intent-input-Ch8ogEg-.d.cts +0 -750
  40. package/dist/intent-input-Ch8ogEg-.d.ts +0 -750
@@ -1,5 +1,7 @@
1
- import { a4 as WalletId, P as PaymentIntentData, h as CreatePayPaymentIntentOptions, g as CreateTxPaymentIntentOptions, V as ValidationOutcomeData } from '../intent-input-Ch8ogEg-.cjs';
2
- export { F as AddressBook, G as AddressRef, O as AssetDefinition, R as AssetRef, T as Assets, X as CosmosPayAPIError, Y as CosmosPayRequestError, $ as ResolvableIntentInput, a0 as ResolvedAsset, a3 as TestnetAssets, a5 as Wallets, a8 as addresses, a9 as assertAddress, aa as defineAsset, ab as isAddress, ac as isContractAddress, ad as isMuxedAddress, ae as isNativeAsset, af as isStellarAddress, ag as resolveAddress, ah as resolveAsset, ai as resolveIntentBody } from '../intent-input-Ch8ogEg-.cjs';
1
+ import { bG as WalletId, an as PaymentIntentData, au as CreatePayPaymentIntentOptions, at as CreateTxPaymentIntentOptions, as as ValidationOutcomeData } from '../intent-input-BtUp3tFN.cjs';
2
+ export { aW as AddressBook, aX as AddressRef, b1 as AssetDefinition, b2 as AssetRef, b3 as Assets, b7 as CosmosPayAPIError, b8 as CosmosPayRequestError, bB as ResolvableIntentInput, bC as ResolvedAsset, bF as TestnetAssets, bH as Wallets, bK as addresses, bL as assertAddress, bM as defineAsset, bN as isAddress, bO as isContractAddress, bP as isMuxedAddress, bQ as isNativeAsset, bR as isStellarAddress, bS as resolveAddress, bT as resolveAsset, bU as resolveIntentBody } from '../intent-input-BtUp3tFN.cjs';
3
+ import { C as CosmosProviderOptions, a as CosmosWalletProvider } from '../cosmosProvider-CFASjnd5.cjs';
4
+ export { i as injectedProvider, l as loadHostedProvider, r as resetProviderCache, b as resolveProvider } from '../cosmosProvider-CFASjnd5.cjs';
3
5
 
4
6
  /**
5
7
  * Types for the browser ("web client") side of the SDK.
@@ -358,11 +360,49 @@ declare class AlbedoAdapter implements WalletAdapter {
358
360
  signTransaction(xdr: string, params: SignParams): Promise<string>;
359
361
  }
360
362
 
363
+ /**
364
+ * Cosmos Wallet — https://github.com/CosmosPay/CosmosPay-Wallet
365
+ *
366
+ * Cosmos Pay's own non-custodial Stellar wallet. It reaches the page two ways and
367
+ * this adapter serves both: the browser extension injects `window.cosmosWallet`,
368
+ * and the hosted build is loaded from the wallet's own origin when `walletUrl` is
369
+ * configured (see `@/web/cosmosProvider`). Everything below is the same either way.
370
+ *
371
+ * It is the only adapter here that is first-party, which is exactly why it is not
372
+ * privileged: it sits in the same detection order as the rest and answers the same
373
+ * three questions. A wallet that needed special treatment in the client would be a
374
+ * wallet the client could not swap out.
375
+ */
376
+
377
+ declare class CosmosWalletAdapter implements WalletAdapter {
378
+ readonly id = "cosmos";
379
+ readonly name = "Cosmos Wallet";
380
+ private readonly options;
381
+ /**
382
+ * @param options - A provider to use directly, or the origin of a hosted Cosmos
383
+ * Wallet to fall back to. Both optional: with the extension installed there is
384
+ * nothing to configure.
385
+ */
386
+ constructor(options?: CosmosProviderOptions | CosmosWalletProvider);
387
+ /**
388
+ * Available when a provider is already here, or when a hosted wallet is
389
+ * configured — the hosted build needs no install, so it is always usable.
390
+ *
391
+ * Deliberately does NOT wait for the hosted script: this answer gates a modal,
392
+ * and a wallet that takes a network round trip to say "yes" reads as broken. The
393
+ * script is fetched on the first real call instead.
394
+ */
395
+ isAvailable(): Promise<boolean>;
396
+ private provider;
397
+ getPublicKey(_network: NetworkConfig): Promise<string>;
398
+ signTransaction(xdr: string, params: SignParams): Promise<string>;
399
+ }
400
+
361
401
  /**
362
402
  * Built-in wallet adapters and the default registration set.
363
403
  *
364
404
  * Auto-detection order (first available wins): Freighter → xBull → Rabet →
365
- * LOBSTR → Albedo. Freighter, xBull and Rabet inject browser globals so they're
405
+ * LOBSTR → Albedo → Cosmos Wallet. Freighter, xBull and Rabet inject browser globals so they're
366
406
  * detected with zero configuration; LOBSTR and Albedo need their library passed
367
407
  * in (no reliable global), so they only activate when injected.
368
408
  */
@@ -383,6 +423,11 @@ interface InjectedWallets {
383
423
  albedo?: any;
384
424
  /** A `@lobstrco/signer-extension-api` module. */
385
425
  lobstr?: any;
426
+ /**
427
+ * A Cosmos Wallet provider, or `{ walletUrl }` to reach the HOSTED wallet when
428
+ * the extension is absent (otherwise `window.cosmosWallet`).
429
+ */
430
+ cosmos?: CosmosWalletProvider | CosmosProviderOptions;
386
431
  }
387
432
  /**
388
433
  * Build the default adapter set, honoring any injected wallet libraries. The
@@ -755,4 +800,4 @@ declare class WebREST {
755
800
  request<T>(method: string, path: string, options?: WebRequestOptions): Promise<T>;
756
801
  }
757
802
 
758
- export { AlbedoAdapter, type BuildPaymentInput, type ConnectResult, CosmosPayWebError, FreighterAdapter, HORIZON_URLS, type InjectedWallets, IntentError, LobstrAdapter, type NetworkConfig, type NormalizedIntent, PASSPHRASES, type PayOptions, type PayResult, type PayableInput, PaymentIntentData, RabetAdapter, type ResolveNetworkInput, type Sep7Request, type SignParams, type StellarNetwork, type StellarSdkLike, StellarSdkRequiredError, type WalletAdapter, WalletError, WalletId, type WalletInfo, WalletNotFoundError, WalletRegistry, WebClient, type WebClientOptions, WebREST, type WebRESTOptions, type WebRequestOptions, XBullAdapter, buildPaymentXdr, classifyNetwork, defaultAdapters, isPassphrase, isSep7Uri, loadStellarSdk, normalizeIntent, parseSep7, postToCallback, resolveNetwork, submitToHorizon, transactionHash };
803
+ export { AlbedoAdapter, type BuildPaymentInput, type ConnectResult, CosmosPayWebError, CosmosProviderOptions, CosmosWalletAdapter, CosmosWalletProvider, FreighterAdapter, HORIZON_URLS, type InjectedWallets, IntentError, LobstrAdapter, type NetworkConfig, type NormalizedIntent, PASSPHRASES, type PayOptions, type PayResult, type PayableInput, PaymentIntentData, RabetAdapter, type ResolveNetworkInput, type Sep7Request, type SignParams, type StellarNetwork, type StellarSdkLike, StellarSdkRequiredError, type WalletAdapter, WalletError, WalletId, type WalletInfo, WalletNotFoundError, WalletRegistry, WebClient, type WebClientOptions, WebREST, type WebRESTOptions, type WebRequestOptions, XBullAdapter, buildPaymentXdr, classifyNetwork, defaultAdapters, isPassphrase, isSep7Uri, loadStellarSdk, normalizeIntent, parseSep7, postToCallback, resolveNetwork, submitToHorizon, transactionHash };
@@ -1,5 +1,7 @@
1
- import { a4 as WalletId, P as PaymentIntentData, h as CreatePayPaymentIntentOptions, g as CreateTxPaymentIntentOptions, V as ValidationOutcomeData } from '../intent-input-Ch8ogEg-.js';
2
- export { F as AddressBook, G as AddressRef, O as AssetDefinition, R as AssetRef, T as Assets, X as CosmosPayAPIError, Y as CosmosPayRequestError, $ as ResolvableIntentInput, a0 as ResolvedAsset, a3 as TestnetAssets, a5 as Wallets, a8 as addresses, a9 as assertAddress, aa as defineAsset, ab as isAddress, ac as isContractAddress, ad as isMuxedAddress, ae as isNativeAsset, af as isStellarAddress, ag as resolveAddress, ah as resolveAsset, ai as resolveIntentBody } from '../intent-input-Ch8ogEg-.js';
1
+ import { bG as WalletId, an as PaymentIntentData, au as CreatePayPaymentIntentOptions, at as CreateTxPaymentIntentOptions, as as ValidationOutcomeData } from '../intent-input-BtUp3tFN.js';
2
+ export { aW as AddressBook, aX as AddressRef, b1 as AssetDefinition, b2 as AssetRef, b3 as Assets, b7 as CosmosPayAPIError, b8 as CosmosPayRequestError, bB as ResolvableIntentInput, bC as ResolvedAsset, bF as TestnetAssets, bH as Wallets, bK as addresses, bL as assertAddress, bM as defineAsset, bN as isAddress, bO as isContractAddress, bP as isMuxedAddress, bQ as isNativeAsset, bR as isStellarAddress, bS as resolveAddress, bT as resolveAsset, bU as resolveIntentBody } from '../intent-input-BtUp3tFN.js';
3
+ import { C as CosmosProviderOptions, a as CosmosWalletProvider } from '../cosmosProvider-CFASjnd5.js';
4
+ export { i as injectedProvider, l as loadHostedProvider, r as resetProviderCache, b as resolveProvider } from '../cosmosProvider-CFASjnd5.js';
3
5
 
4
6
  /**
5
7
  * Types for the browser ("web client") side of the SDK.
@@ -358,11 +360,49 @@ declare class AlbedoAdapter implements WalletAdapter {
358
360
  signTransaction(xdr: string, params: SignParams): Promise<string>;
359
361
  }
360
362
 
363
+ /**
364
+ * Cosmos Wallet — https://github.com/CosmosPay/CosmosPay-Wallet
365
+ *
366
+ * Cosmos Pay's own non-custodial Stellar wallet. It reaches the page two ways and
367
+ * this adapter serves both: the browser extension injects `window.cosmosWallet`,
368
+ * and the hosted build is loaded from the wallet's own origin when `walletUrl` is
369
+ * configured (see `@/web/cosmosProvider`). Everything below is the same either way.
370
+ *
371
+ * It is the only adapter here that is first-party, which is exactly why it is not
372
+ * privileged: it sits in the same detection order as the rest and answers the same
373
+ * three questions. A wallet that needed special treatment in the client would be a
374
+ * wallet the client could not swap out.
375
+ */
376
+
377
+ declare class CosmosWalletAdapter implements WalletAdapter {
378
+ readonly id = "cosmos";
379
+ readonly name = "Cosmos Wallet";
380
+ private readonly options;
381
+ /**
382
+ * @param options - A provider to use directly, or the origin of a hosted Cosmos
383
+ * Wallet to fall back to. Both optional: with the extension installed there is
384
+ * nothing to configure.
385
+ */
386
+ constructor(options?: CosmosProviderOptions | CosmosWalletProvider);
387
+ /**
388
+ * Available when a provider is already here, or when a hosted wallet is
389
+ * configured — the hosted build needs no install, so it is always usable.
390
+ *
391
+ * Deliberately does NOT wait for the hosted script: this answer gates a modal,
392
+ * and a wallet that takes a network round trip to say "yes" reads as broken. The
393
+ * script is fetched on the first real call instead.
394
+ */
395
+ isAvailable(): Promise<boolean>;
396
+ private provider;
397
+ getPublicKey(_network: NetworkConfig): Promise<string>;
398
+ signTransaction(xdr: string, params: SignParams): Promise<string>;
399
+ }
400
+
361
401
  /**
362
402
  * Built-in wallet adapters and the default registration set.
363
403
  *
364
404
  * Auto-detection order (first available wins): Freighter → xBull → Rabet →
365
- * LOBSTR → Albedo. Freighter, xBull and Rabet inject browser globals so they're
405
+ * LOBSTR → Albedo → Cosmos Wallet. Freighter, xBull and Rabet inject browser globals so they're
366
406
  * detected with zero configuration; LOBSTR and Albedo need their library passed
367
407
  * in (no reliable global), so they only activate when injected.
368
408
  */
@@ -383,6 +423,11 @@ interface InjectedWallets {
383
423
  albedo?: any;
384
424
  /** A `@lobstrco/signer-extension-api` module. */
385
425
  lobstr?: any;
426
+ /**
427
+ * A Cosmos Wallet provider, or `{ walletUrl }` to reach the HOSTED wallet when
428
+ * the extension is absent (otherwise `window.cosmosWallet`).
429
+ */
430
+ cosmos?: CosmosWalletProvider | CosmosProviderOptions;
386
431
  }
387
432
  /**
388
433
  * Build the default adapter set, honoring any injected wallet libraries. The
@@ -755,4 +800,4 @@ declare class WebREST {
755
800
  request<T>(method: string, path: string, options?: WebRequestOptions): Promise<T>;
756
801
  }
757
802
 
758
- export { AlbedoAdapter, type BuildPaymentInput, type ConnectResult, CosmosPayWebError, FreighterAdapter, HORIZON_URLS, type InjectedWallets, IntentError, LobstrAdapter, type NetworkConfig, type NormalizedIntent, PASSPHRASES, type PayOptions, type PayResult, type PayableInput, PaymentIntentData, RabetAdapter, type ResolveNetworkInput, type Sep7Request, type SignParams, type StellarNetwork, type StellarSdkLike, StellarSdkRequiredError, type WalletAdapter, WalletError, WalletId, type WalletInfo, WalletNotFoundError, WalletRegistry, WebClient, type WebClientOptions, WebREST, type WebRESTOptions, type WebRequestOptions, XBullAdapter, buildPaymentXdr, classifyNetwork, defaultAdapters, isPassphrase, isSep7Uri, loadStellarSdk, normalizeIntent, parseSep7, postToCallback, resolveNetwork, submitToHorizon, transactionHash };
803
+ export { AlbedoAdapter, type BuildPaymentInput, type ConnectResult, CosmosPayWebError, CosmosProviderOptions, CosmosWalletAdapter, CosmosWalletProvider, FreighterAdapter, HORIZON_URLS, type InjectedWallets, IntentError, LobstrAdapter, type NetworkConfig, type NormalizedIntent, PASSPHRASES, type PayOptions, type PayResult, type PayableInput, PaymentIntentData, RabetAdapter, type ResolveNetworkInput, type Sep7Request, type SignParams, type StellarNetwork, type StellarSdkLike, StellarSdkRequiredError, type WalletAdapter, WalletError, WalletId, type WalletInfo, WalletNotFoundError, WalletRegistry, WebClient, type WebClientOptions, WebREST, type WebRESTOptions, type WebRequestOptions, XBullAdapter, buildPaymentXdr, classifyNetwork, defaultAdapters, isPassphrase, isSep7Uri, loadStellarSdk, normalizeIntent, parseSep7, postToCallback, resolveNetwork, submitToHorizon, transactionHash };
package/dist/web/index.js CHANGED
@@ -1,5 +1,7 @@
1
- import { version, CosmosPayAPIError, CosmosPayRequestError, DEFAULT_BASE_URL, resolveIntentBody } from '../chunk-TZDZBVFS.js';
2
- export { AddressBook, Assets, CosmosPayAPIError, CosmosPayRequestError, TestnetAssets, Wallets, addresses, assertAddress, defineAsset, isAddress, isContractAddress, isMuxedAddress, isNativeAsset, isStellarAddress, resolveAddress, resolveAsset, resolveIntentBody } from '../chunk-TZDZBVFS.js';
1
+ import { version, CosmosPayAPIError, CosmosPayRequestError, DEFAULT_BASE_URL, resolveIntentBody } from '../chunk-TM4HAKWE.js';
2
+ export { AddressBook, Assets, CosmosPayAPIError, CosmosPayRequestError, TestnetAssets, Wallets, addresses, assertAddress, defineAsset, isAddress, isContractAddress, isMuxedAddress, isNativeAsset, isStellarAddress, resolveAddress, resolveAsset, resolveIntentBody } from '../chunk-TM4HAKWE.js';
3
+ import { injectedProvider, resolveProvider } from '../chunk-AYVWYEOK.js';
4
+ export { injectedProvider, loadHostedProvider, resetProviderCache, resolveProvider } from '../chunk-AYVWYEOK.js';
3
5
 
4
6
  // src/web/errors.ts
5
7
  var CosmosPayWebError = class _CosmosPayWebError extends Error {
@@ -316,6 +318,61 @@ var AlbedoAdapter = class {
316
318
  }
317
319
  };
318
320
 
321
+ // src/web/adapters/CosmosWalletAdapter.ts
322
+ var CosmosWalletAdapter = class {
323
+ /**
324
+ * @param options - A provider to use directly, or the origin of a hosted Cosmos
325
+ * Wallet to fall back to. Both optional: with the extension installed there is
326
+ * nothing to configure.
327
+ */
328
+ constructor(options = {}) {
329
+ this.id = "cosmos";
330
+ this.name = "Cosmos Wallet";
331
+ this.options = isProvider(options) ? { provider: options } : options;
332
+ }
333
+ /**
334
+ * Available when a provider is already here, or when a hosted wallet is
335
+ * configured — the hosted build needs no install, so it is always usable.
336
+ *
337
+ * Deliberately does NOT wait for the hosted script: this answer gates a modal,
338
+ * and a wallet that takes a network round trip to say "yes" reads as broken. The
339
+ * script is fetched on the first real call instead.
340
+ */
341
+ async isAvailable() {
342
+ if (this.options.provider) return true;
343
+ if (injectedProvider()) return true;
344
+ return !!this.options.walletUrl;
345
+ }
346
+ async provider() {
347
+ const provider = await resolveProvider(this.options);
348
+ if (!provider) throw new WalletError(this.id, "Cosmos Wallet is not available.");
349
+ return provider;
350
+ }
351
+ async getPublicKey(_network) {
352
+ try {
353
+ const provider = await this.provider();
354
+ return unwrap(await provider.getAddress(), "address");
355
+ } catch (error) {
356
+ throw new WalletError(this.id, errorMessage(error), error);
357
+ }
358
+ }
359
+ async signTransaction(xdr, params) {
360
+ try {
361
+ const provider = await this.provider();
362
+ const result = await provider.signTransaction(xdr, {
363
+ networkPassphrase: params.networkPassphrase,
364
+ address: params.address
365
+ });
366
+ return unwrap(result, "signedTxXdr");
367
+ } catch (error) {
368
+ throw new WalletError(this.id, errorMessage(error), error);
369
+ }
370
+ }
371
+ };
372
+ function isProvider(value) {
373
+ return typeof value.signTransaction === "function";
374
+ }
375
+
319
376
  // src/web/adapters/index.ts
320
377
  function defaultAdapters(injected = {}) {
321
378
  return [
@@ -323,7 +380,13 @@ function defaultAdapters(injected = {}) {
323
380
  new XBullAdapter(injected.xBull),
324
381
  new RabetAdapter(injected.rabet),
325
382
  new LobstrAdapter(injected.lobstr),
326
- new AlbedoAdapter(injected.albedo)
383
+ new AlbedoAdapter(injected.albedo),
384
+ // Appended LAST on purpose. Auto-detection takes the first available adapter,
385
+ // so putting the first-party wallet at the front would silently move an
386
+ // existing integration off Freighter the day a user installs Cosmos Wallet.
387
+ // A dapp that wants it preferred says so — `pay({ wallet: Wallets.COSMOS })`,
388
+ // or `registry.register(adapter, true)`.
389
+ new CosmosWalletAdapter(injected.cosmos ?? {})
327
390
  ];
328
391
  }
329
392
 
@@ -1010,6 +1073,6 @@ function extractHash(response) {
1010
1073
  return "";
1011
1074
  }
1012
1075
 
1013
- export { AlbedoAdapter, CosmosPayWebError, FreighterAdapter, HORIZON_URLS, IntentError, LobstrAdapter, PASSPHRASES, RabetAdapter, StellarSdkRequiredError, WalletError, WalletNotFoundError, WalletRegistry, WebClient, WebREST, XBullAdapter, buildPaymentXdr, classifyNetwork, defaultAdapters, isPassphrase, isSep7Uri, loadStellarSdk, normalizeIntent, parseSep7, postToCallback, resolveNetwork, submitToHorizon, transactionHash };
1076
+ export { AlbedoAdapter, CosmosPayWebError, CosmosWalletAdapter, FreighterAdapter, HORIZON_URLS, IntentError, LobstrAdapter, PASSPHRASES, RabetAdapter, StellarSdkRequiredError, WalletError, WalletNotFoundError, WalletRegistry, WebClient, WebREST, XBullAdapter, buildPaymentXdr, classifyNetwork, defaultAdapters, isPassphrase, isSep7Uri, loadStellarSdk, normalizeIntent, parseSep7, postToCallback, resolveNetwork, submitToHorizon, transactionHash };
1014
1077
  //# sourceMappingURL=index.js.map
1015
1078
  //# sourceMappingURL=index.js.map