@cosmosapp/pay_sdk 2.3.2 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +97 -61
- package/dist/{chunk-U3WDM2FJ.js → chunk-6FIALX2E.js} +3 -3
- package/dist/{chunk-U3WDM2FJ.js.map → chunk-6FIALX2E.js.map} +1 -1
- package/dist/chunk-ALFITFBN.js +105 -0
- package/dist/chunk-ALFITFBN.js.map +1 -0
- package/dist/chunk-PAQHOXQ6.js +392 -0
- package/dist/chunk-PAQHOXQ6.js.map +1 -0
- package/dist/errors-CZu5mmz1.d.cts +293 -0
- package/dist/errors-Cqh7UdUO.d.ts +293 -0
- package/dist/index.cjs +18 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -7
- package/dist/index.d.ts +12 -7
- package/dist/index.js +19 -6
- package/dist/index.js.map +1 -1
- package/dist/intent-input-BybnwL83.d.ts +126 -0
- package/dist/intent-input-C2PTr2XH.d.cts +126 -0
- package/dist/swk/index.js +1 -103
- package/dist/swk/index.js.map +1 -1
- package/dist/wallets/index.cjs +1043 -0
- package/dist/wallets/index.cjs.map +1 -0
- package/dist/wallets/index.d.cts +384 -0
- package/dist/wallets/index.d.ts +384 -0
- package/dist/wallets/index.js +629 -0
- package/dist/wallets/index.js.map +1 -0
- package/dist/{intent-input-CP5bkBYI.d.cts → wallets-CeIjESt5.d.cts} +39 -126
- package/dist/{intent-input-CP5bkBYI.d.ts → wallets-CeIjESt5.d.ts} +39 -126
- package/dist/web/index.cjs +1 -1
- package/dist/web/index.cjs.map +1 -1
- package/dist/web/index.d.cts +7 -292
- package/dist/web/index.d.ts +7 -292
- package/dist/web/index.js +5 -391
- package/dist/web/index.js.map +1 -1
- package/llms/07-webhooks.md +2 -0
- package/llms/15-swaps.md +2 -0
- package/llms/18-wallets.md +94 -0
- package/llms/llms-full.txt +101 -0
- package/llms/llms.txt +1 -0
- package/package.json +22 -8
package/llms/llms-full.txt
CHANGED
|
@@ -596,6 +596,8 @@ Event types (`WebhookEventType`, the same list the API accepts in `eventTypes`):
|
|
|
596
596
|
`LIQUIDITY_FAILED`, `LIQUIDITY_EXPIRED`.
|
|
597
597
|
- Fiat ramps: `RECEIVER_UPDATED`, `PAYIN_CREATED`, `PAYIN_UPDATED`, `PAYIN_COMPLETED`,
|
|
598
598
|
`PAYOUT_CREATED`, `PAYOUT_UPDATED`, `PAYOUT_COMPLETED`.
|
|
599
|
+
- Protected payments (held in a contract until delivery; `data` untyped for now):
|
|
600
|
+
`PROTECTED_PAYMENT_CREATED`, `PROTECTED_PAYMENT_FUNDED`, `PROTECTED_PAYMENT_SHIPPED`, `PROTECTED_PAYMENT_APPROVED`, `PROTECTED_PAYMENT_RELEASED`, `PROTECTED_PAYMENT_DISPUTED`, `PROTECTED_PAYMENT_RESOLVED`, `PROTECTED_PAYMENT_DEADLINE_PASSED`, `PROTECTED_PAYMENT_EXPIRED`, `PROTECTED_PAYMENT_CANCELLED`.
|
|
599
601
|
|
|
600
602
|
A same-chain swap (`SWAP_EXPIRED`) or a liquidity operation (`LIQUIDITY_EXPIRED`) can
|
|
601
603
|
still settle if its transaction lands late: the API then sends `SWAP_SUCCEEDED` or
|
|
@@ -1131,6 +1133,8 @@ await sol.submit({ signedTransaction });
|
|
|
1131
1133
|
const mon = await client.swaps.create({ chain: 'monad', amount: '10', sourceAssetCode: 'MON',
|
|
1132
1134
|
destAssetCode: '0x754704bc059f8c67012fed69bc8a327a5aafb603', source: evmWallet });
|
|
1133
1135
|
if (mon.approval) await wallet.sendTransaction(mon.approval);
|
|
1136
|
+
// A browser wallet (MetaMask...) sends the swap itself: report its hash instead.
|
|
1137
|
+
// await mon.submit({ txHash }); see @cosmosapp/pay_sdk/wallets
|
|
1134
1138
|
|
|
1135
1139
|
const page = await client.swaps.list({ chain: 'solana' }); // ChainSwap[]
|
|
1136
1140
|
```
|
|
@@ -1323,3 +1327,100 @@ shared public key. Any other key ignores the token.
|
|
|
1323
1327
|
`guid`, `destinationTxHash`, `scanStatus`, `scanUrl`, `failureReason`,
|
|
1324
1328
|
`merchantFee`, `idempotencyKey`, `expiresAt`, `submittedAt`, `createdAt`,
|
|
1325
1329
|
`updatedAt`, `publicToken`, plus `isPending`, `isDelivered`, `isFinal`.
|
|
1330
|
+
|
|
1331
|
+
---
|
|
1332
|
+
|
|
1333
|
+
# Wallets: Stellar, EVM and Solana
|
|
1334
|
+
|
|
1335
|
+
`@cosmosapp/pay_sdk/wallets` finds every wallet a person can sign with in their browser and
|
|
1336
|
+
gives each the same small shape, whatever its ecosystem. It bundles no wallet library: each
|
|
1337
|
+
ecosystem is reached through its own open standard.
|
|
1338
|
+
|
|
1339
|
+
| Ecosystem | Reached through | Wallets |
|
|
1340
|
+
| --- | --- | --- |
|
|
1341
|
+
| `stellar` | the SDK's adapters, the providers wallets inject, plus a Stellar Wallets Kit when passed | Freighter (now Varial), xBull, Rabet, LOBSTR, Albedo, Cosmos Pay Wallet, Hana, Klever, OneKey, Bitget, Cactus Link, D'CENT, Scopuly; with a kit also MetaMask (Stellar Snap), Ledger, Trezor, WalletConnect... |
|
|
1342
|
+
| `evm` | EIP-6963 announcements, else `window.ethereum` | MetaMask, Rabby, Coinbase Wallet, OKX, Trust, Brave... |
|
|
1343
|
+
| `solana` | Wallet Standard (`wallet-standard:register-wallet` / `app-ready`) | Phantom, Solflare, Backpack... |
|
|
1344
|
+
|
|
1345
|
+
```ts
|
|
1346
|
+
import { discoverWallets, EvmChains, isUserRejection } from '@cosmosapp/pay_sdk/wallets';
|
|
1347
|
+
|
|
1348
|
+
const { stellar, evm, solana } = await discoverWallets(); // each an array, possibly empty
|
|
1349
|
+
```
|
|
1350
|
+
|
|
1351
|
+
Every wallet has `id` (`stellar:freighter`, `evm:io.metamask`, `solana:phantom`), `name`,
|
|
1352
|
+
`icon` (the wallet's own, when it gives one) and `ecosystem`. Outside a browser every list is
|
|
1353
|
+
empty. Pass `{ ecosystems: ['evm'] }` to look in one ecosystem only.
|
|
1354
|
+
|
|
1355
|
+
## Stellar
|
|
1356
|
+
|
|
1357
|
+
```ts
|
|
1358
|
+
const wallet = stellar[0];
|
|
1359
|
+
const address = await wallet.connect('public'); // or 'testnet'
|
|
1360
|
+
const signedXdr = await wallet.signTransaction(xdr, { network: 'public', address });
|
|
1361
|
+
await swap.submit({ signedXdr });
|
|
1362
|
+
```
|
|
1363
|
+
|
|
1364
|
+
Hana, Klever, OneKey, Bitget, Cactus Link, D'CENT and Scopuly inject a provider into the page and
|
|
1365
|
+
are found with no library. With a Stellar Wallets Kit, its wallets join the list too (a wallet
|
|
1366
|
+
reached several ways is listed once, with the kit's name and icon). Kit v2's static class and a v1
|
|
1367
|
+
instance both work:
|
|
1368
|
+
|
|
1369
|
+
```ts
|
|
1370
|
+
import { StellarWalletsKit } from '@creit.tech/stellar-wallets-kit/sdk';
|
|
1371
|
+
import { defaultModules } from '@creit.tech/stellar-wallets-kit/modules/utils';
|
|
1372
|
+
|
|
1373
|
+
StellarWalletsKit.init({ modules: defaultModules() });
|
|
1374
|
+
const { stellar } = await discoverWallets({ stellar: { kit: StellarWalletsKit } });
|
|
1375
|
+
```
|
|
1376
|
+
|
|
1377
|
+
`stellar.injected` passes wallet libraries that have no global (LOBSTR, Albedo, a hosted Cosmos
|
|
1378
|
+
Pay Wallet), as in `WebClient`.
|
|
1379
|
+
|
|
1380
|
+
## EVM (Monad)
|
|
1381
|
+
|
|
1382
|
+
EVM wallets cannot hand a signed transaction back: they sign and broadcast it themselves, so
|
|
1383
|
+
`sendTransaction` answers the transaction hash. It switches the wallet to the transaction's chain
|
|
1384
|
+
first, adding the chain when the wallet does not know it (`EvmChains.monad`,
|
|
1385
|
+
`EvmChains.monadTestnet`).
|
|
1386
|
+
|
|
1387
|
+
```ts
|
|
1388
|
+
const wallet = evm.find((w) => w.rdns === 'io.metamask') ?? evm[0];
|
|
1389
|
+
const from = await wallet.connect();
|
|
1390
|
+
if (swap.approval) {
|
|
1391
|
+
const approval = await wallet.sendTransaction({ from, ...swap.approval }, EvmChains.monad);
|
|
1392
|
+
await wallet.waitForTransaction(approval); // the swap needs the allowance mined
|
|
1393
|
+
}
|
|
1394
|
+
const txHash = await wallet.sendTransaction({ from, ...swap.transaction }, EvmChains.monad);
|
|
1395
|
+
await swap.submit({ txHash });
|
|
1396
|
+
```
|
|
1397
|
+
|
|
1398
|
+
The node may not know a just-sent transaction yet: `submit({ txHash })` then fails with
|
|
1399
|
+
`400 transaction_not_found` and records nothing, so retry it after a few seconds.
|
|
1400
|
+
|
|
1401
|
+
A cross-chain swap's EVM `depositUri` is an EIP-681 link: `parseEip681(uri)` turns it into the
|
|
1402
|
+
transaction (`{ chainId, to, value }` or an ERC-20 `transfer`), so
|
|
1403
|
+
`wallet.sendTransaction({ from, ...parseEip681(swap.depositUri) })` pays the deposit.
|
|
1404
|
+
|
|
1405
|
+
`wallet.provider` is the wallet's EIP-1193 provider for anything else. `erc20TransferData(to,
|
|
1406
|
+
amount)` builds a token transfer's call data; `toQuantity` turns a decimal amount of wei into the
|
|
1407
|
+
hex a wallet takes.
|
|
1408
|
+
|
|
1409
|
+
## Solana
|
|
1410
|
+
|
|
1411
|
+
```ts
|
|
1412
|
+
const wallet = solana[0];
|
|
1413
|
+
const address = await wallet.connect();
|
|
1414
|
+
const signedTransaction = await wallet.signTransaction(swap.transaction.data); // base64 in and out
|
|
1415
|
+
await swap.submit({ signedTransaction });
|
|
1416
|
+
```
|
|
1417
|
+
|
|
1418
|
+
`signTransaction` signs without broadcasting, so the API can check the transaction and relay it.
|
|
1419
|
+
`signAndSendTransaction` (when `canSignAndSend`) broadcasts too and answers the signature.
|
|
1420
|
+
Chains are `solana:mainnet` (the default), `solana:devnet` and `solana:testnet`.
|
|
1421
|
+
|
|
1422
|
+
## Errors
|
|
1423
|
+
|
|
1424
|
+
A wallet's failure is a `WalletError` (`error.wallet` is the wallet id, `error.cause` the
|
|
1425
|
+
wallet's own error). `isUserRejection(error)` tells the person declining (closing the prompt,
|
|
1426
|
+
pressing reject, EIP-1193 code 4001) from a failure worth reporting.
|
package/llms/llms.txt
CHANGED
|
@@ -38,6 +38,7 @@ The files below are atomic and self-contained — read the ones relevant to the
|
|
|
38
38
|
- [Swaps](./15-swaps.md): same-chain swaps (Stellar DEX, Jupiter on Solana, Kuru Flow on Monad) and cross-chain swaps (NEAR Intents)
|
|
39
39
|
- [Private payments](./16-private-payments.md): payments whose amount is hidden on-chain (Stellar Testnet for now, 0.18% commission)
|
|
40
40
|
- [USDT0](./17-usdt0.md): send USDT0 from Stellar to EVM networks through LayerZero (mainnet only)
|
|
41
|
+
- [Wallets](./18-wallets.md): `@cosmosapp/pay_sdk/wallets`, every Stellar, EVM and Solana wallet in the browser behind one shape (connect, sign, send)
|
|
41
42
|
|
|
42
43
|
## Optional
|
|
43
44
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmosapp/pay_sdk",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "Official SDK for Cosmos Pay, the stablecoin payments API for Stellar, Solana and Monad: payment intents and checkout, webhooks, swaps (same-chain and cross-chain), fiat ramps, products and customers. Payment links on all three (SEP-7, Solana Pay, EIP-681). Includes a browser client for Stellar wallets.",
|
|
3
|
+
"version": "2.4.0",
|
|
4
|
+
"description": "Official SDK for Cosmos Pay, the stablecoin payments API for Stellar, Solana and Monad: payment intents and checkout, webhooks, swaps (same-chain and cross-chain), fiat ramps, products and customers. Payment links on all three (SEP-7, Solana Pay, EIP-681). Includes a browser client for Stellar wallets and a wallets module that reaches every Stellar, EVM (EIP-6963) and Solana (Wallet Standard) wallet.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cosmos-pay",
|
|
7
7
|
"cosmos",
|
|
@@ -27,7 +27,11 @@
|
|
|
27
27
|
"xbull",
|
|
28
28
|
"albedo",
|
|
29
29
|
"rabet",
|
|
30
|
-
"lobstr"
|
|
30
|
+
"lobstr",
|
|
31
|
+
"metamask",
|
|
32
|
+
"phantom",
|
|
33
|
+
"eip-6963",
|
|
34
|
+
"wallet-standard"
|
|
31
35
|
],
|
|
32
36
|
"license": "Apache-2.0",
|
|
33
37
|
"author": "Cosmos Pay",
|
|
@@ -74,6 +78,16 @@
|
|
|
74
78
|
"default": "./dist/swk/index.cjs"
|
|
75
79
|
}
|
|
76
80
|
},
|
|
81
|
+
"./wallets": {
|
|
82
|
+
"import": {
|
|
83
|
+
"types": "./dist/wallets/index.d.ts",
|
|
84
|
+
"default": "./dist/wallets/index.js"
|
|
85
|
+
},
|
|
86
|
+
"require": {
|
|
87
|
+
"types": "./dist/wallets/index.d.cts",
|
|
88
|
+
"default": "./dist/wallets/index.cjs"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
77
91
|
"./package.json": "./package.json"
|
|
78
92
|
},
|
|
79
93
|
"files": [
|
|
@@ -92,8 +106,8 @@
|
|
|
92
106
|
"dev": "tsup --watch",
|
|
93
107
|
"typecheck": "tsc --noEmit",
|
|
94
108
|
"pretest": "npm run build",
|
|
95
|
-
"test": "node --test test/client.test.mjs test/rest.test.mjs test/payment-intents.test.mjs test/swaps.test.mjs test/webhooks.test.mjs test/structures.test.mjs test/web.test.mjs test/catalogs.test.mjs test/cosmos-wallet.test.mjs test/liquidity.test.mjs test/ramps.test.mjs test/kyc.test.mjs test/aliases-assets.test.mjs test/cross-chain-swaps.test.mjs test/extensions.test.mjs test/customers-analytics.test.mjs test/private-payments.test.mjs test/usdt0.test.mjs test/openapi.test.mjs",
|
|
96
|
-
"test:watch": "node --test --watch test/client.test.mjs test/rest.test.mjs test/payment-intents.test.mjs test/swaps.test.mjs test/webhooks.test.mjs test/structures.test.mjs test/web.test.mjs test/catalogs.test.mjs test/cosmos-wallet.test.mjs test/liquidity.test.mjs test/ramps.test.mjs test/kyc.test.mjs test/aliases-assets.test.mjs test/cross-chain-swaps.test.mjs test/extensions.test.mjs test/customers-analytics.test.mjs test/private-payments.test.mjs test/usdt0.test.mjs test/openapi.test.mjs",
|
|
109
|
+
"test": "node --test test/client.test.mjs test/rest.test.mjs test/payment-intents.test.mjs test/swaps.test.mjs test/webhooks.test.mjs test/structures.test.mjs test/web.test.mjs test/catalogs.test.mjs test/cosmos-wallet.test.mjs test/liquidity.test.mjs test/ramps.test.mjs test/kyc.test.mjs test/aliases-assets.test.mjs test/cross-chain-swaps.test.mjs test/extensions.test.mjs test/customers-analytics.test.mjs test/private-payments.test.mjs test/usdt0.test.mjs test/wallets.test.mjs test/openapi.test.mjs",
|
|
110
|
+
"test:watch": "node --test --watch test/client.test.mjs test/rest.test.mjs test/payment-intents.test.mjs test/swaps.test.mjs test/webhooks.test.mjs test/structures.test.mjs test/web.test.mjs test/catalogs.test.mjs test/cosmos-wallet.test.mjs test/liquidity.test.mjs test/ramps.test.mjs test/kyc.test.mjs test/aliases-assets.test.mjs test/cross-chain-swaps.test.mjs test/extensions.test.mjs test/customers-analytics.test.mjs test/private-payments.test.mjs test/usdt0.test.mjs test/wallets.test.mjs test/openapi.test.mjs",
|
|
97
111
|
"prepublishOnly": "npm run build",
|
|
98
112
|
"changelog": "npx --yes git-cliff@2 -o CHANGELOG.md",
|
|
99
113
|
"llms": "node scripts/build-llms.mjs",
|
|
@@ -102,9 +116,9 @@
|
|
|
102
116
|
"openapi:check": "node scripts/sync-openapi.mjs --check"
|
|
103
117
|
},
|
|
104
118
|
"devDependencies": {
|
|
105
|
-
"@types/node": "^26.6.
|
|
106
|
-
"rimraf": "^6.1.
|
|
107
|
-
"semver": "^7.8.
|
|
119
|
+
"@types/node": "^26.6.6",
|
|
120
|
+
"rimraf": "^6.1.4",
|
|
121
|
+
"semver": "^7.8.6",
|
|
108
122
|
"tsup": "^9.0.0",
|
|
109
123
|
"typescript": "^5.9.3"
|
|
110
124
|
},
|