@stellar/typescript-wallet-sdk 4.0.1 → 5.0.0-beta.1788566740000

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 (38) hide show
  1. package/CHANGELOG.MD +26 -0
  2. package/examples/sep10/sep10Server.ts +1 -1
  3. package/examples/sep24/sep24.ts +1 -1
  4. package/examples/tsconfig.json +1 -0
  5. package/jest.e2e.config.js +2 -1
  6. package/jest.integration.config.js +2 -1
  7. package/lib/bundle.js +58575 -22165
  8. package/lib/bundle.js.map +1 -1
  9. package/lib/bundle_browser.js +49263 -12814
  10. package/lib/bundle_browser.js.map +1 -1
  11. package/lib/walletSdk/Customer/index.d.ts +4 -4
  12. package/lib/walletSdk/Exceptions/index.d.ts +3 -0
  13. package/lib/walletSdk/Horizon/AccountService.d.ts +2 -3
  14. package/lib/walletSdk/Horizon/Transaction/TransactionBuilder.d.ts +17 -14
  15. package/lib/walletSdk/Types/horizon.d.ts +11 -5
  16. package/lib/walletSdk/Types/sep12.d.ts +1 -2
  17. package/lib/walletSdk/Uri/Sep7Base.d.ts +1 -1
  18. package/package.json +7 -6
  19. package/src/walletSdk/Auth/AuthHeaderSigner.ts +11 -5
  20. package/src/walletSdk/Auth/WalletSigner.ts +1 -1
  21. package/src/walletSdk/Auth/index.ts +4 -3
  22. package/src/walletSdk/Customer/index.ts +6 -6
  23. package/src/walletSdk/Exceptions/index.ts +8 -0
  24. package/src/walletSdk/Horizon/AccountService.ts +2 -2
  25. package/src/walletSdk/Horizon/Stellar.ts +1 -1
  26. package/src/walletSdk/Horizon/Transaction/TransactionBuilder.ts +31 -19
  27. package/src/walletSdk/Recovery/AccountRecover.ts +1 -1
  28. package/src/walletSdk/Server/index.ts +2 -2
  29. package/src/walletSdk/Types/horizon.ts +16 -5
  30. package/src/walletSdk/Types/sep12.ts +1 -1
  31. package/src/walletSdk/Uri/Sep7Base.ts +10 -9
  32. package/src/walletSdk/Uri/Sep7Tx.ts +1 -1
  33. package/test/auth.test.ts +42 -0
  34. package/test/e2e/reactNative.test.ts +190 -0
  35. package/test/sep7.test.ts +72 -7
  36. package/test/transaction.test.ts +107 -4
  37. package/test/tsconfig.json +1 -0
  38. package/webpack.config.js +0 -4
