@cosmosapp/pay_sdk 2.0.0 → 2.2.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/dist/index.cjs CHANGED
@@ -5,6 +5,84 @@ var crypto = require('crypto');
5
5
 
6
6
  // src/client/Client.ts
7
7
 
8
+ // src/managers/AliasManager.ts
9
+ var AliasManager = class {
10
+ constructor(client) {
11
+ this.route = "/aliases";
12
+ this.client = client;
13
+ }
14
+ get rest() {
15
+ return this.client.rest;
16
+ }
17
+ /** Where to pay a handle: its verified addresses on a network, primary first. */
18
+ resolve(name, options = {}) {
19
+ return this.rest.get(`${this.route}/resolve/${encodeURIComponent(name)}`, {
20
+ query: { network: options.network }
21
+ });
22
+ }
23
+ /** Whether a handle can be claimed, and if not, why not. */
24
+ availability(name) {
25
+ return this.rest.get(`${this.route}/availability/${encodeURIComponent(name)}`);
26
+ }
27
+ /** Which handles point at an address — the reverse lookup. */
28
+ byAddress(address, options = {}) {
29
+ return this.rest.get(`${this.route}/by-address/${encodeURIComponent(address)}`, {
30
+ query: { network: options.network }
31
+ });
32
+ }
33
+ /** A nonce and the exact message to sign, for a claim, a new address or a recovery. */
34
+ createChallenge(options) {
35
+ return this.rest.post(`${this.route}/challenges`, { body: options });
36
+ }
37
+ /** Claim a handle with a signature over a CLAIM challenge. */
38
+ claim(options) {
39
+ return this.rest.post(this.route, { body: options });
40
+ }
41
+ /** The handles this consumer owns (paginated). */
42
+ list(options = {}) {
43
+ return this.rest.get(this.route, {
44
+ query: { take: options.take, skip: options.skip }
45
+ });
46
+ }
47
+ /** Point a handle at another address, signed by that address (ADD_ADDRESS challenge). */
48
+ addAddress(name, options) {
49
+ return this.rest.post(`${this.route}/${encodeURIComponent(name)}/addresses`, {
50
+ body: options
51
+ });
52
+ }
53
+ /** Remove one address from a handle. */
54
+ removeAddress(name, addressId) {
55
+ return this.rest.delete(
56
+ `${this.route}/${encodeURIComponent(name)}/addresses/${encodeURIComponent(addressId)}`
57
+ );
58
+ }
59
+ /** Release a handle back to the namespace. */
60
+ release(name) {
61
+ return this.rest.delete(`${this.route}/${encodeURIComponent(name)}`);
62
+ }
63
+ /**
64
+ * Start a recovery: the service emails a one-time token to the mailbox the
65
+ * handle was claimed with, if `email` is that mailbox. The answer is the same
66
+ * either way, so it says nothing about who owns the handle; the token only
67
+ * ever reaches the mailbox, never this response.
68
+ */
69
+ startRecovery(name, email) {
70
+ return this.rest.post(`${this.route}/${encodeURIComponent(name)}/recovery`, {
71
+ body: { email }
72
+ });
73
+ }
74
+ /**
75
+ * Take a handle over with a new address after losing the old one: the token
76
+ * the owner received by email, plus a signature by the new address over a
77
+ * RECOVER challenge.
78
+ */
79
+ completeRecovery(name, options) {
80
+ return this.rest.post(`${this.route}/${encodeURIComponent(name)}/recovery/complete`, {
81
+ body: options
82
+ });
83
+ }
84
+ };
85
+
8
86
  // src/managers/AnalyticsManager.ts
