@stellar/typescript-wallet-sdk 1.1.3 → 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/examples/sep24/README.md +22 -0
- package/examples/sep24/sep24.ts +199 -0
- 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 +5 -3
- package/src/index.ts +1 -0
- package/src/walletSdk/Anchor/Sep24.ts +2 -0
- package/src/walletSdk/Auth/WalletSigner.ts +64 -1
- package/src/walletSdk/Auth/index.ts +1 -1
- package/src/walletSdk/Exceptions/index.ts +22 -2
- package/src/walletSdk/Horizon/Stellar.ts +1 -0
- package/src/walletSdk/Horizon/Transaction/CommonTransactionBuilder.ts +75 -0
- package/src/walletSdk/Horizon/Transaction/SponsoringBuilder.ts +58 -0
- package/src/walletSdk/Horizon/Transaction/TransactionBuilder.ts +116 -34
- package/src/walletSdk/Horizon/index.ts +1 -0
- package/src/walletSdk/Types/auth.ts +4 -0
- package/src/walletSdk/Types/horizon.ts +12 -1
- 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/src/walletSdk/index.ts +7 -1
- package/test/stellar.test.ts +198 -1
- package/test/transaction.test.ts +325 -0
- package/test/wallet.test.ts +43 -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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stellar/typescript-wallet-sdk",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=18"
|
|
6
6
|
},
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"stream-browserify": "^3.0.0",
|
|
30
30
|
"ts-jest": "^29.0.5",
|
|
31
31
|
"ts-loader": "^9.4.2",
|
|
32
|
+
"ts-node": "^10.9.1",
|
|
32
33
|
"tslib": "^2.5.0",
|
|
33
34
|
"typescript": "^5.0.4",
|
|
34
35
|
"webpack": "^5.83.1",
|
|
@@ -47,10 +48,11 @@
|
|
|
47
48
|
"utility-types": "^3.10.0"
|
|
48
49
|
},
|
|
49
50
|
"scripts": {
|
|
50
|
-
"prepare": "
|
|
51
|
+
"prepare": "husky install",
|
|
51
52
|
"test": "jest --watchAll",
|
|
52
53
|
"build:web": "webpack --config webpack.config.js",
|
|
53
54
|
"build:node": "webpack --env NODE=true --config webpack.config.js",
|
|
54
|
-
"build": "run-p build:web build:node"
|
|
55
|
+
"build": "run-p build:web build:node",
|
|
56
|
+
"example:sep24": "ts-node examples/sep24/sep24.ts"
|
|
55
57
|
}
|
|
56
58
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Transaction,
|
|
3
|
+
TransactionBuilder as StellarTransactionBuilder,
|
|
4
|
+
FeeBumpTransaction,
|
|
5
|
+
} from "stellar-sdk";
|
|
6
|
+
import { AxiosInstance } from "axios";
|
|
7
|
+
|
|
2
8
|
import {
|
|
3
9
|
SignWithClientAccountParams,
|
|
4
10
|
SignWithDomainAccountParams,
|
|
11
|
+
HttpHeaders,
|
|
5
12
|
} from "../Types";
|
|
13
|
+
import { AccountKeypair } from "../Horizon/Account";
|
|
14
|
+
import { DefaultClient } from "../";
|
|
6
15
|
|
|
7
16
|
export interface WalletSigner {
|
|
8
17
|
signWithClientAccount({
|
|
@@ -28,3 +37,57 @@ export const DefaultSigner: WalletSigner = {
|
|
|
28
37
|
);
|
|
29
38
|
},
|
|
30
39
|
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Represents a Domain Signer used for signing Stellar transactions with a domain server.
|
|
43
|
+
*
|
|
44
|
+
* @class
|
|
45
|
+
* @implements {WalletSigner}
|
|
46
|
+
*/
|
|
47
|
+
export class DomainSigner implements WalletSigner {
|
|
48
|
+
private url: string;
|
|
49
|
+
private client: AxiosInstance;
|
|
50
|
+
private headers: HttpHeaders;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Create a new instance of the DomainSigner class.
|
|
54
|
+
*
|
|
55
|
+
* @constructor
|
|
56
|
+
* @param {string} url - The URL of the domain server.
|
|
57
|
+
* @param {HttpHeaders} headers - The HTTP headers for requests to the domain server.
|
|
58
|
+
* These headers can be used for authentication purposes.
|
|
59
|
+
*/
|
|
60
|
+
constructor(url: string, headers: HttpHeaders) {
|
|
61
|
+
this.url = url;
|
|
62
|
+
this.client = DefaultClient;
|
|
63
|
+
this.headers = headers;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
signWithClientAccount({
|
|
67
|
+
transaction,
|
|
68
|
+
accountKp,
|
|
69
|
+
}: SignWithClientAccountParams): Transaction {
|
|
70
|
+
transaction.sign(accountKp.keypair);
|
|
71
|
+
return transaction;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async signWithDomainAccount({
|
|
75
|
+
transactionXDR,
|
|
76
|
+
networkPassphrase,
|
|
77
|
+
accountKp,
|
|
78
|
+
}: SignWithDomainAccountParams): Promise<Transaction> {
|
|
79
|
+
const response = await this.client.post(
|
|
80
|
+
this.url,
|
|
81
|
+
{
|
|
82
|
+
transactionXDR,
|
|
83
|
+
networkPassphrase,
|
|
84
|
+
},
|
|
85
|
+
{ headers: this.headers },
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
return StellarTransactionBuilder.fromXDR(
|
|
89
|
+
response.data.transaction,
|
|
90
|
+
networkPassphrase,
|
|
91
|
+
) as Transaction;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -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
|
}
|
|
@@ -147,6 +161,12 @@ export class WithdrawalTxMissingMemoError extends Error {
|
|
|
147
161
|
}
|
|
148
162
|
}
|
|
149
163
|
|
|
164
|
+
export class PathPayOnlyOneAmountError extends Error {
|
|
165
|
+
constructor() {
|
|
166
|
+
super("Must give sendAmount or destAmount value, but not both");
|
|
167
|
+
Object.setPrototypeOf(this, PathPayOnlyOneAmountError.prototype);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
150
170
|
export class WithdrawalTxMemoError extends Error {
|
|
151
171
|
constructor() {
|
|
152
172
|
super(`Error parsing withdrawal transaction memo`);
|
|
@@ -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";
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import StellarSdk, { xdr } from "stellar-sdk";
|
|
2
|
+
import { IssuedAssetId } from "../../Asset";
|
|
3
|
+
import { AccountKeypair } from "../Account";
|
|
4
|
+
|
|
5
|
+
export abstract class CommonTransactionBuilder<T> {
|
|
6
|
+
protected sourceAddress: string;
|
|
7
|
+
protected operations: Array<xdr.Operation>;
|
|
8
|
+
|
|
9
|
+
constructor(sourceAddress: string, operations: Array<xdr.Operation>) {
|
|
10
|
+
this.sourceAddress = sourceAddress;
|
|
11
|
+
this.operations = operations;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
addAssetSupport(asset: IssuedAssetId, trustLimit?: string): T {
|
|
15
|
+
this.operations.push(
|
|
16
|
+
StellarSdk.Operation.changeTrust({
|
|
17
|
+
asset: asset.toAsset(),
|
|
18
|
+
limit: trustLimit,
|
|
19
|
+
source: this.sourceAddress,
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
22
|
+
return this as any as T;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
removeAssetSupport(asset: IssuedAssetId): T {
|
|
26
|
+
return this.addAssetSupport(asset, "0");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
addAccountSigner(signerAddress: AccountKeypair, signerWeight: number): T {
|
|
30
|
+
this.operations.push(
|
|
31
|
+
StellarSdk.Operation.setOptions({
|
|
32
|
+
source: this.sourceAddress,
|
|
33
|
+
signer: {
|
|
34
|
+
ed25519PublicKey: signerAddress.publicKey,
|
|
35
|
+
weight: signerWeight,
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
);
|
|
39
|
+
return this as any as T;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
removeAccountSigner(signerAddress: AccountKeypair): T {
|
|
43
|
+
return this.addAccountSigner(signerAddress, 0);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
lockAccountMasterKey(): T {
|
|
47
|
+
this.operations.push(
|
|
48
|
+
StellarSdk.Operation.setOptions({
|
|
49
|
+
source: this.sourceAddress,
|
|
50
|
+
masterWeight: 0,
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
return this as any as T;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
setThreshold({
|
|
57
|
+
low,
|
|
58
|
+
medium,
|
|
59
|
+
high,
|
|
60
|
+
}: {
|
|
61
|
+
low?: number;
|
|
62
|
+
medium?: number;
|
|
63
|
+
high?: number;
|
|
64
|
+
}): T {
|
|
65
|
+
this.operations.push(
|
|
66
|
+
StellarSdk.Operation.setOptions({
|
|
67
|
+
source: this.sourceAddress,
|
|
68
|
+
lowThreshold: low,
|
|
69
|
+
medThreshold: medium,
|
|
70
|
+
highThreshold: high,
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
return this as any as T;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import StellarSdk, {
|
|
2
|
+
TransactionBuilder as StellarTransactionBuilder,
|
|
3
|
+
Transaction,
|
|
4
|
+
xdr,
|
|
5
|
+
} from "stellar-sdk";
|
|
6
|
+
import { IssuedAssetId } from "../../Asset";
|
|
7
|
+
|
|
8
|
+
import { CommonTransactionBuilder } from "./CommonTransactionBuilder";
|
|
9
|
+
import { AccountKeypair } from "../Account";
|
|
10
|
+
|
|
11
|
+
export class SponsoringBuilder extends CommonTransactionBuilder<SponsoringBuilder> {
|
|
12
|
+
private sponsorAccount: AccountKeypair;
|
|
13
|
+
|
|
14
|
+
constructor(
|
|
15
|
+
sponsoredAddress: string,
|
|
16
|
+
sponsorAccount: AccountKeypair,
|
|
17
|
+
operations: Array<xdr.Operation>,
|
|
18
|
+
buildingFunction: (SponsoringBuilder) => SponsoringBuilder,
|
|
19
|
+
) {
|
|
20
|
+
super(sponsoredAddress, operations);
|
|
21
|
+
this.sponsorAccount = sponsorAccount;
|
|
22
|
+
|
|
23
|
+
this.startSponsoring();
|
|
24
|
+
buildingFunction(this);
|
|
25
|
+
this.stopSponsoring();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
createAccount(
|
|
29
|
+
newAccount: AccountKeypair,
|
|
30
|
+
startingBalance: number = 0,
|
|
31
|
+
): SponsoringBuilder {
|
|
32
|
+
this.operations.push(
|
|
33
|
+
StellarSdk.Operation.createAccount({
|
|
34
|
+
destination: newAccount.publicKey,
|
|
35
|
+
startingBalance: startingBalance.toString(),
|
|
36
|
+
source: this.sponsorAccount.publicKey,
|
|
37
|
+
}),
|
|
38
|
+
);
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
startSponsoring() {
|
|
43
|
+
this.operations.push(
|
|
44
|
+
StellarSdk.Operation.beginSponsoringFutureReserves({
|
|
45
|
+
sponsoredId: this.sourceAddress,
|
|
46
|
+
source: this.sponsorAccount.publicKey,
|
|
47
|
+
}),
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
stopSponsoring() {
|
|
52
|
+
this.operations.push(
|
|
53
|
+
StellarSdk.Operation.endSponsoringFutureReserves({
|
|
54
|
+
source: this.sourceAddress,
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|