@@ -41,12 +41,12 @@ export declare class Sep12 {
41
41
  getCustomer(params: GetCustomerParams): Promise<GetCustomerResponse>;
42
42
  /**
43
43
  * Add a new customer. Customer info is given in sep9Info param. If it
44
- * is binary type (eg. Buffer of an image) include it in sep9BinaryInfo.
44
+ * is binary type (eg. Uint8Array of an image) include it in sep9BinaryInfo.
45
45
  * @param {AddCustomerParams} params - The parameters for adding a customer.
46
46
  * @param {CustomerInfoMap} [params.sep9Info] - Customer information. What fields you should
47
47
  * give is indicated by the anchor.
48
48
  * @param {CustomerBinaryInfoMap} [params.sep9BinaryInfo] - Customer information that is in binary
49
- * format (eg. Buffer of an image).
49
+ * format (eg. Uint8Array of an image).
50
50
  * @param {string} [params.type] - The type of the customer.
51
51
  * @param {string} [params.memo] - A memo associated with the customer.
52
52
  * @param {string} [params.transactionId] - The id of the transaction that the customer is
@@ -56,12 +56,12 @@ export declare class Sep12 {
56
56
  add({ sep9Info, sep9BinaryInfo, type, memo, transactionId, }: AddCustomerParams): Promise<AddCustomerResponse>;
57
57
  /**
58
58
  * Updates an existing customer. Customer info is given in sep9Info param. If it
59
- * is binary type (eg. Buffer of an image) include it in sep9BinaryInfo.
59
+ * is binary type (eg. Uint8Array of an image) include it in sep9BinaryInfo.
60
60
  * @param {AddCustomerParams} params - The parameters for adding a customer.
61
61
  * @param {CustomerInfoMap} [params.sep9Info] - Customer information. What fields you should
62
62
  * give is indicated by the anchor.
63
63
  * @param {CustomerBinaryInfoMap} [params.sep9BinaryInfo] - Customer information that is in binary
64
- * format (eg. Buffer of an image).
64
+ * format (eg. Uint8Array of an image).
65
65
  * @param {string} [params.id] - The id of the customer.
66
66
  * @param {string} [params.type] - The type of the customer.
67
67
  * @param {string} [params.memo] - A memo associated with the customer.
@@ -61,6 +61,9 @@ export declare class WithdrawalTxMissingMemoError extends Error {
61
61
  export declare class PathPayOnlyOneAmountError extends Error {
62
62
  constructor();
63
63
  }
64
+ export declare class PathPayBoundRequiredError extends Error {
65
+ constructor(bound: "destMin" | "sendMax");
66
+ }
64
67
  export declare class WithdrawalTxMemoError extends Error {
65
68
  constructor();
66
69
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Horizon } from "@stellar/stellar-sdk";
3
2
  import { Config } from "../";
4
3
  import { SigningKeypair } from "./Account";
@@ -27,10 +26,10 @@ export declare class AccountService {
27
26
  /**
28
27
  * Generate new account keypair (public and secret key) from random bytes. This key pair can be
29
28
  * used to create a Stellar account.
30
- * @param {Buffer} randomBytes - Random bytes to create keypair from.
29
+ * @param {Uint8Array} randomBytes - Random bytes to create keypair from.
31
30
  * @returns {SigningKeypair} Keypair capable of signing.
32
31
  */
33
- createKeypairFromRandom(randomBytes: Buffer): SigningKeypair;
32
+ createKeypairFromRandom(randomBytes: Uint8Array): SigningKeypair;
34
33
  /**
35
34
  * Get account information from the Stellar network.
36
35
  * @param {object} params - The parameters for retrieving account information.
@@ -55,19 +55,19 @@ export declare class TransactionBuilder extends CommonTransactionBuilder<Transac
55
55
  * @param {string} params.destinationAddress - The destination Stellar address to which the payment is sent.
56
56
  * @param {StellarAssetId} params.sendAsset - The asset to be sent.
57
57
  * @param {StellarAssetId} params.destAsset - The asset the destination will receive.
58
- * @param {string} [params.sendAmount] - The amount to be sent. Must specify either sendAmount or destAmount,
59
- * but not both.
60
- * @param {string} [params.destAmount] - The amount to be received by the destination. Must specify either sendAmount or destAmount,
61
- * but not both.
62
- * @param {string} [params.destMin] - The minimum amount of the destination asset to be receive. This is a
63
- * protective measure, it allows you to specify a lower bound for an acceptable conversion. Only used
64
- * if using sendAmount.
65
- * (optional, default is ".0000001").
66
- * @param {string} [params.sendMax] - The maximum amount of the destination asset to be sent. This is a
67
- * protective measure, it allows you to specify an upper bound for an acceptable conversion. Only used
68
- * if using destAmount.
69
- * (optional, default is int64 max).
58
+ * @param {string} [params.sendAmount] - The amount of the send asset to be sent. Must specify either
59
+ * sendAmount or destAmount, but not both. Requires destMin.
60
+ * @param {string} [params.destAmount] - The amount of the destination asset to be received by the
61
+ * destination. Must specify either sendAmount or destAmount, but not both. Requires sendMax.
62
+ * @param {string} [params.destMin] - The minimum amount of the destination asset to receive. Required
63
+ * when using sendAmount. This is the slippage limit for the conversion: the payment fails if it would
64
+ * deliver less than this amount, instead of executing at a worse rate.
65
+ * @param {string} [params.sendMax] - The maximum amount of the send asset to spend. Required when using
66
+ * destAmount. This is the slippage limit for the conversion: the payment fails if it would cost more
67
+ * than this amount, instead of executing at a worse rate.
70
68
  *
69
+ * @throws {PathPayOnlyOneAmountError} If both or neither of sendAmount and destAmount are given.
70
+ * @throws {PathPayBoundRequiredError} If destMin is missing for sendAmount, or sendMax for destAmount.
71
71
  * @returns {TransactionBuilder} - Returns the current TransactionBuilder instance for method chaining.
72
72
  */
73
73
  pathPay({ destinationAddress, sendAsset, destAsset, sendAmount, destAmount, destMin, sendMax, }: PathPayParams): TransactionBuilder;
@@ -77,10 +77,13 @@ export declare class TransactionBuilder extends CommonTransactionBuilder<Transac
77
77
  * @param {StellarAssetId} fromAsset - The source asset to be sent.
78
78
  * @param {StellarAssetId} toAsset - The destination asset to receive.
79
79
  * @param {string} amount - The amount of the source asset to be sent.
80
- * @param {string} [destMin] - (Optional) The minimum amount of the destination asset to be received.
80
+ * @param {string} destMin - The minimum amount of the destination asset to receive. This is the
81
+ * slippage limit for the swap: it fails if the conversion would deliver less than this amount,
82
+ * instead of executing at a worse rate.
83
+ * @throws {PathPayBoundRequiredError} If destMin is missing.
81
84
  * @returns {TransactionBuilder} Returns the current instance of the TransactionBuilder for method chaining.
82
85
  */
83
- swap(fromAsset: StellarAssetId, toAsset: StellarAssetId, amount: string, destMin?: string): TransactionBuilder;
86
+ swap(fromAsset: StellarAssetId, toAsset: StellarAssetId, amount: string, destMin: string): TransactionBuilder;
84
87
  /**
85
88
  * Adds an operation to the transaction.
86
89
  * @param {xdr.Operation} op - The operation to add.
@@ -37,9 +37,15 @@ export type PathPayParams = {
37
37
  destinationAddress: string;
38
38
  sendAsset: StellarAssetId;
39
39
  destAsset: StellarAssetId;
40
- sendAmount?: string;
41
- destAmount?: string;
42
- destMin?: string;
43
- sendMax?: string;
44
- };
40
+ } & ({
41
+ sendAmount: string;
42
+ destMin: string;
43
+ destAmount?: never;
44
+ sendMax?: never;
45
+ } | {
46
+ destAmount: string;
47
+ sendMax: string;
48
+ sendAmount?: never;
49
+ destMin?: never;
50
+ });
45
51
  export type CommonBuilder = TransactionBuilder | SponsoringBuilder;
@@ -1,9 +1,8 @@
1
- /// <reference types="node" />
2
1
  export type CustomerInfoMap = {
3
2
  [key: string]: string;
4
3
  };
5
4
  export type CustomerBinaryInfoMap = {
6
- [key: string]: Buffer;
5
+ [key: string]: Uint8Array;
7
6
  };
8
7
  export declare enum Sep12Status {
9
8
  ACCEPTED = "ACCEPTED",
@@ -180,7 +180,7 @@ export declare abstract class Sep7Base {
180
180
  *
181
181
  * @see https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0007.md#request-signing
182
182
  *
183
- * @returns {Buffer} array of bytes to be signed with given keypair on
183
+ * @returns {Uint8Array} array of bytes to be signed with given keypair on
184
184
  * the 'addSignature' method.
185
185
  */
186
186
  private createSignaturePayload;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@stellar/typescript-wallet-sdk",
3
- "version": "4.0.1",
3
+ "version": "5.0.0-beta.1788566740000",
4
4
  "engines": {
5
- "node": ">=22"
5
+ "node": ">=22.12.0"
6
6
  },
7
7
  "browser": "./lib/bundle_browser.js",
8
8
  "main": "./lib/bundle.js",
@@ -16,6 +16,7 @@
16
16
  "@stellar/tsconfig": "^1.0.2",
17
17
  "@types/jest": "^29.4.0",
18
18
  "@types/lodash": "^4.14.194",
19
+ "@types/node": "^22.10.2",
19
20
  "@types/sinon": "^10.0.15",
20
21
  "@typescript-eslint/eslint-plugin": "^6.7.5",
21
22
  "@typescript-eslint/parser": "^6.7.5",
@@ -41,22 +42,22 @@
41
42
  "ts-loader": "^9.4.2",
42
43
  "ts-node": "^10.9.1",
43
44
  "tslib": "^2.5.0",
44
- "typescript": "^5.0.4",
45
+ "typescript": "^5.7.3",
45
46
  "webpack": "^5.83.1",
46
47
  "webpack-cli": "^5.1.1"
47
48
  },