9
87
  var AnalyticsManager = class {
10
88
  constructor(client) {
@@ -31,6 +109,23 @@ var AnalyticsManager = class {
31
109
  }
32
110
  };
33
111
 
112
+ // src/managers/AssetManager.ts
113
+ var AssetManager = class {
114
+ constructor(client) {
115
+ this.route = "/assets";
116
+ this.client = client;
117
+ }
118
+ get rest() {
119
+ return this.client.rest;
120
+ }
121
+ /** The registry for a network. */
122
+ list(options = {}) {
123
+ return this.rest.get(this.route, {
124
+ query: { network: options.network, verified: options.verified }
125
+ });
126
+ }
127
+ };
128
+
34
129
  // src/structures/Base.ts
35
130
  var Base = class {
36
131
  constructor(client, data) {
@@ -204,7 +299,32 @@ var WebhookEventType = {
204
299
  PaymentIntentSucceeded: "PAYMENT_INTENT_SUCCEEDED",
205
300
  PaymentIntentFailed: "PAYMENT_INTENT_FAILED",
206
301
  PaymentIntentCancelled: "PAYMENT_INTENT_CANCELLED",
207
- PaymentIntentDeleted: "PAYMENT_INTENT_DELETED"
302
+ PaymentIntentDeleted: "PAYMENT_INTENT_DELETED",
303
+ // Fiat (BlindPay), re-emitted once the server syncs them.
304
+ ReceiverUpdated: "RECEIVER_UPDATED",
305
+ PayinCreated: "PAYIN_CREATED",
306
+ PayinUpdated: "PAYIN_UPDATED",
307
+ PayinCompleted: "PAYIN_COMPLETED",
308
+ PayoutCreated: "PAYOUT_CREATED",
309
+ PayoutUpdated: "PAYOUT_UPDATED",
310
+ PayoutCompleted: "PAYOUT_COMPLETED",
311
+ // Same-chain swaps on every chain (Stellar, Solana, Monad).
312
+ SwapCreated: "SWAP_CREATED",
313
+ SwapSubmitted: "SWAP_SUBMITTED",
314
+ SwapSucceeded: "SWAP_SUCCEEDED",
315
+ SwapFailed: "SWAP_FAILED",
316
+ // Liquidity pool operations.
317
+ LiquidityCreated: "LIQUIDITY_CREATED",
318
+ LiquiditySubmitted: "LIQUIDITY_SUBMITTED",
319
+ LiquiditySucceeded: "LIQUIDITY_SUCCEEDED",
320
+ LiquidityFailed: "LIQUIDITY_FAILED",
321
+ // Cross-chain swaps (NEAR Intents).
322
+ CrossChainSwapCreated: "CROSS_CHAIN_SWAP_CREATED",
323
+ CrossChainSwapUpdated: "CROSS_CHAIN_SWAP_UPDATED",
324
+ CrossChainSwapSucceeded: "CROSS_CHAIN_SWAP_SUCCEEDED",
325
+ CrossChainSwapRefunded: "CROSS_CHAIN_SWAP_REFUNDED",
326
+ CrossChainSwapFailed: "CROSS_CHAIN_SWAP_FAILED",
327
+ CrossChainSwapExpired: "CROSS_CHAIN_SWAP_EXPIRED"
208
328
  };
209
329
  var WebhookDeliveryStatus = {
210
330
  Pending: "PENDING",
@@ -228,6 +348,16 @@ var LiquidityOperationKind = {
228
348
  var LiquidityOperationStatus = {
229
349
  Pending: "PENDING",
230
350
  Succeeded: "SUCCEEDED"};
351
+ var CrossChainSwapStatus = {
352
+ AwaitingDeposit: "AWAITING_DEPOSIT",
353
+ DepositDetected: "DEPOSIT_DETECTED",
354
+ IncompleteDeposit: "INCOMPLETE_DEPOSIT",
355
+ Processing: "PROCESSING",
356
+ Succeeded: "SUCCEEDED",
357
+ Refunded: "REFUNDED",
358
+ Failed: "FAILED",
359
+ Expired: "EXPIRED"
360
+ };
231
361
 
232
362
  // src/structures/LiquidityOperation.ts
233
363
  var LiquidityOperation = class extends Base {
@@ -853,96 +983,260 @@ var KycManager = class extends BaseManager {
853
983
  }
854
984
  };
855
985
 
856
- // src/managers/PollarManager.ts
857
- var PollarManager = class {
858
- constructor(client) {
859
- this.route = "/pollar";
860
- this.client = client;
986
+ // src/structures/CrossChainSwap.ts
987
+ var FINAL = [
988
+ CrossChainSwapStatus.Succeeded,
989
+ CrossChainSwapStatus.Refunded,
990
+ CrossChainSwapStatus.Failed
991
+ ];
992
+ var CrossChainSwap = class extends Base {
993
+ constructor(client, data) {
994
+ super(client, data);
861
995
  }
862
- get rest() {
863
- return this.client.rest;
996
+ _patch(data) {
997
+ super._patch(data);
998
+ this.status = data.status;
999
+ this.providerStatus = data.providerStatus;
1000
+ this.network = data.network;
1001
+ this.originChain = data.originChain;
1002
+ this.originAsset = data.originAsset;
1003
+ this.originContract = data.originContract;
1004
+ this.destinationChain = data.destinationChain;
1005
+ this.destinationAsset = data.destinationAsset;
1006
+ this.destinationContract = data.destinationContract;
1007
+ this.amountIn = data.amountIn;
1008
+ this.feeBps = data.feeBps;
1009
+ this.feeAmount = data.feeAmount;
1010
+ this.amountOutEstimated = data.amountOutEstimated;
1011
+ this.amountOutMin = data.amountOutMin;
1012
+ this.slippageBps = data.slippageBps;
1013
+ this.recipient = data.recipient;
1014
+ this.refundTo = data.refundTo;
1015
+ this.depositAddress = data.depositAddress;
1016
+ this.depositMemo = data.depositMemo;
1017
+ this.depositUri = data.depositUri;
1018
+ this.qr = data.qr ?? null;
1019
+ this.depositTxHash = data.depositTxHash;
1020
+ this.amountOut = data.amountOut;
1021
+ this.refundedAmount = data.refundedAmount;
1022
+ this.originTxHashes = data.originTxHashes;
1023
+ this.destinationTxHashes = data.destinationTxHashes;
1024
+ this.timeEstimateSeconds = data.timeEstimateSeconds;
1025
+ this.correlationId = data.correlationId;
1026
+ this.quoteSignature = data.quoteSignature;
1027
+ this.idempotencyKey = data.idempotencyKey;
1028
+ this.expiresAt = new Date(data.expiresAt);
1029
+ this.createdAt = new Date(data.createdAt);
1030
+ this.updatedAt = new Date(data.updatedAt);
1031
+ return this;
864
1032
  }
865
- /* -------------------------------- login -------------------------------- */
866
- /** Start a login and get the URL to send the user to. */
867
- authorize(options) {
868
- return this.rest.post(`${this.route}/oauth/authorize`, { body: options });
1033
+ /** Whether the swap has reached an outcome that will not change. */
1034
+ get isFinal() {
1035
+ return FINAL.includes(this.status);
869
1036
  }
870
- /**
871
- * Poll a login. `status: 'authorized'` carries the bridge `code` to redeem;
872
- * `pending` means keep waiting; anything else is over.
873
- */
874
- session(state) {
875
- return this.rest.get(`${this.route}/oauth/sessions/${state}`);
1037
+ get isSucceeded() {
1038
+ return this.status === CrossChainSwapStatus.Succeeded;
876
1039
  }
877
- /** Redeem the bridge code for a session. Single use — a consumed code is dead. */
878
- token(options) {
879
- return this.rest.post(`${this.route}/oauth/token`, { body: options });
1040
+ /** Re-fetch from the API, updating this instance in place. */
1041
+ async fetch() {
1042
+ const fresh = await this.client.crossChainSwaps.fetch(this.id);
1043
+ return this._patch(fresh.toJSON());
880
1044
  }
881
1045
  /**
882
- * Rotate the token pair. The old refresh token stops working, so store what
883
- * comes back before using it — a rotation you lose is a session you lose.
1046
+ * Report the transaction that paid the deposit address so NEAR Intents starts
1047
+ * without waiting for its indexer. Updates this instance in place.
884
1048
  */
885
- refresh(options) {
886
- return this.rest.post(`${this.route}/oauth/refresh`, { body: options });
1049
+ async reportDeposit(txHash) {
1050
+ const fresh = await this.client.crossChainSwaps.reportDeposit(this.id, txHash);
1051
+ return this._patch(fresh.toJSON());
1052
+ }
1053
+ toJSON() {
1054
+ return {
1055
+ id: this.id,
1056
+ status: this.status,
1057
+ providerStatus: this.providerStatus,
1058
+ network: this.network,
1059
+ originChain: this.originChain,
1060
+ originAsset: this.originAsset,
1061
+ originContract: this.originContract,
1062
+ destinationChain: this.destinationChain,
1063
+ destinationAsset: this.destinationAsset,
1064
+ destinationContract: this.destinationContract,
1065
+ amountIn: this.amountIn,
1066
+ feeBps: this.feeBps,
1067
+ feeAmount: this.feeAmount,
1068
+ amountOutEstimated: this.amountOutEstimated,
1069
+ amountOutMin: this.amountOutMin,
1070
+ slippageBps: this.slippageBps,
1071
+ recipient: this.recipient,
1072
+ refundTo: this.refundTo,
1073
+ depositAddress: this.depositAddress,
1074
+ depositMemo: this.depositMemo,
1075
+ depositUri: this.depositUri,
1076
+ ...this.qr ? { qr: this.qr } : {},
1077
+ depositTxHash: this.depositTxHash,
1078
+ amountOut: this.amountOut,
1079
+ refundedAmount: this.refundedAmount,
1080
+ originTxHashes: this.originTxHashes,
1081
+ destinationTxHashes: this.destinationTxHashes,
1082
+ timeEstimateSeconds: this.timeEstimateSeconds,
1083
+ correlationId: this.correlationId,
1084
+ quoteSignature: this.quoteSignature,
1085
+ idempotencyKey: this.idempotencyKey,
1086
+ expiresAt: this.expiresAt.toISOString(),
1087
+ createdAt: this.createdAt.toISOString(),
1088
+ updatedAt: this.updatedAt.toISOString()
1089
+ };
1090
+ }
1091
+ };
1092
+
1093
+ // src/managers/CrossChainSwapManager.ts
1094
+ var CrossChainSwapManager = class extends BaseManager {
1095
+ constructor() {
1096
+ super(...arguments);
1097
+ this.route = "/cross-chain-swaps";
887
1098
  }
888
- /** Revoke a session — this device, or every one of them. */
889
- logout(options) {
890
- return this.rest.post(`${this.route}/oauth/logout`, { body: options });
1099
+ /** The tokens NEAR Intents can swap on Stellar, Solana and Monad. */
1100
+ async assets() {
1101
+ const { data } = await this.rest.get(
1102
+ `${this.route}/assets`
1103
+ );
1104
+ return data;
891
1105
  }
892
- /** Validate an end-user access token and learn whose it is. */
893
- verifyToken(options) {
894
- return this.rest.post(`${this.route}/tokens/verify`, {
1106
+ /** A dry quote: output, minimum and commission. Persists nothing. */
1107
+ quote(options) {
1108
+ return this.rest.post(`${this.route}/quote`, {
895
1109
  body: options
896
1110
  });
897
1111
  }
898
- /* ------------------------------- wallets ------------------------------- */
899
- /**
900
- * Fund a wallet's XLM base reserve. A Stellar account does not exist until
901
- * something pays for it, which is why a fresh Pollar wallet can have an address
902
- * and still not be on the network.
903
- */
904
- activateWallet(options) {
905
- return this.rest.post(`${this.route}/wallets/activate`, {
1112
+ /** A live quote: the deposit address, memo and wallet link that fund the swap. */
1113
+ async create(options) {
1114
+ const data = await this.rest.post(this.route, {
906
1115
  body: options
907
1116
  });
1117
+ return this._add(new CrossChainSwap(this.client, data));
1118
+ }
1119
+ async fetch(id) {
1120
+ const data = await this.rest.get(`${this.route}/${id}`);
1121
+ return this._add(new CrossChainSwap(this.client, data));
1122
+ }
1123
+ async list(options = {}) {
1124
+ const data = await this.rest.get(this.route, {
1125
+ query: { status: options.status, take: options.take, skip: options.skip }
1126
+ });
1127
+ return {
1128
+ items: data.data.map((d) => this._add(new CrossChainSwap(this.client, d))),
1129
+ total: data.total,
1130
+ take: data.take,
1131
+ skip: data.skip
1132
+ };
1133
+ }
1134
+ /** Report the transaction that paid the deposit address. */
1135
+ async reportDeposit(id, txHash) {
1136
+ const data = await this.rest.post(
1137
+ `${this.route}/${id}/deposit`,
1138
+ { body: { txHash } }
1139
+ );
1140
+ return this._add(new CrossChainSwap(this.client, data));
1141
+ }
1142
+ };
1143
+
1144
+ // src/managers/DefindexManager.ts
1145
+ var DefindexManager = class {
1146
+ constructor(client) {
1147
+ this.route = "/defindex";
1148
+ this.client = client;
1149
+ }
1150
+ get rest() {
1151
+ return this.client.rest;
1152
+ }
1153
+ vaults() {
1154
+ return this.rest.get(`${this.route}/vaults`);
1155
+ }
1156
+ vault(vault) {
1157
+ return this.rest.get(`${this.route}/vaults/${encodeURIComponent(vault)}`);
908
1158
  }
909
- /** Enable the application's configured assets on a wallet. */
910
- addDefaultTrustlines(address) {
1159
+ /** An account's position in a vault. */
1160
+ balance(vault, account) {
1161
+ return this.rest.get(
1162
+ `${this.route}/vaults/${encodeURIComponent(vault)}/balance`,
1163
+ { query: { account } }
1164
+ );
1165
+ }
1166
+ deposit(vault, options) {
911
1167
  return this.rest.post(
912
- `${this.route}/wallets/${address}/trustlines/default`
1168
+ `${this.route}/vaults/${encodeURIComponent(vault)}/deposit`,
1169
+ { body: options }
913
1170
  );
914
1171
  }
915
- /** Enable specific assets on a wallet. */
916
- addTrustlines(address, options) {
917
- return this.rest.post(`${this.route}/wallets/${address}/trustlines`, {
918
- body: options
919
- });
1172
+ withdraw(vault, options) {
1173
+ return this.rest.post(
1174
+ `${this.route}/vaults/${encodeURIComponent(vault)}/withdraw`,
1175
+ { body: options }
1176
+ );
920
1177
  }
921
- /**
922
- * Remove a trustline. An asset is `(code, issuer)`, and both are in the path for
923
- * that reason: a bare code names no asset.
924
- */
925
- removeTrustline(address, code, issuer) {
1178
+ /** Submit a signed DeFindex transaction (base64 XDR). */
1179
+ submit(xdr) {
1180
+ return this.rest.post(`${this.route}/submit`, { body: { xdr } });
1181
+ }
1182
+ };
1183
+
1184
+ // src/managers/PluginManager.ts
1185
+ var PluginManager = class {
1186
+ constructor(client) {
1187
+ this.route = "/plugins";
1188
+ this.client = client;
1189
+ }
1190
+ get rest() {
1191
+ return this.client.rest;
1192
+ }
1193
+ async list() {
1194
+ const { data } = await this.rest.get(this.route);
1195
+ return data;
1196
+ }
1197
+ fetch(slug) {
1198
+ return this.rest.get(`${this.route}/${encodeURIComponent(slug)}`);
1199
+ }
1200
+ /** Install (or re-consent to) a plugin. */
1201
+ install(slug, options) {
1202
+ return this.rest.put(
1203
+ `${this.route}/${encodeURIComponent(slug)}/installation`,
1204
+ { body: options }
1205
+ );
1206
+ }
1207
+ uninstall(slug) {
926
1208
  return this.rest.delete(
927
- `${this.route}/wallets/${address}/trustlines/${code}/${issuer}`
1209
+ `${this.route}/${encodeURIComponent(slug)}/installation`
928
1210
  );
929
1211
  }
930
- /* -------------------------------- users -------------------------------- */
931
- /**
932
- * Register a user with Pollar ahead of their first login. Needs an elevated
933
- * (admin) key: the Pollar user directory is shared by every tenant, so a tenant
934
- * key gets `403 elevated_key_required`.
935
- */
936
- registerUser(options) {
937
- return this.rest.post(`${this.route}/users`, { body: options });
1212
+ /** Run a read-only action the plugin declares. */
1213
+ query(slug, action, input) {
1214
+ return this.rest.post(
1215
+ `${this.route}/${encodeURIComponent(slug)}/queries/${encodeURIComponent(action)}`,
1216
+ { body: { input } }
1217
+ );
938
1218
  }
939
- /**
940
- * Register a user AND provision their Stellar wallet in one call — the variant
941
- * to use when the user should be able to receive before they ever log in. Needs
942
- * an elevated (admin) key, like {@link registerUser}.
943
- */
944
- registerUserWithWallet(options) {
945
- return this.rest.post(`${this.route}/users/with-wallet`, { body: options });
1219
+ /** Run an action that may change the plugin's state. */
1220
+ command(slug, action, input) {
1221
+ return this.rest.post(
1222
+ `${this.route}/${encodeURIComponent(slug)}/commands/${encodeURIComponent(action)}`,
1223
+ { body: { input } }
1224
+ );
1225
+ }
1226
+ };
1227
+
1228
+ // src/managers/PublicKeyManager.ts
1229
+ var PublicKeyManager = class {
1230
+ constructor(client) {
1231
+ this.route = "/public-key";
1232
+ this.client = client;
1233
+ }
1234
+ get rest() {
1235
+ return this.client.rest;
1236
+ }
1237
+ /** The public key for an environment (`dev` → testnet, `prod` → mainnet). */
1238
+ fetch(env = "dev") {
1239
+ return this.rest.get(this.route, { query: { env } });
946
1240
  }
947
1241
  };
948
1242
 
@@ -955,6 +1249,7 @@ var PaymentIntent = class extends Base {
955
1249
  super._patch(data);
956
1250
  this.kind = data.kind;
957
1251
  this.status = data.status;
1252
+ this.chain = data.chain ?? "stellar";
958
1253
  this.network = data.network;
959
1254
  this.source = data.source;
960
1255
  this.destination = data.destination;
@@ -989,9 +1284,10 @@ var PaymentIntent = class extends Base {
989
1284
  get isPending() {
990
1285
  return this.status === PaymentIntentStatus.Pending;
991
1286
  }
992
- /** Human-readable asset label (`XLM` for native). */
1287
+ /** Human-readable asset label (the chain's coin for native: `XLM`, `SOL` or `MON`). */
993
1288
  get assetLabel() {
994
- return !this.asset || this.asset === "native" ? "XLM" : this.asset;
1289
+ if (this.asset && this.asset !== "native") return this.asset;
1290
+ return this.chain === "solana" ? "SOL" : this.chain === "monad" ? "MON" : "XLM";
995
1291
  }
996
1292
  /** Re-fetch this intent from the API, returning a fresh instance. */
997
1293
  fetch() {
@@ -1022,6 +1318,7 @@ var PaymentIntent = class extends Base {
1022
1318
  id: this.id,
1023
1319
  kind: this.kind,
1024
1320
  status: this.status,
1321
+ chain: this.chain,
1025
1322
  network: this.network,
1026
1323
  source: this.source,
1027
1324
  destination: this.destination,
@@ -1201,7 +1498,10 @@ var PaymentIntentManager = class extends BaseManager {
1201
1498
  });
1202
1499
  return this._add(new PaymentIntent(this.client, data));
1203
1500
  }
1204
- /** Create a SEP-7 `pay` intent (no source → pay URI + QR, no XDR). */
1501
+ /**
1502
+ * Create a `pay` intent (no source → a payment link + QR, no XDR): SEP-7 on Stellar (the
1503
+ * default), Solana Pay with `chain: 'solana'`, EIP-681 with `chain: 'monad'`.
1504
+ */
1205
1505
  async createPay(options) {
1206
1506
  const data = await this.rest.post(`${this.route}/pay`, {
1207
1507
  body: resolveIntentBody(options)
@@ -1213,11 +1513,20 @@ var PaymentIntentManager = class extends BaseManager {
1213
1513
  const data = await this.rest.get(`${this.route}/${id}`);
1214
1514
  return this._add(new PaymentIntent(this.client, data));
1215
1515
  }
1516
+ /**
1517
+ * Every status change an intent went through, oldest first — who moved it
1518
+ * (`api`, `validate`, `observer`, `system`), when, and with which transaction.
1519
+ */
1520
+ transitions(id) {
1521
+ return this.rest.get(`${this.route}/${id}/transitions`);
1522
+ }
1216
1523
  /** List the consumer's payment intents (paginated). */
1217
1524
  async list(options = {}) {
1218
1525
  const data = await this.rest.get(this.route, {
1219
1526
  query: {
1220
1527
  status: options.status,
1528
+ chain: options.chain,
1529
+ createdFrom: options.createdFrom instanceof Date ? options.createdFrom.toISOString() : options.createdFrom,
1221
1530
  take: options.take,
1222
1531
  skip: options.skip
1223
1532
  }
@@ -1358,6 +1667,92 @@ var ProductManager = class extends BaseManager {
1358
1667
  }
1359
1668
  };
1360
1669
 
1670
+ // src/structures/ChainSwap.ts
1671
+ var ChainSwap = class extends Base {
1672
+ constructor(client, data) {
1673
+ super(client, data);
1674
+ }
1675
+ _patch(data) {
1676
+ super._patch(data);
1677
+ this.chain = data.chain;
1678
+ this.network = data.network;
1679
+ this.provider = data.provider;
1680
+ this.status = data.status;
1681
+ this.source = data.source;
1682
+ this.sendAsset = data.sendAsset;
1683
+ this.sendAmount = data.sendAmount;
1684
+ this.destAsset = data.destAsset;
1685
+ this.destEstimated = data.destEstimated;
1686
+ this.destMin = data.destMin;
1687
+ this.feeBps = data.feeBps;
1688
+ this.feeAmount = data.feeAmount;
1689
+ this.slippageBps = data.slippageBps;
1690
+ this.path = data.path;
1691
+ this.transaction = data.transaction;
1692
+ this.approval = data.approval;
1693
+ this.txHash = data.txHash;
1694
+ this.idempotencyKey = data.idempotencyKey;
1695
+ this.expiresAt = new Date(data.expiresAt);
1696
+ this.createdAt = new Date(data.createdAt);
1697
+ this.updatedAt = new Date(data.updatedAt);
1698
+ return this;
1699
+ }
1700
+ /** Whether the swap has settled on-chain. */
1701
+ get isSucceeded() {
1702
+ return this.status === SwapStatus.Succeeded;
1703
+ }
1704
+ /** Whether the swap is still awaiting submission. */
1705
+ get isPending() {
1706
+ return this.status === SwapStatus.Pending;
1707
+ }
1708
+ /** Whether the built transaction can no longer be submitted. */
1709
+ get isStale() {
1710
+ return this.isPending && this.expiresAt.getTime() <= Date.now();
1711
+ }
1712
+ /** Re-fetch this swap from the API. */
1713
+ async fetch() {
1714
+ return await this.client.swaps.fetch(this.id);
1715
+ }
1716
+ /**
1717
+ * Relay the signed transaction. Mutates this instance from the refreshed
1718
+ * swap in the outcome and returns the outcome.
1719
+ */
1720
+ async submit(options) {
1721
+ const outcome = await this.client.swaps.submit(
1722
+ this.id,
1723
+ options
1724
+ );
1725
+ this._patch(outcome.swap.toJSON());
1726
+ return outcome;
1727
+ }
1728
+ toJSON() {
1729
+ return {
1730
+ id: this.id,
1731
+ chain: this.chain,
1732
+ network: this.network,
1733
+ provider: this.provider,
1734
+ status: this.status,
1735
+ source: this.source,
1736
+ sendAsset: this.sendAsset,
1737
+ sendAmount: this.sendAmount,
1738
+ destAsset: this.destAsset,
1739
+ destEstimated: this.destEstimated,
1740
+ destMin: this.destMin,
1741
+ feeBps: this.feeBps,
1742
+ feeAmount: this.feeAmount,
1743
+ slippageBps: this.slippageBps,
1744
+ path: this.path,
1745
+ transaction: this.transaction,
1746
+ approval: this.approval,
1747
+ txHash: this.txHash,
1748
+ idempotencyKey: this.idempotencyKey,
1749
+ expiresAt: this.expiresAt.toISOString(),
1750
+ createdAt: this.createdAt.toISOString(),
1751
+ updatedAt: this.updatedAt.toISOString()
1752
+ };
1753
+ }
1754
+ };
1755
+
1361
1756
  // src/structures/Swap.ts
1362
1757
  var Swap = class extends Base {
1363
1758
  constructor(client, data) {
@@ -1407,15 +1802,18 @@ var Swap = class extends Base {
1407
1802
  return !this.destAsset || this.destAsset === "native" ? "XLM" : this.destAsset;
1408
1803
  }
1409
1804
  /** Re-fetch this swap from the API, returning a fresh instance. */
1410
- fetch() {
1411
- return this.client.swaps.fetch(this.id);
1805
+ async fetch() {
1806
+ return await this.client.swaps.fetch(this.id);
1412
1807
  }
1413
1808
  /**
1414
1809
  * Relay the signed transaction for this swap. Mutates this instance from the
1415
1810
  * refreshed swap in the outcome and returns the outcome.
1416
1811
  */
1417
1812
  async submit(options) {
1418
- const outcome = await this.client.swaps.submit(this.id, options);
1813
+ const outcome = await this.client.swaps.submit(
1814
+ this.id,
1815
+ options
1816
+ );
1419
1817
  this._patch(outcome.swap.toJSON());
1420
1818
  return outcome;
1421
1819
  }
@@ -1450,6 +1848,9 @@ var Swap = class extends Base {
1450
1848
  };
1451
1849
 
1452
1850
  // src/managers/SwapManager.ts
1851
+ function isChainSwapData(data) {
1852
+ return "chain" in data && typeof data.chain === "string";
1853
+ }
1453
1854
  var SwapManager = class extends BaseManager {
1454
1855
  constructor() {
1455
1856
  super(...arguments);
@@ -1461,50 +1862,67 @@ var SwapManager = class extends BaseManager {
1461
1862
  body: options
1462
1863
  });
1463
1864
  }
1464
- /** Create a swap (unsigned XDR + SEP-7 URI + QR). */
1465
1865
  async create(options) {
1466
- const data = await this.rest.post(this.route, { body: options });
1467
- return this._add(new Swap(this.client, data));
1866
+ const data = await this.rest.post(this.route, {
1867
+ body: options
1868
+ });
1869
+ return this.materialize(data);
1468
1870
  }
1469
- /** Get a single swap by id. */
1871
+ /** Get a single swap by id, on any chain. */
1470
1872
  async fetch(id) {
1471
- const data = await this.rest.get(`${this.route}/${id}`);
1472
- return this._add(new Swap(this.client, data));
1873
+ const data = await this.rest.get(
1874
+ `${this.route}/${id}`
1875
+ );
1876
+ return this.materialize(data);
1473
1877
  }
1474
- /** List the consumer's swaps (paginated). */
1475
1878
  async list(options = {}) {
1476
- const data = await this.rest.get(this.route, {
1477
- query: {
1478
- status: options.status,
1479
- take: options.take,
1480
- skip: options.skip
1879
+ const data = await this.rest.get(
1880
+ this.route,
1881
+ {
1882
+ query: {
1883
+ chain: options.chain,
1884
+ status: options.status,
1885
+ take: options.take,
1886
+ skip: options.skip
1887
+ }
1481
1888
  }
1482
- });
1889
+ );
1483
1890
  return {
1484
- items: data.data.map((d) => this._add(new Swap(this.client, d))),
1891
+ items: data.data.map((d) => this.materialize(d)),
1485
1892
  total: data.total,
1486
1893
  take: data.take,
1487
1894
  skip: data.skip
1488
1895
  };
1489
1896
  }
1490
1897
  /**
1491
- * Relay a signed swap transaction to the network. Finalizes status
1492
- * server-side and returns the outcome with the refreshed swap materialized.
1898
+ * Relay a signed swap transaction to its network: `{ signedXdr }` for a
1899
+ * Stellar swap, `{ signedTransaction }` for a Solana or Monad one.
1493
1900
  */
1494
1901
  async submit(id, options) {
1495
- const data = await this.rest.post(
1496
- `${this.route}/${id}/submit`,
1497
- { body: options }
1498
- );
1902
+ const data = await this.rest.post(`${this.route}/${id}/submit`, { body: options });
1903
+ if (isChainSwapData(data.swap)) {
1904
+ return {
1905
+ submitted: data.submitted,
1906
+ status: data.status,
1907
+ txHash: data.txHash,
1908
+ swap: this._add(new ChainSwap(this.client, data.swap))
1909
+ };
1910
+ }
1911
+ const stellar = data;
1499
1912
  return {
1500
- submitted: data.submitted,
1501
- status: data.status,
1502
- txHash: data.txHash ?? null,
1503
- reason: data.reason ?? null,
1504
- resultCodes: data.resultCodes ?? null,
1505
- swap: this._add(new Swap(this.client, data.swap))
1913
+ submitted: stellar.submitted,
1914
+ status: stellar.status,
1915
+ txHash: stellar.txHash ?? null,
1916
+ reason: stellar.reason ?? null,
1917
+ resultCodes: stellar.resultCodes ?? null,
1918
+ swap: this._add(new Swap(this.client, stellar.swap))
1506
1919
  };
1507
1920
  }
1921
+ materialize(data) {
1922
+ return this._add(
1923
+ isChainSwapData(data) ? new ChainSwap(this.client, data) : new Swap(this.client, data)
1924
+ );
1925
+ }
1508
1926
  };
1509
1927
 
1510
1928
  // src/structures/WebhookDelivery.ts
@@ -1619,7 +2037,7 @@ var WebhookEndpoint = class extends Base {
1619
2037
  };
1620
2038
 
1621
2039
  // src/util/Constants.ts
1622
- var version = "2.0.0";
2040
+ var version = "2.2.0";
1623
2041
  var DEFAULT_BASE_URL = "https://api.cosmospay.lat/cosmos-api";
1624
2042
  var DEFAULT_VERSION = "v1";
1625
2043
  var DEFAULT_TIMEOUT = 3e4;
@@ -1805,12 +2223,9 @@ var WebhookManager = class extends BaseManager {
1805
2223
  "No webhook secret configured. Pass `{ secret }` or set `webhookSecret` on the client."
1806
2224
  );
1807
2225
  }
1808
- const event = Webhooks.constructEvent(
1809
- rawBody,
1810
- signatureHeader,
1811
- secret,
1812
- { toleranceSeconds: options.toleranceSeconds }
1813
- );
2226
+ const event = Webhooks.constructEvent(rawBody, signatureHeader, secret, {
2227
+ toleranceSeconds: options.toleranceSeconds
2228
+ });
1814
2229
  this.emit(event.type, event);
1815
2230
  this.emit(toCamelEvent(event.type), event);
1816
2231
  this.emit("event", event);
@@ -1979,6 +2394,9 @@ var REST = class extends events.EventEmitter {
1979
2394
  post(path, options = {}) {
1980
2395
  return this.request("POST", path, options);
1981
2396
  }
2397
+ put(path, options = {}) {
2398
+ return this.request("PUT", path, options);
2399
+ }
1982
2400
  patch(path, options = {}) {
1983
2401
  return this.request("PATCH", path, options);
1984
2402
  }
@@ -2170,15 +2588,20 @@ var Client = class extends events.EventEmitter {
2170
2588
  this.webhooks = new WebhookManager(this);
2171
2589
  this.products = new ProductManager(this);
2172
2590
  this.swaps = new SwapManager(this);
2591
+ this.crossChainSwaps = new CrossChainSwapManager(this);
2173
2592
  this.liquidity = new LiquidityManager(this);
2174
2593
  this.onramp = new OnrampManager(this);
2175
2594
  this.offramp = new OfframpManager(this);
2176
2595
  this.activity = new ActivityManager(this);
2177
2596
  this.kyc = new KycManager(this);
2178
- this.pollar = new PollarManager(this);
2179
2597
  this.customers = new CustomerManager(this);
2180
2598
  this.analytics = new AnalyticsManager(this);
2181
2599
  this.health = new HealthManager(this);
2600
+ this.aliases = new AliasManager(this);
2601
+ this.assets = new AssetManager(this);
2602
+ this.plugins = new PluginManager(this);
2603
+ this.defindex = new DefindexManager(this);
2604
+ this.publicKey = new PublicKeyManager(this);
2182
2605
  }
2183
2606
  /** Update the API key used for subsequent requests. */
2184
2607
  setApiKey(apiKey) {
@@ -2210,19 +2633,26 @@ var Wallets = {
2210
2633
 
2211
2634
  exports.ActivityManager = ActivityManager;
2212
2635
  exports.AddressBook = AddressBook;
2636
+ exports.AliasManager = AliasManager;
2213
2637
  exports.AnalyticsManager = AnalyticsManager;
2638
+ exports.AssetManager = AssetManager;
2214
2639
  exports.Assets = Assets;
2215
2640
  exports.Base = Base;
2216
2641
  exports.BaseManager = BaseManager;
2642
+ exports.ChainSwap = ChainSwap;
2217
2643
  exports.Client = Client;
2218
2644
  exports.CosmosPayAPIError = CosmosPayAPIError;
2219
2645
  exports.CosmosPayRequestError = CosmosPayRequestError;
2646
+ exports.CrossChainSwap = CrossChainSwap;
2647
+ exports.CrossChainSwapManager = CrossChainSwapManager;
2648
+ exports.CrossChainSwapStatus = CrossChainSwapStatus;
2220
2649
  exports.Customer = Customer;
2221
2650
  exports.CustomerManager = CustomerManager;
2222
2651
  exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL;
2223
2652
  exports.DEFAULT_RETRIES = DEFAULT_RETRIES;
2224
2653
  exports.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
2225
2654
  exports.DEFAULT_VERSION = DEFAULT_VERSION;
2655
+ exports.DefindexManager = DefindexManager;
2226
2656
  exports.Events = Events;
2227
2657
  exports.HealthManager = HealthManager;
2228
2658
  exports.KycManager = KycManager;
@@ -2234,10 +2664,11 @@ exports.PaymentIntent = PaymentIntent;
2234
2664
  exports.PaymentIntentKind = PaymentIntentKind;
2235
2665
  exports.PaymentIntentManager = PaymentIntentManager;
2236
2666
  exports.PaymentIntentStatus = PaymentIntentStatus;
2237
- exports.PollarManager = PollarManager;
2667
+ exports.PluginManager = PluginManager;
2238
2668
  exports.Product = Product;
2239
2669
  exports.ProductKind = ProductKind;
2240
2670
  exports.ProductManager = ProductManager;
2671
+ exports.PublicKeyManager = PublicKeyManager;
2241
2672
  exports.REST = REST;
2242
2673
  exports.Receiver = Receiver;
2243
2674
  exports.SIGNATURE_HEADER = SIGNATURE_HEADER;