@stellar/typescript-wallet-sdk 4.0.0 → 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.
- package/CHANGELOG.MD +39 -0
- package/examples/sep10/sep10Server.ts +1 -1
- package/examples/sep24/sep24.ts +1 -1
- package/examples/tsconfig.json +1 -0
- package/jest.e2e.config.js +2 -1
- package/jest.integration.config.js +2 -1
- package/lib/bundle.js +58608 -22154
- package/lib/bundle.js.map +1 -1
- package/lib/bundle_browser.js +49296 -12803
- package/lib/bundle_browser.js.map +1 -1
- package/lib/walletSdk/Customer/index.d.ts +4 -4
- package/lib/walletSdk/Exceptions/index.d.ts +12 -0
- package/lib/walletSdk/Horizon/AccountService.d.ts +2 -3
- package/lib/walletSdk/Horizon/Transaction/TransactionBuilder.d.ts +17 -14
- package/lib/walletSdk/Server/index.d.ts +17 -1
- package/lib/walletSdk/Types/auth.d.ts +5 -0
- package/lib/walletSdk/Types/horizon.d.ts +11 -5
- package/lib/walletSdk/Types/sep12.d.ts +1 -2
- package/lib/walletSdk/Uri/Sep7Base.d.ts +1 -1
- package/package.json +7 -6
- package/src/walletSdk/Auth/AuthHeaderSigner.ts +11 -5
- package/src/walletSdk/Auth/WalletSigner.ts +1 -1
- package/src/walletSdk/Auth/index.ts +4 -3
- package/src/walletSdk/Customer/index.ts +6 -6
- package/src/walletSdk/Exceptions/index.ts +27 -0
- package/src/walletSdk/Horizon/AccountService.ts +2 -2
- package/src/walletSdk/Horizon/Stellar.ts +1 -1
- package/src/walletSdk/Horizon/Transaction/TransactionBuilder.ts +31 -19
- package/src/walletSdk/Recovery/AccountRecover.ts +1 -1
- package/src/walletSdk/Server/index.ts +55 -12
- package/src/walletSdk/Types/auth.ts +5 -0
- package/src/walletSdk/Types/horizon.ts +16 -5
- package/src/walletSdk/Types/sep12.ts +1 -1
- package/src/walletSdk/Uri/Sep7Base.ts +10 -9
- package/src/walletSdk/Uri/Sep7Tx.ts +1 -1
- package/test/auth.test.ts +42 -0
- package/test/e2e/reactNative.test.ts +190 -0
- package/test/sep7.test.ts +72 -7
- package/test/server.test.ts +219 -1
- package/test/transaction.test.ts +107 -4
- package/test/tsconfig.json +1 -0
- 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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
}
|
|
@@ -115,9 +118,18 @@ export declare class NetworkPassphraseMismatchError extends Error {
|
|
|
115
118
|
export declare class ChallengeTxnIncorrectSequenceError extends Error {
|
|
116
119
|
constructor();
|
|
117
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* @deprecated No longer thrown. `Server.signChallengeTransaction` now validates
|
|
123
|
+
* challenges with `WebAuth.readChallengeTx` and reports every failure, including
|
|
124
|
+
* an invalid server signature, as `ChallengeValidationFailedError`. This class
|
|
125
|
+
* will be removed in the next major release.
|
|
126
|
+
*/
|
|
118
127
|
export declare class ChallengeTxnInvalidSignatureError extends Error {
|
|
119
128
|
constructor();
|
|
120
129
|
}
|
|
130
|
+
export declare class ChallengeTxnClientAccountMismatchError extends Error {
|
|
131
|
+
constructor(expected: string, received: string);
|
|
132
|
+
}
|
|
121
133
|
export declare class AllowHttpOnNonTestnetError extends Error {
|
|
122
134
|
constructor();
|
|
123
135
|
}
|
|
@@ -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 {
|
|
29
|
+
* @param {Uint8Array} randomBytes - Random bytes to create keypair from.
|
|
31
30
|
* @returns {SigningKeypair} Keypair capable of signing.
|
|
32
31
|
*/
|
|
33
|
-
createKeypairFromRandom(randomBytes:
|
|
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
|
|
59
|
-
* but not both.
|
|
60
|
-
* @param {string} [params.destAmount] - The amount
|
|
61
|
-
* but not both.
|
|
62
|
-
* @param {string} [params.destMin] - The minimum amount of the destination asset to
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
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}
|
|
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
|
|
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.
|
|
@@ -5,14 +5,30 @@
|
|
|
5
5
|
import { SignChallengeTxnParams, SignChallengeTxnResponse, AnchorTransaction } from "../Types";
|
|
6
6
|
/**
|
|
7
7
|
* Helper method for signing a SEP-10 challenge transaction if valid.
|
|
8
|
+
*
|
|
9
|
+
* The challenge is validated with `WebAuth.readChallengeTx` from
|
|
10
|
+
* `@stellar/stellar-sdk` — the same validator used by `Sep10.sign()` — which
|
|
11
|
+
* checks the full SEP-10 structure and binds the challenge to the expected
|
|
12
|
+
* anchor: the transaction source must be the anchor's `SIGNING_KEY`, the
|
|
13
|
+
* `<home domain> auth` operation must match the expected home domain, and any
|
|
14
|
+
* `web_auth_domain` operation must match the host of the anchor's
|
|
15
|
+
* `WEB_AUTH_ENDPOINT` (falling back to `anchorDomain` when the TOML omits it).
|
|
16
|
+
* The client account the challenge was issued for is then checked against
|
|
17
|
+
* `accountKp`, so this helper only signs challenges meant for it. Muxed client
|
|
18
|
+
* accounts are supported: the comparison is made on the underlying `G...`
|
|
19
|
+
* address, since that is the key that signs. The muxed id itself is not pinned
|
|
20
|
+
* — a caller that needs to bind a specific subaccount should check the
|
|
21
|
+
* challenge's client account itself.
|
|
22
|
+
*
|
|
8
23
|
* @param {SignChallengeTxnParams} params - The Authentication params.
|
|
9
24
|
* @param {AccountKeypair} params.accountKp - Keypair for the Stellar account signing the transaction.
|
|
10
25
|
* @param {string} [params.challengeTx] - The challenge transaction given by an anchor for authentication.
|
|
11
26
|
* @param {string} [params.networkPassphrase] - The network passphrase for the network authenticating on.
|
|
12
27
|
* @param {string} [params.anchorDomain] - Domain hosting stellar.toml file containing `SIGNING_KEY`.
|
|
28
|
+
* @param {string|string[]} [params.homeDomain] - Expected home domain(s) of the challenge. Defaults to `anchorDomain`.
|
|
13
29
|
* @returns {Promise<SignChallengeTxnResponse>} The signed transaction.
|
|
14
30
|
*/
|
|
15
|
-
export declare const signChallengeTransaction: ({ accountKp, challengeTx, networkPassphrase, anchorDomain, }: SignChallengeTxnParams) => Promise<SignChallengeTxnResponse>;
|
|
31
|
+
export declare const signChallengeTransaction: ({ accountKp, challengeTx, networkPassphrase, anchorDomain, homeDomain, }: SignChallengeTxnParams) => Promise<SignChallengeTxnResponse>;
|
|
16
32
|
/**
|
|
17
33
|
* Helper method for parsing a JSON string into an AnchorTransaction.
|
|
18
34
|
* @param {string} transaction - The json string of an anchor transaction.
|
|
@@ -54,6 +54,11 @@ export type SignChallengeTxnParams = {
|
|
|
54
54
|
challengeTx: string;
|
|
55
55
|
networkPassphrase: string;
|
|
56
56
|
anchorDomain: string;
|
|
57
|
+
/**
|
|
58
|
+
* The home domain(s) the challenge is expected to be scoped to. Defaults to
|
|
59
|
+
* `anchorDomain`. Pass an array for anchors that serve multiple home domains.
|
|
60
|
+
*/
|
|
61
|
+
homeDomain?: string | string[];
|
|
57
62
|
};
|
|
58
63
|
export type SignChallengeTxnResponse = {
|
|
59
64
|
transaction: XdrEncodedTransaction;
|
|
@@ -37,9 +37,15 @@ export type PathPayParams = {
|
|
|
37
37
|
destinationAddress: string;
|
|
38
38
|
sendAsset: StellarAssetId;
|
|
39
39
|
destAsset: StellarAssetId;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
destMin
|
|
43
|
-
|
|
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;
|
|
@@ -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 {
|
|
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": "
|
|
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.
|
|
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": "
|
|
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
|
|
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 =
|
|
66
|
-
|
|
67
|
-
|
|
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 =
|
|
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.
|
|
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.
|
|
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()
|
|
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.
|
|
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.
|
|
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.
|
|
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 |
|
|
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.
|
|
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.
|
|
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 |
|
|
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`);
|
|
@@ -312,6 +320,12 @@ export class ChallengeTxnIncorrectSequenceError extends Error {
|
|
|
312
320
|
}
|
|
313
321
|
}
|
|
314
322
|
|
|
323
|
+
/**
|
|
324
|
+
* @deprecated No longer thrown. `Server.signChallengeTransaction` now validates
|
|
325
|
+
* challenges with `WebAuth.readChallengeTx` and reports every failure, including
|
|
326
|
+
* an invalid server signature, as `ChallengeValidationFailedError`. This class
|
|
327
|
+
* will be removed in the next major release.
|
|
328
|
+
*/
|
|
315
329
|
export class ChallengeTxnInvalidSignatureError extends Error {
|
|
316
330
|
constructor() {
|
|
317
331
|
super("Invalid signature for challenge transaction");
|
|
@@ -319,6 +333,19 @@ export class ChallengeTxnInvalidSignatureError extends Error {
|
|
|
319
333
|
}
|
|
320
334
|
}
|
|
321
335
|
|
|
336
|
+
export class ChallengeTxnClientAccountMismatchError extends Error {
|
|
337
|
+
constructor(expected: string, received: string) {
|
|
338
|
+
super(
|
|
339
|
+
`Challenge transaction client account mismatch: expected "${expected}" ` +
|
|
340
|
+
`but challenge was issued for "${received}"`,
|
|
341
|
+
);
|
|
342
|
+
Object.setPrototypeOf(
|
|
343
|
+
this,
|
|
344
|
+
ChallengeTxnClientAccountMismatchError.prototype,
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
322
349
|
export class AllowHttpOnNonTestnetError extends Error {
|
|
323
350
|
constructor() {
|
|
324
351
|
super("Can only allow Http on Testnet");
|
|
@@ -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 {
|
|
45
|
+
* @param {Uint8Array} randomBytes - Random bytes to create keypair from.
|
|
46
46
|
* @returns {SigningKeypair} Keypair capable of signing.
|
|
47
47
|
*/
|
|
48
|
-
createKeypairFromRandom(randomBytes:
|
|
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.
|
|
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 {
|
|
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
|
|
144
|
-
* but not both.
|
|
145
|
-
* @param {string} [params.destAmount] - The amount
|
|
146
|
-
* but not both.
|
|
147
|
-
* @param {string} [params.destMin] - The minimum amount of the destination asset to
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
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
|
|
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
|
|
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}
|
|
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
|
|
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
|
|
276
|
-
this.setMemo(Memo.hash(
|
|
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),
|