48
49
  "dependencies": {
49
50
  "@stablelib/base64": "^2.0.0",
50
51
  "@stablelib/utf8": "^2.0.0",
51
- "@stellar/stellar-sdk": "16.2.0",
52
+ "@stellar/stellar-sdk": "17.0.1",
52
53
  "axios": "^1.4.0",
53
- "base64url": "^3.0.1",
54
54
  "https-browserify": "^1.0.0",
55
55
  "jws": "^4.0.0",
56
56
  "lodash": "^4.17.21",
57
57
  "query-string": "^7.1.3",
58
58
  "stream-http": "^3.2.0",
59
59
  "tweetnacl": "^1.0.3",
60
+ "uint8array-extras": "^1.5.0",
60
61
  "url": "^0.11.0",
61
62
  "util": "^0.12.5",
62
63
  "utility-types": "^3.10.0",
@@ -76,4 +77,4 @@
76
77
  "example:sep24": "ts-node examples/sep24/sep24.ts",
77
78
  "example:sep12": "ts-node examples/sep12/sep12.ts"
78
79
  }
79
- }
80
+ }
@@ -2,7 +2,7 @@ import { AxiosInstance } from "axios";
2
2
  import { encode as utf8Encode } from "@stablelib/utf8";
3
3
  import { StrKey } from "@stellar/stellar-sdk";
