@stellar/typescript-wallet-sdk 1.2.0 → 1.2.1
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/lib/bundle.js +369 -36
- package/lib/bundle.js.map +1 -1
- package/lib/bundle_browser.js +369 -36
- package/lib/bundle_browser.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/walletSdk/Auth/WalletSigner.d.ts +23 -1
- package/lib/walletSdk/Exceptions/index.d.ts +5 -1
- package/lib/walletSdk/Horizon/Transaction/CommonTransactionBuilder.d.ts +18 -0
- package/lib/walletSdk/Horizon/Transaction/SponsoringBuilder.d.ts +10 -0
- package/lib/walletSdk/Horizon/Transaction/TransactionBuilder.d.ts +42 -9
- package/lib/walletSdk/Horizon/index.d.ts +1 -0
- package/lib/walletSdk/Types/auth.d.ts +3 -0
- package/lib/walletSdk/Types/horizon.d.ts +11 -1
- package/lib/walletSdk/Types/index.d.ts +7 -0
- package/lib/walletSdk/Utils/extractAxiosErrorData.d.ts +2 -0
- package/lib/walletSdk/Utils/index.d.ts +1 -0
- package/lib/walletSdk/index.d.ts +2 -1
- package/package.json +1 -1
- package/src/walletSdk/Exceptions/index.ts +16 -2
- package/src/walletSdk/Horizon/Stellar.ts +1 -0
- package/src/walletSdk/Types/index.ts +8 -1
- package/src/walletSdk/Utils/extractAxiosErrorData.ts +28 -0
- package/src/walletSdk/Utils/index.ts +1 -0
- package/test/wallet.test.ts +19 -0
package/lib/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export { Anchor } from "./walletSdk/Anchor";
|
|
|
11
11
|
export { Sep24 } from "./walletSdk/Anchor/Sep24";
|
|
12
12
|
export { IssuedAssetId, NativeAssetId, FiatAssetId } from "./walletSdk/Asset";
|
|
13
13
|
export { Sep10, WalletSigner, DefaultSigner } from "./walletSdk/Auth";
|
|
14
|
-
export { PublicKeypair, SigningKeypair, AccountService, Stellar, TransactionBuilder, } from "./walletSdk/Horizon";
|
|
14
|
+
export { PublicKeypair, SigningKeypair, AccountService, Stellar, TransactionBuilder, SponsoringBuilder, } from "./walletSdk/Horizon";
|
|
15
15
|
export { Recovery } from "./walletSdk/Recovery";
|
|
16
16
|
export { Watcher } from "./walletSdk/Watcher";
|
|
17
17
|
/**
|
|
@@ -1,7 +1,29 @@
|
|
|
1
1
|
import { Transaction } from "stellar-sdk";
|
|
2
|
-
import { SignWithClientAccountParams, SignWithDomainAccountParams } from "../Types";
|
|
2
|
+
import { SignWithClientAccountParams, SignWithDomainAccountParams, HttpHeaders } from "../Types";
|
|
3
3
|
export interface WalletSigner {
|
|
4
4
|
signWithClientAccount({ transaction, accountKp, }: SignWithClientAccountParams): Transaction;
|
|
5
5
|
signWithDomainAccount({ transactionXDR, networkPassphrase, accountKp, }: SignWithDomainAccountParams): Promise<Transaction>;
|
|
6
6
|
}
|
|
7
7
|
export declare const DefaultSigner: WalletSigner;
|
|
8
|
+
/**
|
|
9
|
+
* Represents a Domain Signer used for signing Stellar transactions with a domain server.
|
|
10
|
+
*
|
|
11
|
+
* @class
|
|
12
|
+
* @implements {WalletSigner}
|
|
13
|
+
*/
|
|
14
|
+
export declare class DomainSigner implements WalletSigner {
|
|
15
|
+
private url;
|
|
16
|
+
private client;
|
|
17
|
+
private headers;
|
|
18
|
+
/**
|
|
19
|
+
* Create a new instance of the DomainSigner class.
|
|
20
|
+
*
|
|
21
|
+
* @constructor
|
|
22
|
+
* @param {string} url - The URL of the domain server.
|
|
23
|
+
* @param {HttpHeaders} headers - The HTTP headers for requests to the domain server.
|
|
24
|
+
* These headers can be used for authentication purposes.
|
|
25
|
+
*/
|
|
26
|
+
constructor(url: string, headers: HttpHeaders);
|
|
27
|
+
signWithClientAccount({ transaction, accountKp, }: SignWithClientAccountParams): Transaction;
|
|
28
|
+
signWithDomainAccount({ transactionXDR, networkPassphrase, accountKp, }: SignWithDomainAccountParams): Promise<Transaction>;
|
|
29
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Networks, Horizon } from "stellar-sdk";
|
|
2
|
-
import { AnchorTransaction, FLOW_TYPE } from "../Types";
|
|
2
|
+
import { AnchorTransaction, FLOW_TYPE, AxiosErrorData } from "../Types";
|
|
3
3
|
export declare class ServerRequestFailedError extends Error {
|
|
4
|
+
data: AxiosErrorData;
|
|
4
5
|
constructor(e: Error);
|
|
5
6
|
}
|
|
6
7
|
export declare class AssetNotSupportedError extends Error {
|
|
@@ -54,6 +55,9 @@ export declare class WithdrawalTxNotPendingUserTransferStartError extends Error
|
|
|
54
55
|
export declare class WithdrawalTxMissingMemoError extends Error {
|
|
55
56
|
constructor();
|
|
56
57
|
}
|
|
58
|
+
export declare class PathPayOnlyOneAmountError extends Error {
|
|
59
|
+
constructor();
|
|
60
|
+
}
|
|
57
61
|
export declare class WithdrawalTxMemoError extends Error {
|
|
58
62
|
constructor();
|
|
59
63
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { xdr } from "stellar-sdk";
|
|
2
|
+
import { IssuedAssetId } from "../../Asset";
|
|
3
|
+
import { AccountKeypair } from "../Account";
|
|
4
|
+
export declare abstract class CommonTransactionBuilder<T> {
|
|
5
|
+
protected sourceAddress: string;
|
|
6
|
+
protected operations: Array<xdr.Operation>;
|
|
7
|
+
constructor(sourceAddress: string, operations: Array<xdr.Operation>);
|
|
8
|
+
addAssetSupport(asset: IssuedAssetId, trustLimit?: string): T;
|
|
9
|
+
removeAssetSupport(asset: IssuedAssetId): T;
|
|
10
|
+
addAccountSigner(signerAddress: AccountKeypair, signerWeight: number): T;
|
|
11
|
+
removeAccountSigner(signerAddress: AccountKeypair): T;
|
|
12
|
+
lockAccountMasterKey(): T;
|
|
13
|
+
setThreshold({ low, medium, high, }: {
|
|
14
|
+
low?: number;
|
|
15
|
+
medium?: number;
|
|
16
|
+
high?: number;
|
|
17
|
+
}): T;
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { xdr } from "stellar-sdk";
|
|
2
|
+
import { CommonTransactionBuilder } from "./CommonTransactionBuilder";
|
|
3
|
+
import { AccountKeypair } from "../Account";
|
|
4
|
+
export declare class SponsoringBuilder extends CommonTransactionBuilder<SponsoringBuilder> {
|
|
5
|
+
private sponsorAccount;
|
|
6
|
+
constructor(sponsoredAddress: string, sponsorAccount: AccountKeypair, operations: Array<xdr.Operation>, buildingFunction: (SponsoringBuilder: any) => SponsoringBuilder);
|
|
7
|
+
createAccount(newAccount: AccountKeypair, startingBalance?: number): SponsoringBuilder;
|
|
8
|
+
startSponsoring(): void;
|
|
9
|
+
stopSponsoring(): void;
|
|
10
|
+
}
|
|
@@ -1,20 +1,53 @@
|
|
|
1
1
|
import { Account as StellarAccount, Transaction, Server, Memo, xdr } from "stellar-sdk";
|
|
2
2
|
import { Config } from "walletSdk";
|
|
3
3
|
import { AccountKeypair } from "../Account";
|
|
4
|
-
import {
|
|
5
|
-
import { WithdrawTransaction } from "../../Types";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
import { StellarAssetId } from "../../Asset";
|
|
5
|
+
import { WithdrawTransaction, PathPayParams } from "../../Types";
|
|
6
|
+
import { CommonTransactionBuilder } from "./CommonTransactionBuilder";
|
|
7
|
+
import { SponsoringBuilder } from "./SponsoringBuilder";
|
|
8
|
+
export declare class TransactionBuilder extends CommonTransactionBuilder<TransactionBuilder> {
|
|
9
|
+
private cfg;
|
|
9
10
|
private builder;
|
|
10
|
-
sourceAccount: string;
|
|
11
11
|
constructor(cfg: Config, sourceAccount: StellarAccount, baseFee?: number, memo?: Memo, timebounds?: Server.Timebounds);
|
|
12
|
+
sponsoring(sponsorAccount: AccountKeypair, buildingFunction: (SponsoringBuilder: any) => SponsoringBuilder, sponsoredAccount?: AccountKeypair): TransactionBuilder;
|
|
12
13
|
createAccount(newAccount: AccountKeypair, startingBalance?: number): TransactionBuilder;
|
|
13
14
|
transfer(destinationAddress: string, assetId: StellarAssetId, amount: string): TransactionBuilder;
|
|
15
|
+
/**
|
|
16
|
+
* Creates and adds a path payment operation to the transaction builder.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} destinationAddress - The destination Stellar address to which the payment is sent.
|
|
19
|
+
* @param {StellarAssetId} sendAsset - The asset to be sent.
|
|
20
|
+
* @param {StellarAssetId} destAsset - The asset the destination will receive.
|
|
21
|
+
* @param {string} [sendAmount] - The amount to be sent. Must specify either sendAmount or destAmount,
|
|
22
|
+
* but not both.
|
|
23
|
+
* @param {string} [destAmount] - The amount to be received by the destination. Must specify either sendAmount or destAmount,
|
|
24
|
+
* but not both.
|
|
25
|
+
* @param {string} [destMin] - The minimum amount of the destination asset to be receive. This is a
|
|
26
|
+
* protective measure, it allows you to specify a lower bound for an acceptable conversion. Only used
|
|
27
|
+
* if using sendAmount.
|
|
28
|
+
* (optional, default is ".0000001").
|
|
29
|
+
* @param {string} [sendMax] - The maximum amount of the destination asset to be sent. This is a
|
|
30
|
+
* protective measure, it allows you to specify an upper bound for an acceptable conversion. Only used
|
|
31
|
+
* if using destAmount.
|
|
32
|
+
* (optional, default is int64 max).
|
|
33
|
+
*
|
|
34
|
+
* @returns {TransactionBuilder} - Returns the current TransactionBuilder instance for method chaining.
|
|
35
|
+
*/
|
|
36
|
+
pathPay({ destinationAddress, sendAsset, destAsset, sendAmount, destAmount, destMin, sendMax, }: PathPayParams): TransactionBuilder;
|
|
37
|
+
/**
|
|
38
|
+
* Swap assets using the Stellar network. This swaps using the
|
|
39
|
+
* pathPaymentStrictReceive operation.
|
|
40
|
+
*
|
|
41
|
+
* @param {StellarAssetId} fromAsset - The source asset to be sent.
|
|
42
|
+
* @param {StellarAssetId} toAsset - The destination asset to receive.
|
|
43
|
+
* @param {string} amount - The amount of the source asset to be sent.
|
|
44
|
+
* @param {string} [destMin] - (Optional) The minimum amount of the destination asset to be received.
|
|
45
|
+
*
|
|
46
|
+
* @returns {TransactionBuilder} Returns the current instance of the TransactionBuilder for method chaining.
|
|
47
|
+
*/
|
|
48
|
+
swap(fromAsset: StellarAssetId, toAsset: StellarAssetId, amount: string, destMin?: string): TransactionBuilder;
|
|
14
49
|
addOperation(op: xdr.Operation): TransactionBuilder;
|
|
15
50
|
setMemo(memo: Memo): TransactionBuilder;
|
|
16
|
-
addAssetSupport(asset: IssuedAssetId, trustLimit?: string): TransactionBuilder;
|
|
17
|
-
removeAssetSupport(asset: IssuedAssetId): TransactionBuilder;
|
|
18
|
-
build(): Transaction;
|
|
19
51
|
transferWithdrawalTransaction(transaction: WithdrawTransaction, assetId: StellarAssetId): TransactionBuilder;
|
|
52
|
+
build(): Transaction;
|
|
20
53
|
}
|
|
@@ -2,3 +2,4 @@ export { PublicKeypair, SigningKeypair } from "./Account";
|
|
|
2
2
|
export { AccountService } from "./AccountService";
|
|
3
3
|
export { Stellar } from "./Stellar";
|
|
4
4
|
export { TransactionBuilder } from "./Transaction/TransactionBuilder";
|
|
5
|
+
export { SponsoringBuilder } from "./Transaction/SponsoringBuilder";
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Memo, Server, Transaction } from "stellar-sdk";
|
|
2
2
|
import { AccountKeypair } from "../Horizon/Account";
|
|
3
3
|
import { TransactionBuilder } from "../Horizon/Transaction/TransactionBuilder";
|
|
4
|
+
import { StellarAssetId } from "../Asset";
|
|
4
5
|
export declare enum NETWORK_URLS {
|
|
5
6
|
PUBLIC = "https://horizon.stellar.org",
|
|
6
7
|
TESTNET = "https://horizon-testnet.stellar.org"
|
|
7
8
|
}
|
|
8
9
|
export type TransactionParams = {
|
|
9
10
|
sourceAddress: AccountKeypair;
|
|
10
|
-
baseFee
|
|
11
|
+
baseFee?: number;
|
|
11
12
|
memo?: Memo;
|
|
12
13
|
timebounds?: Server.Timebounds | number;
|
|
13
14
|
};
|
|
@@ -32,3 +33,12 @@ export declare enum HORIZON_ORDER {
|
|
|
32
33
|
ASC = "asc",
|
|
33
34
|
DESC = "desc"
|
|
34
35
|
}
|
|
36
|
+
export type PathPayParams = {
|
|
37
|
+
destinationAddress: string;
|
|
38
|
+
sendAsset: StellarAssetId;
|
|
39
|
+
destAsset: StellarAssetId;
|
|
40
|
+
sendAmount?: string;
|
|
41
|
+
destAmount?: string;
|
|
42
|
+
destMin?: string;
|
|
43
|
+
sendMax?: string;
|
|
44
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RawAxiosRequestHeaders } from "axios";
|
|
1
2
|
import { Server, Networks } from "stellar-sdk";
|
|
2
3
|
import { ApplicationConfiguration, StellarConfiguration } from "walletSdk";
|
|
3
4
|
export type WalletParams = {
|
|
@@ -22,6 +23,12 @@ export type StellarConfigurationParams = {
|
|
|
22
23
|
baseFee?: number;
|
|
23
24
|
defaultTimeout?: number;
|
|
24
25
|
};
|
|
26
|
+
export type AxiosErrorData = {
|
|
27
|
+
status?: number;
|
|
28
|
+
statusText?: string;
|
|
29
|
+
responseData?: any;
|
|
30
|
+
headers?: RawAxiosRequestHeaders;
|
|
31
|
+
};
|
|
25
32
|
export * from "./anchor";
|
|
26
33
|
export * from "./auth";
|
|
27
34
|
export * from "./horizon";
|
package/lib/walletSdk/index.d.ts
CHANGED
|
@@ -34,5 +34,6 @@ export declare const DefaultClient: AxiosInstance;
|
|
|
34
34
|
export declare class ApplicationConfiguration {
|
|
35
35
|
defaultSigner: WalletSigner;
|
|
36
36
|
defaultClient: AxiosInstance;
|
|
37
|
-
|
|
37
|
+
defaultClientDomain?: string;
|
|
38
|
+
constructor(defaultSigner?: WalletSigner, defaultClient?: AxiosInstance, defaultClientDomain?: string);
|
|
38
39
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
import { Networks, Horizon } from "stellar-sdk";
|
|
2
|
-
import
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import { AnchorTransaction, FLOW_TYPE, AxiosErrorData } from "../Types";
|
|
4
|
+
import { extractAxiosErrorData } from "../Utils";
|
|
3
5
|
|
|
4
6
|
export class ServerRequestFailedError extends Error {
|
|
7
|
+
data: AxiosErrorData;
|
|
8
|
+
|
|
5
9
|
constructor(e: Error) {
|
|
6
|
-
|
|
10
|
+
if (axios.isAxiosError(e)) {
|
|
11
|
+
const errorData = extractAxiosErrorData(e);
|
|
12
|
+
const message =
|
|
13
|
+
errorData.responseData && Object.keys(errorData.responseData).length > 0
|
|
14
|
+
? JSON.stringify(errorData.responseData)
|
|
15
|
+
: errorData.statusText;
|
|
16
|
+
super(`Server request failed with error: ${errorData.status} ${message}`);
|
|
17
|
+
this.data = errorData;
|
|
18
|
+
} else {
|
|
19
|
+
super(`Server request failed with error: ${e}`);
|
|
20
|
+
}
|
|
7
21
|
Object.setPrototypeOf(this, ServerRequestFailedError.prototype);
|
|
8
22
|
}
|
|
9
23
|
}
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
TransactionSubmitFailedError,
|
|
20
20
|
TransactionSubmitWithFeeIncreaseFailedError,
|
|
21
21
|
SignerRequiredError,
|
|
22
|
+
ServerRequestFailedError,
|
|
22
23
|
} from "../Exceptions";
|
|
23
24
|
import { getResultCode } from "../Utils/getResultCode";
|
|
24
25
|
import { SigningKeypair } from "./Account";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RawAxiosRequestHeaders } from "axios";
|
|
2
2
|
import { Server, Networks } from "stellar-sdk";
|
|
3
3
|
import { ApplicationConfiguration, StellarConfiguration } from "walletSdk";
|
|
4
4
|
|
|
@@ -30,6 +30,13 @@ export type StellarConfigurationParams = {
|
|
|
30
30
|
defaultTimeout?: number;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
+
export type AxiosErrorData = {
|
|
34
|
+
status?: number;
|
|
35
|
+
statusText?: string;
|
|
36
|
+
responseData?: any;
|
|
37
|
+
headers?: RawAxiosRequestHeaders;
|
|
38
|
+
};
|
|
39
|
+
|
|
33
40
|
// Export all other types from walletSdk/Types.ts
|
|
34
41
|
export * from "./anchor";
|
|
35
42
|
export * from "./auth";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { AxiosErrorData } from "../Types";
|
|
3
|
+
|
|
4
|
+
// Based on https://axios-http.com/docs/handling_errors
|
|
5
|
+
|
|
6
|
+
export const extractAxiosErrorData = (error: Error): AxiosErrorData => {
|
|
7
|
+
if (!axios.isAxiosError(error)) {
|
|
8
|
+
return { responseData: JSON.stringify(error) };
|
|
9
|
+
}
|
|
10
|
+
if (error.response) {
|
|
11
|
+
return {
|
|
12
|
+
status: error.response.status,
|
|
13
|
+
statusText: error.response.statusText,
|
|
14
|
+
responseData: error.response.data,
|
|
15
|
+
headers: error.response.headers,
|
|
16
|
+
};
|
|
17
|
+
} else if (error.request) {
|
|
18
|
+
// The request was made but no response was received
|
|
19
|
+
return {
|
|
20
|
+
statusText: `No response received from request: ${JSON.stringify(
|
|
21
|
+
error.request,
|
|
22
|
+
)}`,
|
|
23
|
+
};
|
|
24
|
+
} else {
|
|
25
|
+
// Something happened in setting up the request that triggered an Error
|
|
26
|
+
return { statusText: `Failed request with error: ${error.message}` };
|
|
27
|
+
}
|
|
28
|
+
};
|
package/test/wallet.test.ts
CHANGED
|
@@ -195,6 +195,25 @@ describe("Anchor", () => {
|
|
|
195
195
|
expect(resp.id).toBeTruthy();
|
|
196
196
|
});
|
|
197
197
|
|
|
198
|
+
it("should throw ServerRequestFailedError", async () => {
|
|
199
|
+
const assetCode = "SRT";
|
|
200
|
+
let didError = false;
|
|
201
|
+
try {
|
|
202
|
+
const resp = await anchor.sep24().withdraw({
|
|
203
|
+
withdrawalAccount: accountKp.publicKey,
|
|
204
|
+
assetCode,
|
|
205
|
+
authToken: "bad auth token",
|
|
206
|
+
});
|
|
207
|
+
} catch (e) {
|
|
208
|
+
didError = true;
|
|
209
|
+
expect(e.data.status).toBe(403);
|
|
210
|
+
expect(e.data.statusText).toBe("Forbidden");
|
|
211
|
+
expect(e.data.responseData.error).toBeTruthy();
|
|
212
|
+
expect(e.data.headers).toBeTruthy();
|
|
213
|
+
}
|
|
214
|
+
expect(didError).toBe(true);
|
|
215
|
+
});
|
|
216
|
+
|
|
198
217
|
it("should fetch new transaction by id", async () => {
|
|
199
218
|
const assetCode = "SRT";
|
|
200
219
|
|