4
4
  import nacl from "tweetnacl";
5
- import base64url from "base64url";
5
+ import { stringToUint8Array, uint8ArrayToBase64 } from "uint8array-extras";
6
6
 
7
7
  import { SigningKeypair } from "../Horizon/Account";
8
8
  import { DefaultClient } from "../";
@@ -62,15 +62,21 @@ export class DefaultAuthHeaderSigner implements AuthHeaderSigner {
62
62
 
63
63
  // encode JWT message
64
64
  const header = { alg: "EdDSA" };
65
- const encodedHeader = base64url(JSON.stringify(header));
66
- const encodedPayload = base64url(
67
- JSON.stringify({ ...claims, exp: timeExp, iat: issuedAt }),
65
+ const encodedHeader = uint8ArrayToBase64(
66
+ stringToUint8Array(JSON.stringify(header)),
67
+ { urlSafe: true },
68
+ );
69
+ const encodedPayload = uint8ArrayToBase64(
70
+ stringToUint8Array(
71
+ JSON.stringify({ ...claims, exp: timeExp, iat: issuedAt }),
72
+ ),
73
+ { urlSafe: true },
68
74
  );
69
75
  const utf8Jwt = utf8Encode(`${encodedHeader}.${encodedPayload}`);
70
76
 
71
77
  // sign JWT and create signature
72
78
  const signature = nacl.sign.detached(utf8Jwt, naclKP.secretKey);
73
- const encodedSignature = base64url(Buffer.from(signature));
79
+ const encodedSignature = uint8ArrayToBase64(signature, { urlSafe: true });
74
80
 
75
81
  const jwt = `${encodedHeader}.${encodedPayload}.${encodedSignature}`;
76
82
  return jwt;
@@ -103,7 +103,7 @@ export class DomainSigner implements WalletSigner {
103
103
  { headers: this.headers },
104
104
  );
105
105
 
106
- return StellarTransactionBuilder.fromXDR(
106
+ return StellarTransactionBuilder.fromXdr(
107
107
  response.data.transaction,
108
108
  networkPassphrase,
109
109
  ) as Transaction;
@@ -1,6 +1,7 @@
1
1
  import { AxiosInstance } from "axios";
2
2
  import { TransactionBuilder, Transaction, WebAuth } from "@stellar/stellar-sdk";
3
3
  import { decode } from "jws";
4
+ import { areUint8ArraysEqual } from "uint8array-extras";
4
5
 
5
6
  import { Config } from "../";
6
7
  import {
@@ -185,7 +186,7 @@ export class Sep10 {
185
186
  );
186
187
  }
187
188
 
188
- let transaction: Transaction = TransactionBuilder.fromXDR(
189
+ let transaction: Transaction = TransactionBuilder.fromXdr(
189
190
  challengeResponse.transaction,
190
191
  networkPassphrase,
191
192
  ) as Transaction;
@@ -206,7 +207,7 @@ export class Sep10 {
206
207
  // a domain signer that only appends its signature preserves the hash. Any
207
208
  // change to the operations, source account, memo, or other body fields
208
209
  // changes the hash and is rejected here.
209
- if (!returned.hash().equals(originalHash)) {
210
+ if (!areUint8ArraysEqual(returned.hash(), originalHash)) {
210
211
  throw new DomainSigningModifiedError();
211
212
  }
212
213
 
@@ -220,7 +221,7 @@ export class Sep10 {
220
221
  private async getToken(signedTransaction: Transaction): Promise<AuthToken> {
221
222
  try {
222
223
  const resp = await this.httpClient.post(this.webAuthEndpoint, {
223
- transaction: signedTransaction.toXDR(),
224
+ transaction: signedTransaction.toXdr(),
224
225
  });
225
226
  if (!resp.data.token) {
226
227
  throw new MissingTokenError();
@@ -77,12 +77,12 @@ export class Sep12 {
77
77
 
78
78
  /**
79
79
  * Add a new customer. Customer info is given in sep9Info param. If it
80
- * is binary type (eg. Buffer of an image) include it in sep9BinaryInfo.
80
+ * is binary type (eg. Uint8Array of an image) include it in sep9BinaryInfo.
81
81
  * @param {AddCustomerParams} params - The parameters for adding a customer.
82
82
  * @param {CustomerInfoMap} [params.sep9Info] - Customer information. What fields you should
83
83
  * give is indicated by the anchor.
84
84
  * @param {CustomerBinaryInfoMap} [params.sep9BinaryInfo] - Customer information that is in binary
85
- * format (eg. Buffer of an image).
85
+ * format (eg. Uint8Array of an image).
86
86
  * @param {string} [params.type] - The type of the customer.
87
87
  * @param {string} [params.memo] - A memo associated with the customer.
88
88
  * @param {string} [params.transactionId] - The id of the transaction that the customer is
@@ -96,7 +96,7 @@ export class Sep12 {
96
96
  memo,
97
97
  transactionId,
98
98
  }: AddCustomerParams): Promise<AddCustomerResponse> {
99
- let customerMap: { [key: string]: string | Buffer } = {
99
+ let customerMap: { [key: string]: string | Uint8Array } = {
100
100
  ...sep9Info,
101
101
  ...sep9BinaryInfo,
102
102
  };
@@ -127,12 +127,12 @@ export class Sep12 {
127
127
 
128
128
  /**
129
129
  * Updates an existing customer. Customer info is given in sep9Info param. If it
130
- * is binary type (eg. Buffer of an image) include it in sep9BinaryInfo.
130
+ * is binary type (eg. Uint8Array of an image) include it in sep9BinaryInfo.
131
131
  * @param {AddCustomerParams} params - The parameters for adding a customer.
132
132
  * @param {CustomerInfoMap} [params.sep9Info] - Customer information. What fields you should
133
133
  * give is indicated by the anchor.
134
134
  * @param {CustomerBinaryInfoMap} [params.sep9BinaryInfo] - Customer information that is in binary
135
- * format (eg. Buffer of an image).
135
+ * format (eg. Uint8Array of an image).
136
136
  * @param {string} [params.id] - The id of the customer.
137
137
  * @param {string} [params.type] - The type of the customer.
138
138
  * @param {string} [params.memo] - A memo associated with the customer.
@@ -149,7 +149,7 @@ export class Sep12 {
149
149
  memo,
150
150
  transactionId,
151
151
  }: AddCustomerParams): Promise<AddCustomerResponse> {
152
- let customerMap: { [key: string]: string | Buffer } = {};
152
+ let customerMap: { [key: string]: string | Uint8Array } = {};
153
153
  if (id) {
154
154
  customerMap["id"] = id;
155
155
  }
@@ -182,6 +182,14 @@ export class PathPayOnlyOneAmountError extends Error {
182
182
  }
183
183
  }
184
184
 
185
+ export class PathPayBoundRequiredError extends Error {
186
+ constructor(bound: "destMin" | "sendMax") {
187
+ const amount = bound === "destMin" ? "sendAmount" : "destAmount";
188
+ super(`${bound} is required when using ${amount}`);
189
+ Object.setPrototypeOf(this, PathPayBoundRequiredError.prototype);
190
+ }
191
+ }
192
+
185
193
  export class WithdrawalTxMemoError extends Error {
186
194
  constructor() {
187
195
  super(`Error parsing withdrawal transaction memo`);
@@ -42,10 +42,10 @@ export class AccountService {
42
42
  /**
43
43
  * Generate new account keypair (public and secret key) from random bytes. This key pair can be
44
44
  * used to create a Stellar account.
45
- * @param {Buffer} randomBytes - Random bytes to create keypair from.
45
+ * @param {Uint8Array} randomBytes - Random bytes to create keypair from.
46
46
  * @returns {SigningKeypair} Keypair capable of signing.
47
47
  */
48
- createKeypairFromRandom(randomBytes: Buffer): SigningKeypair {
48
+ createKeypairFromRandom(randomBytes: Uint8Array): SigningKeypair {
49
49
  return new SigningKeypair(Keypair.fromRawEd25519Seed(randomBytes));
50
50
  }
51
51
 
@@ -259,7 +259,7 @@ export class Stellar {
259
259
  * @returns {Transaction|FeeBumpTransaction} The decoded transaction.
260
260
  */
261
261
  decodeTransaction(xdr: string): Transaction | FeeBumpTransaction {
262
- return StellarTransactionBuilder.fromXDR(xdr, this.cfg.stellar.network);
262
+ return StellarTransactionBuilder.fromXdr(xdr, this.cfg.stellar.network);
263
263
  }
264
264
 
265
265
  /**
@@ -23,7 +23,10 @@ import {
23
23
  TransactionStatus,
24
24
  PathPayParams,
25
25
  } from "../../Types";
26
- import { PathPayOnlyOneAmountError } from "../../Exceptions";
26
+ import {
27
+ PathPayBoundRequiredError,
28
+ PathPayOnlyOneAmountError,
29
+ } from "../../Exceptions";
27
30
  import { CommonTransactionBuilder } from "./CommonTransactionBuilder";
28
31
  import { SponsoringBuilder } from "./SponsoringBuilder";
29
32
 
@@ -140,19 +143,19 @@ export class TransactionBuilder extends CommonTransactionBuilder<TransactionBuil
140
143
  * @param {string} params.destinationAddress - The destination Stellar address to which the payment is sent.
141
144
  * @param {StellarAssetId} params.sendAsset - The asset to be sent.
142
145
  * @param {StellarAssetId} params.destAsset - The asset the destination will receive.
143
- * @param {string} [params.sendAmount] - The amount to be sent. Must specify either sendAmount or destAmount,
144
- * but not both.
145
- * @param {string} [params.destAmount] - The amount to be received by the destination. Must specify either sendAmount or destAmount,
146
- * but not both.
147
- * @param {string} [params.destMin] - The minimum amount of the destination asset to be receive. This is a
148
- * protective measure, it allows you to specify a lower bound for an acceptable conversion. Only used
149
- * if using sendAmount.
150
- * (optional, default is ".0000001").
151
- * @param {string} [params.sendMax] - The maximum amount of the destination asset to be sent. This is a
152
- * protective measure, it allows you to specify an upper bound for an acceptable conversion. Only used
153
- * if using destAmount.
154
- * (optional, default is int64 max).
146
+ * @param {string} [params.sendAmount] - The amount of the send asset to be sent. Must specify either
147
+ * sendAmount or destAmount, but not both. Requires destMin.
148
+ * @param {string} [params.destAmount] - The amount of the destination asset to be received by the
149
+ * destination. Must specify either sendAmount or destAmount, but not both. Requires sendMax.
150
+ * @param {string} [params.destMin] - The minimum amount of the destination asset to receive. Required
151
+ * when using sendAmount. This is the slippage limit for the conversion: the payment fails if it would
152
+ * deliver less than this amount, instead of executing at a worse rate.
153
+ * @param {string} [params.sendMax] - The maximum amount of the send asset to spend. Required when using
154
+ * destAmount. This is the slippage limit for the conversion: the payment fails if it would cost more
155
+ * than this amount, instead of executing at a worse rate.
155
156
  *
157
+ * @throws {PathPayOnlyOneAmountError} If both or neither of sendAmount and destAmount are given.
158
+ * @throws {PathPayBoundRequiredError} If destMin is missing for sendAmount, or sendMax for destAmount.
156
159
  * @returns {TransactionBuilder} - Returns the current TransactionBuilder instance for method chaining.
157
160
  */
158
161
  pathPay({
@@ -168,23 +171,29 @@ export class TransactionBuilder extends CommonTransactionBuilder<TransactionBuil
168
171
  throw new PathPayOnlyOneAmountError();
169
172
  }
170
173
  if (sendAmount) {
174
+ if (destMin === undefined) {
175
+ throw new PathPayBoundRequiredError("destMin");
176
+ }
171
177
  this.operations.push(
172
178
  Operation.pathPaymentStrictSend({
173
179
  destination: destinationAddress,
174
180
  sendAsset: sendAsset.toAsset(),
175
181
  sendAmount,
176
182
  destAsset: destAsset.toAsset(),
177
- destMin: destMin || ".0000001",
183
+ destMin,
178
184
  }),
179
185
  );
180
186
  } else {
187
+ if (sendMax === undefined) {
188
+ throw new PathPayBoundRequiredError("sendMax");
189
+ }
181
190
  this.operations.push(
182
191
  Operation.pathPaymentStrictReceive({
183
192
  destination: destinationAddress,
184
193
  sendAsset: sendAsset.toAsset(),
185
194
  destAmount,
186
195
  destAsset: destAsset.toAsset(),
187
- sendMax: sendMax || "922337203685.4775807",
196
+ sendMax,
188
197
  }),
189
198
  );
190
199
  }
@@ -198,14 +207,17 @@ export class TransactionBuilder extends CommonTransactionBuilder<TransactionBuil
198
207
  * @param {StellarAssetId} fromAsset - The source asset to be sent.
199
208
  * @param {StellarAssetId} toAsset - The destination asset to receive.
200
209
  * @param {string} amount - The amount of the source asset to be sent.
201
- * @param {string} [destMin] - (Optional) The minimum amount of the destination asset to be received.
210
+ * @param {string} destMin - The minimum amount of the destination asset to receive. This is the
211
+ * slippage limit for the swap: it fails if the conversion would deliver less than this amount,
212
+ * instead of executing at a worse rate.
213
+ * @throws {PathPayBoundRequiredError} If destMin is missing.
202
214
  * @returns {TransactionBuilder} Returns the current instance of the TransactionBuilder for method chaining.
203
215
  */
204
216
  swap(
205
217
  fromAsset: StellarAssetId,
206
218
  toAsset: StellarAssetId,
207
219
  amount: string,
208
- destMin?: string,
220
+ destMin: string,
209
221
  ): TransactionBuilder {
210
222
  this.pathPay({
211
223
  destinationAddress: this.sourceAddress,
@@ -272,8 +284,8 @@ export class TransactionBuilder extends CommonTransactionBuilder<TransactionBuil
272
284
  // the hash and non-hash paths rather than leaking the raw SDK error.
273
285
  try {
274
286
  if (transaction.withdraw_memo_type === "hash") {
275
- const buffer = Buffer.from(transaction.withdraw_memo, "base64");
276
- this.setMemo(Memo.hash(buffer.toString("hex")));
287
+ const memoBytes = xdr.decodeBytes(transaction.withdraw_memo, "base64");
288
+ this.setMemo(Memo.hash(xdr.encodeBytes(memoBytes, "hex")));
277
289
  } else {
278
290
  this.setMemo(
279
291
  new Memo(transaction.withdraw_memo_type, transaction.withdraw_memo),
@@ -231,7 +231,7 @@ export abstract class AccountRecover {
231
231
  const resp = await this.httpClient.post(
232
232
  requestUrl,
233
233
  {
234
- transaction: transaction.toXDR(),
234
+ transaction: transaction.toXdr(),
235
235
  },
236
236
  {
237
237
  headers: {
@@ -60,7 +60,7 @@ export const signChallengeTransaction = async ({
60
60
  anchorDomain,
61
61
  homeDomain,
62
62
  }: SignChallengeTxnParams): Promise<SignChallengeTxnResponse> => {
63
- const parsedTx = TransactionBuilder.fromXDR(
63
+ const parsedTx = TransactionBuilder.fromXdr(
64
64
  challengeTx,
65
65
  networkPassphrase,
66
66
  ) as Transaction;
@@ -106,7 +106,7 @@ export const signChallengeTransaction = async ({
106
106
 
107
107
  accountKp.sign(tx);
108
108
  return {
109
- transaction: tx.toXDR(),
109
+ transaction: tx.toXdr(),
110
110
  networkPassphrase,
111
111
  };
112
112
  };
@@ -44,10 +44,21 @@ export type PathPayParams = {
44
44
  destinationAddress: string;
45
45
  sendAsset: StellarAssetId;
46
46
  destAsset: StellarAssetId;
47
- sendAmount?: string;
48
- destAmount?: string;
49
- destMin?: string;
50
- sendMax?: string;
51
- };
47
+ } & (
48
+ | {
49
+ // Strict send: spend exactly sendAmount, receive at least destMin
50
+ sendAmount: string;
51
+ destMin: string;
52
+ destAmount?: never;
53
+ sendMax?: never;
54
+ }
55
+ | {
56
+ // Strict receive: deliver exactly destAmount, spend at most sendMax
57
+ destAmount: string;
58
+ sendMax: string;
59
+ sendAmount?: never;
60
+ destMin?: never;
61
+ }
62
+ );
52
63
 
53
64
  export type CommonBuilder = TransactionBuilder | SponsoringBuilder;
@@ -3,7 +3,7 @@ export type CustomerInfoMap = {
3
3
  };
4
4
 
5
5
  export type CustomerBinaryInfoMap = {
6
- [key: string]: Buffer;
6
+ [key: string]: Uint8Array;
7
7
  };
8
8
 
9
9
  export enum Sep12Status {
@@ -1,4 +1,5 @@
1
- import { Keypair, Networks, StellarToml } from "@stellar/stellar-sdk";
1
+ import { Keypair, Networks, StellarToml, xdr } from "@stellar/stellar-sdk";
2
+ import { concatUint8Arrays, stringToUint8Array } from "uint8array-extras";
2
3
  import {
3
4
  Sep7OperationType,
4
5
  URI_MSG_MAX_LENGTH,
@@ -214,7 +215,7 @@ export abstract class Sep7Base {
214
215
  */
215
216
  addSignature(keypair: Keypair): string {
216
217
  const payload = this.createSignaturePayload();
217
- const signature = keypair.sign(payload).toString("base64");
218
+ const signature = xdr.encodeBytes(keypair.sign(payload), "base64");
218
219
  this.setParam("signature", signature);
219
220
  return signature;
220
221
  }
@@ -256,7 +257,7 @@ export abstract class Sep7Base {
256
257
  }
257
258
  const keypair = Keypair.fromPublicKey(signingKey);
258
259
  const payload = this.createSignaturePayload();
259
- return keypair.verify(payload, Buffer.from(signature, "base64"));
260
+ return keypair.verify(payload, xdr.decodeBytes(signature, "base64"));
260
261
  } catch (e) {
261
262
  // if something fails we assume signature verification failed
262
263
  return false;
@@ -300,10 +301,10 @@ export abstract class Sep7Base {
300
301
  *
301
302
  * @see https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0007.md#request-signing
302
303
  *
303
- * @returns {Buffer} array of bytes to be signed with given keypair on
304
+ * @returns {Uint8Array} array of bytes to be signed with given keypair on
304
305
  * the 'addSignature' method.
305
306
  */
306
- private createSignaturePayload(): Buffer {
307
+ private createSignaturePayload(): Uint8Array {
307
308
  let data = this.toString();
308
309
 
309
310
  const signature = this.signature;
@@ -315,10 +316,10 @@ export abstract class Sep7Base {
315
316
  // The first 35 bytes of the payload are all 0, the 36th byte is 4.
316
317
  // Then we concatenate the URI request with the prefix 'stellar.sep.7 - URI Scheme'
317
318
  // (no delimiter) and convert that to bytes to give use the final payload to be signed.
318
- return Buffer.concat([
319
- Buffer.alloc(35, 0),
320
- Buffer.alloc(1, 4),
321
- Buffer.from(`stellar.sep.7 - URI Scheme${data}`),
319
+ return concatUint8Arrays([
320
+ new Uint8Array(35),
321
+ Uint8Array.of(4),
322
+ stringToUint8Array(`stellar.sep.7 - URI Scheme${data}`),
322
323
  ]);
323
324
  }
324
325
  }
@@ -30,7 +30,7 @@ export class Sep7Tx extends Sep7Base {
30
30
  */
31
31
  static forTransaction(transaction: Transaction): Sep7Tx {
32
32
  const uri = new Sep7Tx();
33
- uri.xdr = transaction.toEnvelope().toXDR().toString("base64");
33
+ uri.xdr = transaction.toEnvelope().toXdr("base64");
34
34
  uri.networkPassphrase = transaction.networkPassphrase as Networks;
35
35
  return uri;
36
36
  }